| @@ -0,0 +1,5 @@ | |||
| //app.js | |||
| App({ | |||
| onLaunch: function () { | |||
| } | |||
| }) | |||
| @@ -0,0 +1,20 @@ | |||
| { | |||
| "pages":[ | |||
| "pages/index/index" | |||
| ], | |||
| "window": { | |||
| "navigationBarBackgroundColor": "#0082FE", | |||
| "navigationBarTextStyle": "white", | |||
| "navigationBarTitleText": "BM16离线历史记录", | |||
| "backgroundColor": "#eeeeee", | |||
| "backgroundTextStyle": "light" | |||
| }, | |||
| "plugins": { | |||
| "sdkPlugin": { | |||
| "version": "2.4.0", | |||
| "provider": "wx17e93aad47cdae1a" | |||
| } | |||
| }, | |||
| "style": "v2", | |||
| "sitemapLocation": "sitemap.json" | |||
| } | |||
| @@ -0,0 +1,431 @@ | |||
| // const plugin = requirePlugin("myPlugin").AiFresh; | |||
| const {BM16His: plugin} = requirePlugin("sdkPlugin"); | |||
| function inArray(arr, key, val) { | |||
| for (let i = 0; i < arr.length; i++) { | |||
| if (arr[i][key] === val) { | |||
| return i; | |||
| } | |||
| } | |||
| return -1; | |||
| } | |||
| // ArrayBuffer转16进度字符串示例 | |||
| function ab2hex(buffer) { | |||
| var hexArr = Array.prototype.map.call( | |||
| new Uint8Array(buffer), | |||
| function (bit) { | |||
| return ('00' + bit.toString(16)).slice(-2) | |||
| } | |||
| ) | |||
| return hexArr.join(','); | |||
| } | |||
| // var information = [] | |||
| Page({ | |||
| data: { | |||
| devices: [], | |||
| mac: "", | |||
| connected: false, | |||
| text: "", | |||
| unitList_all: ['g', 'ml', 'lb:oz', 'oz', 'kg', '斤', '牛奶 ml', '水 ml', '牛奶 floz', '水 floz', 'lb'], | |||
| unitList: ['g', 'ml', 'lb:oz', 'oz'], | |||
| weight: 0, | |||
| unit: 'g', | |||
| unitIndex: 0, | |||
| min: 0, | |||
| second: 0, | |||
| showWriteInput: false, | |||
| connected: false, | |||
| chs: [], | |||
| cmd: '', | |||
| name: '', | |||
| deviceId: null, | |||
| historyList: [], | |||
| height:0, | |||
| information:[], | |||
| }, | |||
| onLoad: function () { | |||
| let screenHeight = wx.getSystemInfoSync().windowHeight; | |||
| this.setData({ | |||
| height: screenHeight - 344, | |||
| }); | |||
| }, | |||
| clearDevices() { | |||
| this.setData({ | |||
| devices: [] | |||
| }) | |||
| this.closeBluetoothAdapter() | |||
| wx.nextTick(()=>{ | |||
| this.openBluetoothAdapter() | |||
| }) | |||
| }, | |||
| // 初始化蓝牙模块 | |||
| openBluetoothAdapter() { | |||
| wx.openBluetoothAdapter({ | |||
| success: (res) => { | |||
| console.log('openBluetoothAdapter success', res) | |||
| this.startBluetoothDevicesDiscovery() | |||
| }, | |||
| fail: (res) => { | |||
| if (res.errCode === 10001) { | |||
| wx.showToast({ | |||
| title: '请打开蓝牙', | |||
| icon: "none" | |||
| }) | |||
| wx.onBluetoothAdapterStateChange(function (res) { | |||
| console.log('onBluetoothAdapterStateChange', res) | |||
| if (res.available) { | |||
| this.startBluetoothDevicesDiscovery() | |||
| } | |||
| }) | |||
| } | |||
| } | |||
| }) | |||
| }, | |||
| // 获取本机蓝牙适配器状态 | |||
| getBluetoothAdapterState() { | |||
| wx.getBluetoothAdapterState({ | |||
| success: (res) => { | |||
| console.log('getBluetoothAdapterState', res) | |||
| if (res.discovering) { | |||
| this.onBluetoothDeviceFound() | |||
| } else if (res.available) { | |||
| this.startBluetoothDevicesDiscovery() | |||
| } | |||
| } | |||
| }) | |||
| }, | |||
| // 开始搜寻附近的蓝牙外围设备 | |||
| startBluetoothDevicesDiscovery() { | |||
| if (this._discoveryStarted) { | |||
| return | |||
| } | |||
| this._discoveryStarted = true | |||
| wx.startBluetoothDevicesDiscovery({ | |||
| allowDuplicatesKey: true, | |||
| services: [ | |||
| "FFE0", | |||
| "F0A0", // BM30广播模块需加上,如使用连接模块可忽略 | |||
| ], | |||
| powerLevel: 'high', | |||
| success: (res) => { | |||
| console.log('startBluetoothDevicesDiscovery success', res) | |||
| this.onBluetoothDeviceFound() | |||
| }, | |||
| }) | |||
| }, | |||
| // 停止搜寻附近的蓝牙外围设备 | |||
| stopBluetoothDevicesDiscovery() { | |||
| wx.stopBluetoothDevicesDiscovery() | |||
| }, | |||
| // 监听寻找到新设备的事件 | |||
| onBluetoothDeviceFound() { | |||
| wx.onBluetoothDeviceFound((res) => { | |||
| console.log('res',res); | |||
| res.devices.forEach(device => { | |||
| if (!device.name && !device.localName) { | |||
| return | |||
| } | |||
| const foundDevices = this.data.devices | |||
| console.log('foundDevices',foundDevices); | |||
| const idx = inArray(foundDevices, 'deviceId', device.deviceId) | |||
| let advertisDatas = ab2hex(device.advertisData).split(',').toString() | |||
| let index = advertisDatas.indexOf('6e,49') | |||
| let cid = advertisDatas[index + 9] + advertisDatas[index + 10] | |||
| const data = {} | |||
| // console.log(device) | |||
| // console.log(ab2hex(device.advertisData)) | |||
| // 此处判断是否BM30广播模块,如使用连接模块请删除此 if ,只保留 else 内容 | |||
| if (cid == 14 ||cid == '0e') { | |||
| if (device.advertisServiceUUIDs[0].indexOf("F0A0") !== -1) { | |||
| let parseDataRes = plugin.parseBroadcastData(device.advertisData) | |||
| // console.log(parseDataRes) | |||
| if (parseDataRes.status == 1) { | |||
| let analyzeData = plugin.analyzeBroadcastScaleData(parseDataRes) | |||
| device.analyzeDataText = analyzeData.text | |||
| console.log(analyzeData.data.weight) | |||
| } | |||
| } else { | |||
| let buff = device.advertisData.slice(8, 14) | |||
| device.mac = new Uint8Array(buff) // 保存广播数据中的mac地址,这是由于iOS不直接返回mac地址 | |||
| let tempMac = Array.from(device.mac) | |||
| tempMac.reverse() | |||
| device.macAddr = ab2hex(tempMac, ':').toUpperCase() | |||
| } | |||
| if (idx === -1) { | |||
| data[`devices[${foundDevices.length}]`] = device | |||
| } else { | |||
| data[`devices[${idx}]`] = device | |||
| } | |||
| this.setData(data) | |||
| } | |||
| }) | |||
| }) | |||
| }, | |||
| // 连接低功耗蓝牙设备 | |||
| createBLEConnection(e) { | |||
| this._connLoading = true | |||
| wx.showLoading({ | |||
| title: '连接中', | |||
| }) | |||
| setTimeout(() => { | |||
| if (this._connLoading) { | |||
| this._connLoading = false | |||
| wx.hideLoading() | |||
| } | |||
| }, 6000) | |||
| const ds = e.currentTarget.dataset | |||
| const index = ds.index | |||
| // 保存当前连接的设备,注意不能从wxml的dataset中直接返回该对象,因为ArrarBuffer类型的数据无法保留 | |||
| const deviceId = ds.deviceId | |||
| const name = ds.name | |||
| this._device = this.data.devices[index] | |||
| console.log(this._device) | |||
| wx.createBLEConnection({ | |||
| deviceId, | |||
| success: (res) => { | |||
| // console.log('this._device',this._device); | |||
| let buff = this._device.advertisData.slice(-6) | |||
| let arr = new Uint8Array(buff).reverse() | |||
| let mac = ab2hex(arr).replace(/,/g,":") | |||
| // console.log('mac',mac); | |||
| this.setData({ | |||
| connected: true, | |||
| name, | |||
| deviceId, | |||
| mac | |||
| }) | |||
| console.log("createBLEConnection:success") | |||
| this.log('蓝牙连接成功!') | |||
| wx.stopBluetoothDevicesDiscovery() | |||
| this.onBLEConnectionStateChange() | |||
| this.getBLEDeviceServices(deviceId) | |||
| }, | |||
| fail: res => { | |||
| this._connLoading = false | |||
| wx.hideLoading() | |||
| wx.showToast({ | |||
| title: '连接失败', | |||
| icon: 'none' | |||
| }) | |||
| } | |||
| }) | |||
| // 连接上设备就可以停止蓝牙搜索,减少功耗。 | |||
| this.stopBluetoothDevicesDiscovery() | |||
| }, | |||
| onBLEConnectionStateChange() { | |||
| wx.onBLEConnectionStateChange((res) => { | |||
| console.log('wx.onBLEConnectionStateChange() ', res.deviceId, res.connected, res.errorCode, res.errorMsg) | |||
| // 该方法回调中可以用于处理连接意外断开等异常情况 | |||
| // console.log(`%c device ${res.deviceId} state has changed, connected: ${res.connected}`, 'color: #F26363') | |||
| if (!res.connected) { | |||
| wx.showToast({ | |||
| title: '连接已断开', | |||
| icon: 'none' | |||
| }) | |||
| this.log(this.data.mac + '蓝牙已断开连接....') | |||
| this.setData({ | |||
| showWriteInput: false, | |||
| }) | |||
| } | |||
| }) | |||
| }, | |||
| // 断开与低功耗蓝牙设备的连接 | |||
| closeBLEConnection() { | |||
| wx.closeBLEConnection({ | |||
| deviceId: this._deviceId | |||
| }) | |||
| this.log(this.data.mac + '蓝牙已断开连接....') | |||
| this.setData({ | |||
| showWriteInput: false, | |||
| }) | |||
| }, | |||
| quit(){ | |||
| this.closeBLEConnection() | |||
| this.setData({ | |||
| connected: false, | |||
| information:[] | |||
| }) | |||
| }, | |||
| // 获取蓝牙设备的 serviceId | |||
| getBLEDeviceServices(deviceId) { | |||
| wx.getBLEDeviceServices({ | |||
| deviceId, | |||
| success: (res) => { | |||
| for (let i = 0; i < res.services.length; i++) { | |||
| if (res.services[i].isPrimary && res.services[i].uuid.indexOf('FFE0') > -1) { | |||
| this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid) | |||
| return | |||
| } | |||
| } | |||
| } | |||
| }) | |||
| }, | |||
| // 获取蓝牙设备某个服务中所有特征值(characteristic) | |||
| getBLEDeviceCharacteristics(deviceId, serviceId) { | |||
| this._deviceId = deviceId | |||
| this._serviceId = serviceId | |||
| this._device.serviceId = serviceId | |||
| wx.getBLEDeviceCharacteristics({ | |||
| deviceId, | |||
| serviceId, | |||
| success: (res) => { | |||
| console.log('getBLEDeviceCharacteristics success', res.characteristics) | |||
| console.log('plugin',plugin); | |||
| // 初始化插件 | |||
| plugin.initPlugin(res.characteristics, this._device) | |||
| wx.onBLECharacteristicValueChange((characteristic) => { | |||
| // 解析特征值,返回解密后的数据 | |||
| let bleData = plugin.parseBleData(characteristic.value) | |||
| console.log(bleData) | |||
| if (bleData.status == 0) { | |||
| console.log("握手成功") | |||
| this._connLoading = false | |||
| wx.hideLoading() | |||
| wx.showToast({ | |||
| title: '连接成功', | |||
| }) | |||
| } else if (bleData.status == 2) { | |||
| let payload = bleData.data //对应协议中的payload数据,可以自行解析该数据 | |||
| // console.log(ab2hex(payload, ' ')) | |||
| // console.log(ab2hex(bleData.completeData, ' ')) | |||
| switch (payload[0]) { | |||
| case 0x1B: | |||
| if (payload[1] == 0) { | |||
| this.log('设置系统时间成功') | |||
| }else if (payload[1] == 1) { | |||
| this.log('设置系统时间失败') | |||
| }else{ | |||
| this.log('系统不支持时间设置') | |||
| } | |||
| break; | |||
| case 0x1C: | |||
| if (payload[1] == 1) { | |||
| let {year,month,day,hour,min,second} = plugin.analyzeSystemTime(payload) | |||
| this.log(`系统时间为:${year}/${month}/${day} ${hour}:${min}:${second}`) | |||
| } else { | |||
| this.log('系统时间无效') | |||
| } | |||
| break; | |||
| case 0x2B: | |||
| if (payload[1] == 0x05) { | |||
| if (payload[2] == 0) { | |||
| this.log('无用户历史记录') | |||
| } else if(payload[2] == 1) { | |||
| this.log('开始发送历史记录') | |||
| }else{ | |||
| this.log('结束发送历史记录') | |||
| } | |||
| } | |||
| if (payload[1] == 0x06) { | |||
| if (payload[2] == 0x01) { | |||
| plugin.analyzeMCUBodyData(payload) | |||
| } else if (payload[2] == 0x02){ | |||
| plugin.analyzeMCUBodyData(payload) | |||
| }else if (payload[2] == 0x03) { | |||
| let { year,month,day,hour,min,second,id,userCharacteristics,sex,age,height,weight,metabolicBasisRate,bodyAge ,uint,symbol,impedance,compute,bodyFat,subcutaneousFat,visceralFat,musclesRate,boneMass,waterContent,proteinRate,heartRate } = plugin.analyzeMCUBodyData(payload) | |||
| this.log(`时间为:${year}/${month}/${day} ${hour}:${min}:${second} | |||
| id:${id} 用户特征:${userCharacteristics},性别:${sex},年龄:${age},身高:${height}, | |||
| 体重:${weight},单前单位:${uint},重量数据精度:${symbol},阻抗:${impedance}, | |||
| 心率数据:${heartRate},体脂:${bodyFat},皮下脂肪:${subcutaneousFat} | |||
| ,内脏脂肪:${visceralFat},肌肉率:${musclesRate},基础代谢率:${metabolicBasisRate}, | |||
| 骨量:${boneMass},水含量:${waterContent},蛋白率:${proteinRate},身体年龄:${bodyAge}`) | |||
| } | |||
| } | |||
| if (payload[1] == 0x07) { | |||
| if (payload[2] == 0x01) { | |||
| plugin.analyzeAPPBodyData(payload) | |||
| } else if (payload[2] == 0x02){ | |||
| let { year,month,day,hour,min,second,id,userCharacteristics,sex,age,height,weight,uint,symbol,impedance,compute,heartRate } = plugin.analyzeAPPBodyData(payload) | |||
| this.log(`时间为:${year}/${month}/${day} ${hour}:${min}:${second} | |||
| id:${id} 用户特征:${userCharacteristics},性别:${sex},年龄:${age},身高:${height}, | |||
| 体重:${weight},单前单位:${uint},重量数据精度:${symbol},阻抗:${impedance}, | |||
| 算法标识:${compute},心率数据:${heartRate}`) | |||
| } | |||
| } | |||
| if (payload[1] == 0x04) { | |||
| if (payload[2] == 0) { | |||
| this.log('更新列表成功') | |||
| } else if(payload[2] == 1){ | |||
| this.log('更新个人用户成功') | |||
| }else if(payload[2] == 2){ | |||
| this.log('更新列表失败') | |||
| }else if(payload[2] == 3){ | |||
| this.log('更新个人用户失败') | |||
| }else{ | |||
| this.log('未知指令') | |||
| } | |||
| } | |||
| } | |||
| } else if (bleData.status == 1){ | |||
| } | |||
| }) | |||
| }, | |||
| fail(res) { | |||
| console.error('getBLEDeviceCharacteristics', res) | |||
| } | |||
| }) | |||
| }, | |||
| log(data){ | |||
| let info = this.data.information | |||
| info.unshift(data) | |||
| this.setData({ | |||
| information:info | |||
| }) | |||
| }, | |||
| writeBLECharacteristicValue(buffer, uuid, deviceId, serviceId) { | |||
| // 向蓝牙设备发送一个二进制流数据 | |||
| wx.writeBLECharacteristicValue({ | |||
| deviceId, | |||
| serviceId, | |||
| characteristicId: uuid, | |||
| value: buffer, | |||
| success(res) { | |||
| console.log('writeBLECharacteristicValue success', res) | |||
| console.log('下发指令==> ' + ab2hex(buffer)) | |||
| } | |||
| }) | |||
| }, | |||
| closeBluetoothAdapter() { | |||
| wx.closeBluetoothAdapter() | |||
| this._discoveryStarted = false | |||
| }, | |||
| setSystemTime(){ | |||
| // console.log('设置时间'); | |||
| plugin.setSystemTime() | |||
| }, | |||
| getSystemTime(){ | |||
| // console.log('获取时间'); | |||
| plugin.getSystemTime() | |||
| }, | |||
| updateUserList(){ | |||
| // console.log('更新用户列表'); | |||
| let userInfo = { identity:0,id:7,sex:1,age:21,height:176,weight:77.5,impedance:450} | |||
| let userInfo1 = { identity:1,id:2,sex:0,age:29,height:162,weight:66.1,impedance:420 } | |||
| let userInfo2 = { identity:0,id:1,sex:1,age:22,height:168,weight:71.1,impedance:430 } | |||
| let userList = [] | |||
| userList.push(userInfo) | |||
| userList.push(userInfo1) | |||
| userList.push(userInfo2) | |||
| plugin.updateUserList(userList) | |||
| }, | |||
| updateUserInformation(){ | |||
| //console.log('更新用户个人信息'); | |||
| let userInfo ={ identity:0,id:7,sex:1,age:21,height:176,weight:77.5,impedance:450} | |||
| plugin.updateUserInformation(userInfo) | |||
| }, | |||
| requestHis(){ | |||
| plugin.requestHis() | |||
| } | |||
| }); | |||
| @@ -0,0 +1,3 @@ | |||
| { | |||
| "usingComponents": {} | |||
| } | |||
| @@ -0,0 +1,60 @@ | |||
| <wxs module="utils"> | |||
| module.exports.max = function(n1, n2) { | |||
| return Math.max(n1, n2) | |||
| } | |||
| module.exports.len = function(arr) { | |||
| arr = arr || [] | |||
| return arr.length | |||
| } | |||
| module.exports.fill0 = function(num) { | |||
| if (!num) { | |||
| return '00' | |||
| } | |||
| return ('00' + num).slice(-2) | |||
| } | |||
| </wxs> | |||
| <block wx:if="{{!connected}}"> | |||
| <button bindtap="openBluetoothAdapter">开始扫描</button> | |||
| <button bindtap="stopBluetoothDevicesDiscovery">停止扫描</button> | |||
| <button bindtap="closeBluetoothAdapter">结束流程</button> | |||
| <button bindtap="clearDevices">清空列表</button> | |||
| <view class="devices_summary">已发现 {{devices.length}} 个外围设备:</view> | |||
| <view class="device_list"> | |||
| <view wx:for="{{devices}}" wx:key="index" | |||
| class="device_item"> | |||
| <view style="font-size: 16px; color: #333;">{{item.name || item.localName}}</view> | |||
| <view style="font-size: 10px">信号强度: {{item.RSSI}}dBm ({{utils.max(0, item.RSSI + 100)}}%)</view> | |||
| <view style="font-size: 10px">mac地址: {{item.deviceId}}</view> | |||
| <view | |||
| class="device_item_btn" | |||
| hover-class="btn_hover" | |||
| data-device-id="{{item.deviceId}}" | |||
| data-name="{{item.name || item.localName}}" | |||
| data-index="{{index}}" | |||
| bindtap="createBLEConnection" | |||
| >连接</view> | |||
| </view> | |||
| </view> | |||
| </block> | |||
| <view class="wrap" wx:else> | |||
| <view class="stopConnect"> | |||
| <view>{{mac}}</view> | |||
| <view class="btn_connect" hover-class="btn_hover" bindtap="closeBLEConnection">断开连接</view> | |||
| </view> | |||
| <view class="btn_wrap"> | |||
| <button bindtap="setSystemTime">设置系统时间</button> | |||
| <button bindtap="getSystemTime">获取系统时间</button> | |||
| <button bindtap="updateUserList">更新用户列表</button> | |||
| <button bindtap="updateUserInformation">更新个人用户信息</button> | |||
| <button bindtap="requestHis">请求同步历史记录</button> | |||
| <button bindtap="quit">退回蓝牙连接页面</button> | |||
| </view> | |||
| <!-- <view class="weight_wrap"> --> | |||
| <scroll-view class="log" scroll-y style='height:{{2*height}}rpx' scroll-into-view="{{jumpPoint}}"> | |||
| <view class="logList" wx:for="{{information}}"> | |||
| {{item}} | |||
| </view> | |||
| </scroll-view> | |||
| </view> | |||
| @@ -0,0 +1,164 @@ | |||
| page { | |||
| color: #333; | |||
| } | |||
| .devices_summary { | |||
| margin-top: 30px; | |||
| padding: 10px; | |||
| font-size: 16px; | |||
| } | |||
| .device_list { | |||
| min-height: 300px; | |||
| margin: 0 5px; | |||
| border: 1px solid #EEE; | |||
| width: auto; | |||
| } | |||
| .device_item { | |||
| border-bottom: 1px solid #EEE; | |||
| padding: 10px; | |||
| color: #666; | |||
| position: relative; | |||
| } | |||
| .device_item_btn{ | |||
| position: absolute; | |||
| right: 12px; | |||
| top: 50%; | |||
| transform: translateY(-50%); | |||
| width: 60px; | |||
| height: 30px; | |||
| display: flex; | |||
| align-items: center; | |||
| justify-content: center; | |||
| border: 1px solid #ddd; | |||
| border-radius: 3px; | |||
| } | |||
| .connected_info { | |||
| position: fixed; | |||
| bottom: 0; | |||
| width: 100%; | |||
| background-color: #F0F0F0; | |||
| padding: 10px; | |||
| padding-bottom: 20px; | |||
| margin-bottom: env(safe-area-inset-bottom); | |||
| font-size: 14px; | |||
| min-height: 100px; | |||
| box-shadow: 0px 0px 3px 0px; | |||
| } | |||
| .connected_info .operation { | |||
| position: absolute; | |||
| display: inline-block; | |||
| right: 30px; | |||
| } | |||
| .writeInputViewBg{ | |||
| position: fixed; | |||
| top: 0; | |||
| left: 0; | |||
| right: 0; | |||
| bottom: 0; | |||
| z-index: 1000; | |||
| background-color: rgba(0,0,0,0.5); | |||
| } | |||
| .writeInputView{ | |||
| position: fixed; | |||
| top: 30%; | |||
| left: 50%; | |||
| z-index: 1001; | |||
| background-color: #fff; | |||
| width: 80vw; | |||
| height: 300rpx; | |||
| display: flex; | |||
| flex-direction: column; | |||
| align-items: center; | |||
| transform: translateX(-50%); | |||
| } | |||
| .writeInput{ | |||
| margin-top: 60rpx; | |||
| width: 90%; | |||
| height: 60rpx; | |||
| border: 1rpx solid #ccc; | |||
| } | |||
| .writeInput input{ | |||
| width: 100%; | |||
| height: 100%; | |||
| box-sizing: border-box; | |||
| } | |||
| .hint{ | |||
| padding-top: 10rpx; | |||
| font-size: 24rpx; | |||
| color: #999; | |||
| } | |||
| .btns{ | |||
| display: flex; | |||
| align-items: center; | |||
| justify-content: space-between; | |||
| width: 60%; | |||
| margin-top: 50rpx; | |||
| } | |||
| .stopConnect{ | |||
| display: flex; | |||
| align-items: center; | |||
| justify-content: space-between; | |||
| padding: 10px; | |||
| } | |||
| .btn_connect{ | |||
| width: 20%; | |||
| height: 30px; | |||
| display: flex; | |||
| align-items: center; | |||
| justify-content: center; | |||
| background: #f8f8f8; | |||
| border: 1px solid #ddd; | |||
| border-radius: 5px; | |||
| } | |||
| .log{ | |||
| width: 100%; | |||
| } | |||
| .logList{ | |||
| border-bottom: 1px solid #f8f8f8; | |||
| } | |||
| .weight_wrap, | |||
| .timer_wrap{ | |||
| padding: 10px; | |||
| border-top: 1px solid #ddd; | |||
| } | |||
| .timer_value, | |||
| .weight_value{ | |||
| display: flex; | |||
| align-items: center; | |||
| justify-content: center; | |||
| } | |||
| .value_item{ | |||
| margin: 0 5px; | |||
| padding: 4px 6px; | |||
| border: 1px solid #eee; | |||
| min-width: 60px; | |||
| text-align: center; | |||
| } | |||
| .btn_wrap{ | |||
| padding-top: 10px; | |||
| } | |||
| .btn_unitList_title{ | |||
| padding: 10px; | |||
| } | |||
| .btn_unitList{ | |||
| display: flex; | |||
| flex-wrap: wrap; | |||
| align-items: center; | |||
| justify-content: space-around; | |||
| } | |||
| .btn_unit{ | |||
| width: 20%; | |||
| height: 40px; | |||
| display: flex; | |||
| align-items: center; | |||
| justify-content: center; | |||
| background: #f8f8f8; | |||
| border: 1px solid #ddd; | |||
| border-radius: 5px; | |||
| margin: 10px 0; | |||
| } | |||
| .btn_hover{ | |||
| background: rgba(0,0,0,0.1); | |||
| } | |||
| @@ -0,0 +1,54 @@ | |||
| { | |||
| "description": "项目配置文件", | |||
| "packOptions": { | |||
| "ignore": [], | |||
| "include": [] | |||
| }, | |||
| "setting": { | |||
| "urlCheck": true, | |||
| "es6": true, | |||
| "enhance": true, | |||
| "postcss": true, | |||
| "preloadBackgroundData": false, | |||
| "minified": true, | |||
| "newFeature": false, | |||
| "coverView": true, | |||
| "nodeModules": false, | |||
| "autoAudits": false, | |||
| "showShadowRootInWxmlPanel": true, | |||
| "scopeDataCheck": false, | |||
| "uglifyFileName": false, | |||
| "checkInvalidKey": true, | |||
| "checkSiteMap": true, | |||
| "uploadWithSourceMap": true, | |||
| "compileHotReLoad": false, | |||
| "useMultiFrameRuntime": true, | |||
| "useApiHook": true, | |||
| "useApiHostProcess": false, | |||
| "babelSetting": { | |||
| "ignore": [], | |||
| "disablePlugins": [], | |||
| "outputPath": "" | |||
| }, | |||
| "enableEngineNative": false, | |||
| "bundle": false, | |||
| "useIsolateContext": true, | |||
| "useCompilerModule": true, | |||
| "userConfirmedUseCompilerModuleSwitch": false, | |||
| "userConfirmedBundleSwitch": false, | |||
| "packNpmManually": false, | |||
| "packNpmRelationList": [], | |||
| "minifyWXSS": true | |||
| }, | |||
| "compileType": "miniprogram", | |||
| "libVersion": "2.14.1", | |||
| "appid": "wx17e93aad47cdae1a", | |||
| "projectname": "ailink_demo", | |||
| "simulatorType": "wechat", | |||
| "simulatorPluginLibVersion": {}, | |||
| "condition": {}, | |||
| "editorSetting": { | |||
| "tabIndent": "insertSpaces", | |||
| "tabSize": 4 | |||
| } | |||
| } | |||
| @@ -0,0 +1,7 @@ | |||
| { | |||
| "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", | |||
| "projectname": "ailink_demo", | |||
| "setting": { | |||
| "compileHotReLoad": true | |||
| } | |||
| } | |||
| @@ -0,0 +1,7 @@ | |||
| { | |||
| "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html", | |||
| "rules": [{ | |||
| "action": "allow", | |||
| "page": "*" | |||
| }] | |||
| } | |||
| @@ -0,0 +1,593 @@ | |||
| ////////////////////////////// 返回参数判断 ////////////////////// | |||
| //height传入单位为cm weight单位为kg sex=1为男性 else 为女性 | |||
| module.exports = { | |||
| getWeightDisplay, | |||
| getBMIDisplay, | |||
| getFatRateDisplay, | |||
| getMuscleDisplay, | |||
| getMoistureDisplay, | |||
| getBonemassDisplay, | |||
| getBMRDisplay, | |||
| getVisceralfatDisplay, | |||
| getVisceralfatDisplay, | |||
| getSubcutaneousFatDisplay, | |||
| getProteinRateDisplay, | |||
| getPhysicalAgeDisplay, | |||
| getFatWeightDisplay, | |||
| getMuscleMassDisplay, | |||
| getProteinDisplay, | |||
| getFatLevel, | |||
| getBodyLevel, | |||
| getWeightScore, | |||
| }; | |||
| // 体重 标准判断 | |||
| function getWeightDisplay(height, weight) { | |||
| var i = Math.pow(height / 100, 2); | |||
| var a1 = 18.5 * i; | |||
| var a2 = 25 * i; | |||
| var a3 = 30 * i; | |||
| var string1 = a1.toFixed(1); | |||
| var string2 = a2.toFixed(1); | |||
| var string3 = a3.toFixed(1); | |||
| if (weight == "-.-") { | |||
| return { | |||
| standard: "-.-", | |||
| text: "", | |||
| }; | |||
| } else if (weight < string1) { | |||
| return { | |||
| standard: "偏瘦", | |||
| text: `基于目前的身体状况,您的标准体重范围为${string1}~${string2}kg,保持理想体重有助于身体各机能持续健康运转,维持最佳代谢状态。体重偏瘦或许已经危害到你的健康,建议您保持良好睡眠,适当食用含高卡路里食物,保持良好的饮食习惯。`, | |||
| }; | |||
| } else if (weight >= string1 && weight < string2) { | |||
| return { | |||
| standard: "标准", | |||
| text: `当前体重为${weight}kg,处于标准体重范围,状态良好,保持良好的饮食习惯和适当的运动,追求完美身材吧。`, | |||
| }; | |||
| } else if (weight >= string2 && weight < string3) { | |||
| return { | |||
| standard: "偏胖", | |||
| text: `当前体重为${weight}kg,体重处于不健康区间!请减少高油高热量食物摄入,加强身体锻炼,努力恢复健康体重和好身材。`, | |||
| }; | |||
| } else if (weight >= string3) { | |||
| return { | |||
| standard: "肥胖", | |||
| text: `当前体重为${weight}kg,远高于标准体重,过度肥胖不仅形体臃肿,更是各种慢性疾病的主要导火线,请减少高脂肪、高热量食物的摄入,制定健身计划,加强锻炼,努力恢复健康体重和好身材。`, | |||
| }; | |||
| } | |||
| return {}; | |||
| } | |||
| //BMI标准 | |||
| function getBMIDisplay(BMI) { | |||
| var standard = ""; | |||
| if (BMI < 18.5 && BMI > 0) { | |||
| standard = "偏瘦"; | |||
| } else if (18.5 <= BMI && BMI < 25) { | |||
| standard = "标准"; | |||
| } else if (25 <= BMI && BMI < 30) { | |||
| standard = "偏胖"; | |||
| } else if (BMI >= 30) { | |||
| standard = "肥胖 "; | |||
| } | |||
| return { | |||
| standard: standard, | |||
| text: `BMI(即身体质量指数,简称体质指数,英文为Body Mass Index,简称BMI),是用体重公斤数除以身高米数平方得出的数字,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。根据您目前的身高体重远高于标准值,我们建议您采用科学的减肥方式,适当减轻体重,避免因肥胖导致的健康问题。`, | |||
| }; | |||
| } | |||
| //体脂率标准 | |||
| function getFatRateDisplay(fatRate, sex, age) { | |||
| if (age >= 30) { | |||
| if (sex == 1) { | |||
| if (fatRate < 11) { | |||
| return { | |||
| standard: "偏低", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏低,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,建议均衡搭配饮食,适当增加卡路里摄入量。`, | |||
| }; | |||
| } else if (fatRate >= 11 && fatRate < 22) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平标准。保持健康规律作息,注意保持摄入足够水分,增加代谢,有利于保持健康标准体脂率。 `, | |||
| }; | |||
| } else if (fatRate >= 22 && fatRate < 27) { | |||
| return { | |||
| standard: "偏高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } else if (fatRate >= 27) { | |||
| return { | |||
| standard: "高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平严重偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } | |||
| } else { | |||
| if (fatRate < 21) { | |||
| return { | |||
| standard: "偏低", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏低,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,建议均衡搭配饮食,适当增加卡路里摄入量。`, | |||
| }; | |||
| } else if (fatRate >= 21 && fatRate < 32) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平标准。保持健康规律作息,注意保持摄入足够水分,增加代谢,有利于保持健康标准体脂率。 `, | |||
| }; | |||
| } else if (fatRate >= 32 && fatRate < 39) { | |||
| return { | |||
| standard: "偏高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } else if (fatRate >= 39) { | |||
| return { | |||
| standard: "高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平严重偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } | |||
| } | |||
| } else if (0 < age && age < 30) { | |||
| if (sex == 1) { | |||
| if (fatRate < 10) { | |||
| return { | |||
| standard: "偏低", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏低,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,建议均衡搭配饮食,适当增加卡路里摄入量。`, | |||
| }; | |||
| } else if (fatRate >= 10 && fatRate < 21) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平标准。保持健康规律作息,注意保持摄入足够水分,增加代谢,有利于保持健康标准体脂率。 `, | |||
| }; | |||
| } else if (fatRate >= 21 && fatRate < 26) { | |||
| return { | |||
| standard: "偏高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } else if (fatRate >= 26) { | |||
| return { | |||
| standard: "高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平严重偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } | |||
| } else { | |||
| if (fatRate < 20) { | |||
| return { | |||
| standard: "偏低", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏低,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,建议均衡搭配饮食,适当增加卡路里摄入量。`, | |||
| }; | |||
| } else if (fatRate >= 20 && fatRate < 31) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平标准。保持健康规律作息,注意保持摄入足够水分,增加代谢,有利于保持健康标准体脂率。 `, | |||
| }; | |||
| } else if (fatRate >= 31 && fatRate < 38) { | |||
| return { | |||
| standard: "偏高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } else if (fatRate >= 38) { | |||
| return { | |||
| standard: "高", | |||
| text: `您的体脂率为${fatRate}%,体脂肪水平严重偏高,处于危险区间。脂肪是维持人体新陈谢和运动的能量物质,过多/过少都不利于健康,请注意控制高油高脂食物的摄入,并且多做运动。`, | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| //肌肉率标准 | |||
| function getMuscleDisplay(muscle, sex, muscleWeight) { | |||
| if (sex == 1) { | |||
| if (muscle < 40) { | |||
| return { | |||
| standard: "不足", | |||
| text: `你当前的肌肉率为${muscle}%,肌肉含量为${muscleWeight}kg,体内的肌肉含量不足。增加肌肉量能让您更快的消耗热量,以最健康的方式减掉多余脂肪。合理的饮食,适量的运动,能够增加肌肉含量。`, | |||
| }; | |||
| } else if (40 <= muscle && muscle < 60) { | |||
| return { | |||
| standard: "标准", | |||
| text: `你当前的肌肉率为${muscle}%,肌肉含量为${muscleWeight}kg,体内的肌肉含量标准,身体匀称健康,请您保持锻炼。`, | |||
| }; | |||
| } else if (60 <= muscle) { | |||
| return { | |||
| standard: "优", | |||
| text: `你当前的肌肉率为${muscle}%,肌肉含量为${muscleWeight}kg,体内肌肉结量比较充足,请继续保持适当的运动量和合理的饮食。`, | |||
| }; | |||
| } | |||
| } else { | |||
| if (muscle < 30) { | |||
| return { | |||
| standard: "不足", | |||
| text: `你当前的肌肉率为${muscle}%,肌肉含量为${muscleWeight}kg,体内的肌肉含量不足。增加肌肉量能让您更快的消耗热量,以最健康的方式减掉多余脂肪。合理的饮食,适量的运动,能够增加肌肉含量。`, | |||
| }; | |||
| } else if (30 <= muscle && muscle < 50) { | |||
| return { | |||
| standard: "标准", | |||
| text: `你当前的肌肉率为${muscle}%,肌肉含量为${muscleWeight}kg,体内的肌肉含量标准,身体匀称健康,请您保持锻炼。`, | |||
| }; | |||
| } else if (50 <= muscle) { | |||
| return { | |||
| standard: "优", | |||
| text: `你当前的肌肉率为${muscle}%,肌肉含量为${muscleWeight}kg,体内肌肉结量比较充足,请继续保持适当的运动量和合理的饮食。`, | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| //水分标准 | |||
| function getMoistureDisplay(moisture, sex) { | |||
| if (sex == 1) { | |||
| if (moisture < 55) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您当前的身体水分含量为${moisture}%,水分处于偏低水平。身体里充足的水分能帮助您更好的消化食物和吸收养分,并促进代谢,带走身体毒素。建议您保持规律的饮食,每天八杯水,这样就可以维持正常的身体水分平衡。`, | |||
| }; | |||
| } else if (55 <= moisture && moisture < 65) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您当前的身体水分含量为${moisture}%,水分处于标准区间,请继续保持健康的饮食习惯。`, | |||
| }; | |||
| } else if (50 <= moisture) { | |||
| return { | |||
| standard: "优", | |||
| text: `您当前的身体水分含量为${moisture}%,水分处于优良状态。适量饮水,适当运动,继续保持健康的饮食习惯,有助于保持良好的身体状态哦。`, | |||
| }; | |||
| } | |||
| } else { | |||
| if (moisture < 45) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您当前的身体水分含量为${moisture}%,水分处于偏低水平。身体里充足的水分能帮助您更好的消化食物和吸收养分,并促进代谢,带走身体毒素。建议您保持规律的饮食,每天八杯水,这样就可以维持正常的身体水分平衡。`, | |||
| }; | |||
| } else if (45 <= moisture && moisture < 60) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您当前的身体水分含量为${moisture}%,水分处于标准区间,请继续保持健康的饮食习惯。`, | |||
| }; | |||
| } else if (60 <= moisture) { | |||
| return { | |||
| standard: "优", | |||
| text: `您当前的身体水分含量为${moisture}%,水分处于优良状态。适量饮水,适当运动,继续保持健康的饮食习惯,有助于保持良好的身体状态哦。`, | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| //骨重标准 | |||
| function getBonemassDisplay(bonemass, sex, weight) { | |||
| if (sex == 1) { | |||
| if (weight < 60) { | |||
| if (bonemass < 2.4) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的骨量水平偏低,建议补充含钙丰富的食品,均衡饮食,进行适量运动,有助于钙质的吸收。`, | |||
| }; | |||
| } else if (2.4 <= bonemass && bonemass <= 2.6) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的骨量水平标准,骨量在短期内不会出现明显变化,您只要保证健康的饮食和适当的锻炼,就可以维持稳定的骨量水平。`, | |||
| }; | |||
| } else if (2.6 < bonemass) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的骨量水平高于标准水平,这说明您的生活习惯比较健康,营养摄入均衡。继续保持良好的生活习惯,有助于保持良好的骨量水平。`, | |||
| }; | |||
| } | |||
| } else if (60 <= weight && weight < 75) { | |||
| if (bonemass < 2.8) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的骨量水平偏低,建议补充含钙丰富的食品,均衡饮食,进行适量运动,有助于钙质的吸收。`, | |||
| }; | |||
| } else if (2.8 <= bonemass && bonemass <= 3.0) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的骨量水平标准,骨量在短期内不会出现明显变化,您只要保证健康的饮食和适当的锻炼,就可以维持稳定的骨量水平。`, | |||
| }; | |||
| } else if (3.0 < bonemass) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的骨量水平高于标准水平,这说明您的生活习惯比较健康,营养摄入均衡。继续保持良好的生活习惯,有助于保持良好的骨量水平。`, | |||
| }; | |||
| } | |||
| } else if (75 <= weight) { | |||
| if (bonemass < 3.1) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的骨量水平偏低,建议补充含钙丰富的食品,均衡饮食,进行适量运动,有助于钙质的吸收。`, | |||
| }; | |||
| } else if (3.1 <= bonemass && bonemass <= 3.3) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的骨量水平标准,骨量在短期内不会出现明显变化,您只要保证健康的饮食和适当的锻炼,就可以维持稳定的骨量水平。`, | |||
| }; | |||
| } else if (3.3 < bonemass) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的骨量水平高于标准水平,这说明您的生活习惯比较健康,营养摄入均衡。继续保持良好的生活习惯,有助于保持良好的骨量水平。`, | |||
| }; | |||
| } | |||
| } | |||
| } else { | |||
| if (weight < 45) { | |||
| if (bonemass < 1.7) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的骨量水平偏低,建议补充含钙丰富的食品,均衡饮食,进行适量运动,有助于钙质的吸收。`, | |||
| }; | |||
| } else if (1.7 <= bonemass && bonemass <= 1.9) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的骨量水平标准,骨量在短期内不会出现明显变化,您只要保证健康的饮食和适当的锻炼,就可以维持稳定的骨量水平。`, | |||
| }; | |||
| } else if (1.9 < bonemass) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的骨量水平高于标准水平,这说明您的生活习惯比较健康,营养摄入均衡。继续保持良好的生活习惯,有助于保持良好的骨量水平。`, | |||
| }; | |||
| } | |||
| } else if (45 <= weight && weight < 60) { | |||
| if (bonemass < 2.1) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的骨量水平偏低,建议补充含钙丰富的食品,均衡饮食,进行适量运动,有助于钙质的吸收。`, | |||
| }; | |||
| } else if (2.1 <= bonemass && bonemass <= 2.3) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的骨量水平标准,骨量在短期内不会出现明显变化,您只要保证健康的饮食和适当的锻炼,就可以维持稳定的骨量水平。`, | |||
| }; | |||
| } else if (2.3 < bonemass) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的骨量水平高于标准水平,这说明您的生活习惯比较健康,营养摄入均衡。继续保持良好的生活习惯,有助于保持良好的骨量水平。`, | |||
| }; | |||
| } | |||
| } else if (60 <= weight) { | |||
| if (bonemass < 2.4) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的骨量水平偏低,建议补充含钙丰富的食品,均衡饮食,进行适量运动,有助于钙质的吸收。`, | |||
| }; | |||
| } else if (2.4 <= bonemass && bonemass <= 2.6) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的骨量水平标准,骨量在短期内不会出现明显变化,您只要保证健康的饮食和适当的锻炼,就可以维持稳定的骨量水平。`, | |||
| }; | |||
| } else if (2.6 < bonemass) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的骨量水平高于标准水平,这说明您的生活习惯比较健康,营养摄入均衡。继续保持良好的生活习惯,有助于保持良好的骨量水平。`, | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| //基础代谢率标准 | |||
| function getBMRDisplay(BMR, age, weight, sex) { | |||
| var standard = 0; | |||
| if (sex == 1) { | |||
| if (0 < age && age < 3) { | |||
| standard = 60.9 * weight - 54; | |||
| } else if (3 <= age && age < 10) { | |||
| standard = 22.7 * weight + 495; | |||
| } else if (10 <= age && age < 18) { | |||
| standard = 17.5 * weight + 651; | |||
| } else if (18 <= age && age < 30) { | |||
| standard = 15.3 * weight + 679; | |||
| } else if (30 <= age) { | |||
| standard = 11.6 * weight + 879; | |||
| } | |||
| } else { | |||
| if (0 < age && age < 3) { | |||
| standard = 61.0 * weight - 51; | |||
| } else if (3 <= age && age < 10) { | |||
| standard = 22.5 * weight + 499; | |||
| } else if (10 <= age && age < 18) { | |||
| standard = 12.2 * weight + 746; | |||
| } else if (18 <= age && age < 30) { | |||
| standard = 14.7 * weight + 496; | |||
| } else if (30 <= age) { | |||
| standard = 8.7 * weight + 820; | |||
| } | |||
| } | |||
| if (BMR < standard) { | |||
| return { | |||
| standard: "偏低", | |||
| text: `基于您的基础代谢水平,推荐您每日的摄入热量为${standard}kcal.您的基础代谢率为${BMR}kcal,低于标准区间。均衡合理的热量摄入,适量运动能帮助您健康减脂,达到理想身材。 `, | |||
| }; | |||
| } else { | |||
| return { | |||
| standard: "优", | |||
| text: `您的基础代谢率为${BMR}kcal,目前已达标。每天进行一些低强度的运动,合理的热量摄入有助您增加肌肉。`, | |||
| }; | |||
| } | |||
| } | |||
| //内脏脂肪指数标准 | |||
| function getVisceralfatDisplay(visceralfat) { | |||
| if (visceralfat < 9) { | |||
| return { | |||
| standard: "标准", | |||
| text: `内脏脂肪指数反映人体内内脏脂肪堆积的程度。保持标准的内脏脂肪指数,可以大幅降低心脏病、高血压、高血脂和2型糖尿病的发病风险。您的内脏脂肪水平正常,请继续保持健康饮食和适当运动。`, | |||
| }; | |||
| } else if (9 <= visceralfat && visceralfat < 14) { | |||
| return { | |||
| standard: "警惕", | |||
| text: `您的内脏脂肪处于偏高范围内,内脏脂肪指数偏高,将增加心脏病、高血压、高血脂和2型糖尿病的发病风险。健康您控制饮食,减少糖分高、脂肪高、油炸等食物摄入,多吃谷类、蔬菜、水果等富含维生素、蛋白的蔬菜水果,同时多做运动。`, | |||
| }; | |||
| } else if (14 <= visceralfat) { | |||
| return { | |||
| standard: "危险", | |||
| text: `您的内脏脂肪水平严重偏高,内脏脂肪指数偏高,将增加心脏病、高血压、高血脂和2型糖尿病的发病风险。健康您控制饮食,减少糖分高、脂肪高、油炸等食物摄入,多吃谷类、蔬菜、水果等富含维生素、蛋白的蔬菜水果,同时多做运动。`, | |||
| }; | |||
| } | |||
| } | |||
| //皮下脂肪标准 | |||
| function getSubcutaneousFatDisplay(proteinRate, sex) { | |||
| if (sex == 1) { | |||
| if (proteinRate < 7) { | |||
| return { | |||
| standard: "不足", | |||
| text: `皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织。皮下脂肪主要的作用有 绝热和贮存 。皮下脂肪是人体储存‘余粮’的主要场所。您目前处于正常水平以下,不足的皮下脂肪可能会出现身体偏瘦,皮肤缺乏光泽或有全身痛,没力气等现象,建议你平时注意饮食加强营养,避免劳累情绪激动,适当运动锻炼,避免受风寒着凉。`, | |||
| }; | |||
| } else if (7 <= proteinRate && proteinRate < 15) { | |||
| return { | |||
| standard: "标准", | |||
| text: `皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织。皮下脂肪主要的作用有 绝热和贮存 您的皮下脂肪处于正常水平。坚持合理的饮食,良好的生活习惯,适量运动,就可以使身材和健康状态都保持在良好的范围内。`, | |||
| }; | |||
| } else if (15 <= proteinRate) { | |||
| return { | |||
| standard: "偏高", | |||
| text: `您的皮下脂肪高于正常水平。高糖分高脂肪饮食、久坐少动、遗传因素等都是引起皮下脂肪偏高的原因。建议注意均衡饮食,保持良好的生活习惯,控制热量摄入,进行适当运动。`, | |||
| }; | |||
| } | |||
| } else { | |||
| if (proteinRate < 11) { | |||
| return { | |||
| standard: "不足", | |||
| text: `皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织。皮下脂肪主要的作用有 绝热和贮存 。皮下脂肪是人体储存‘余粮’的主要场所。您目前处于正常水平以下,不足的皮下脂肪可能会出现身体偏瘦,皮肤缺乏光泽或有全身痛,没力气等现象,建议你平时注意饮食加强营养,避免劳累情绪激动,适当运动锻炼,避免受风寒着凉。`, | |||
| }; | |||
| } else if (11 <= proteinRate && proteinRate < 17) { | |||
| return { | |||
| standard: "标准", | |||
| text: `皮下脂脂肪就是贮存于皮下的脂肪组织,人体的脂肪大约有2/3贮存在皮下组织。皮下脂肪主要的作用有 绝热和贮存 您的皮下脂肪处于正常水平。坚持合理的饮食,良好的生活习惯,适量运动,就可以使身材和健康状态都保持在良好的范围内。`, | |||
| }; | |||
| } else if (17 <= proteinRate) { | |||
| return { | |||
| standard: "偏高", | |||
| text: `您的皮下脂肪高于正常水平。高糖分高脂肪饮食、久坐少动、遗传因素等都是引起皮下脂肪偏高的原因。建议注意均衡饮食,保持良好的生活习惯,控制热量摄入,进行适当运动。`, | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| //蛋白率 | |||
| function getProteinRateDisplay(proteinRate, sex) { | |||
| if (sex == 1) { | |||
| if (proteinRate < 16) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的蛋白水平偏低。缺乏蛋白质会引起免疫力下降、肌肉无力和贫血。建议你保持健康饮食,不过分节食,补充足够的营养。`, | |||
| }; | |||
| } else if (16 <= proteinRate && proteinRate <= 18) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的蛋白水平比例充足,请继续保持,同时也要防止过度摄入,蛋白质过度摄入也会在体内转化成脂肪,造成脂肪堆积。`, | |||
| }; | |||
| } else if (18 < proteinRate) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的蛋白水平优于标准水平,继续保持良好的作息、均衡的饮食,更有助于蛋白质的吸收。`, | |||
| }; | |||
| } | |||
| } else { | |||
| if (proteinRate < 14) { | |||
| return { | |||
| standard: "不足", | |||
| text: `您的蛋白水平偏低。缺乏蛋白质会引起免疫力下降、肌肉无力和贫血。建议你保持健康饮食,不过分节食,补充足够的营养。`, | |||
| }; | |||
| } else if (14 <= proteinRate && proteinRate <= 16) { | |||
| return { | |||
| standard: "标准", | |||
| text: `您的蛋白水平比例充足,请继续保持,同时也要防止过度摄入,蛋白质过度摄入也会在体内转化成脂肪,造成脂肪堆积。`, | |||
| }; | |||
| } else if (16 < proteinRate) { | |||
| return { | |||
| standard: "优", | |||
| text: `您的蛋白水平优于标准水平,继续保持良好的作息、均衡的饮食,更有助于蛋白质的吸收。`, | |||
| }; | |||
| } | |||
| } | |||
| } | |||
| //身体年龄 | |||
| function getPhysicalAgeDisplay(physicalAge, age) { | |||
| if (physicalAge > age) { | |||
| return { | |||
| standard: "偏大", | |||
| text: `身体年龄是以基础代谢为基础,综合体重、身高、脂肪、肌肉等数值,换算所得出的数值。所以身体年龄是一个高于或低于实际年龄的综合判断标准。仅供参考。`, | |||
| }; | |||
| } else if (physicalAge == age) { | |||
| return { | |||
| standard: "标准", | |||
| text: `身体年龄是以基础代谢为基础,综合体重、身高、脂肪、肌肉等数值,换算所得出的数值。所以身体年龄是一个高于或低于实际年龄的综合判断标准。仅供参考。`, | |||
| }; | |||
| } else if (physicalAge < age) { | |||
| return { | |||
| standard: "优", | |||
| text: `身体年龄是以基础代谢为基础,综合体重、身高、脂肪、肌肉等数值,换算所得出的数值。所以身体年龄是一个高于或低于实际年龄的综合判断标准。仅供参考。`, | |||
| }; | |||
| } | |||
| } | |||
| //脂肪量标准 同 体脂率标准 | |||
| function getFatWeightDisplay(fatRate, sex, age) { | |||
| getFatRateDisplay(fatRate, sex, age) | |||
| } | |||
| //肌肉量标准 同 肌肉率标准 | |||
| function getMuscleMassDisplay(muscle, sex, muscleWeight) { | |||
| getMuscleDisplay(muscle, sex, muscleWeight) | |||
| } | |||
| //蛋白量标准 同 蛋白率标准 | |||
| function getProteinDisplay(proteinRate, sex) { | |||
| getProteinRateDisplay(proteinRate, sex) | |||
| } | |||
| //肥胖等级 stWeight=标准体重 | |||
| function getFatLevel(weight, stWeight, height) { | |||
| var Level = (weight - stWeight) / stWeight; | |||
| if (Level < -0.2) { | |||
| return { | |||
| standard: "体重不足", | |||
| text: `肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。基于目前的身体状况,您的标准体重范围为${ | |||
| 18.5 * height * height | |||
| }~${ | |||
| 25 * height * height | |||
| }kg,保持理想体重有助于身体各机能持续健康运转,维持最佳代谢状态。体重偏瘦或许已经危害到你的健康,建议您保持良好睡眠,适当食用含高卡路里食物,保持良好的饮食习惯。`, | |||
| }; | |||
| } else if (Level >= -0.2 && Level < -0.1) { | |||
| return { | |||
| standard: "偏瘦", | |||
| text: `肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。基于目前的身体状况,您的标准体重范围为${ | |||
| 18.5 * height * height | |||
| }~${ | |||
| 25 * height * height | |||
| }kg,保持理想体重有助于身体各机能持续健康运转,维持最佳代谢状态。体重偏瘦或许已经危害到你的健康,建议您保持良好睡眠,适当食用含高卡路里食物,保持良好的饮食习惯。`, | |||
| }; | |||
| } else if (Level >= -0.1 && Level < 0.1) { | |||
| return { | |||
| standard: "标准", | |||
| text: `肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。当前体重处于标准体重范围,状态良好,请继续保持良好的饮食习惯和适当的运动,保持完美身材吧。`, | |||
| }; | |||
| } else if (Level > 0.1 && Level <= 0.2) { | |||
| return { | |||
| standard: "偏重", | |||
| text: `肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。当前体重为${weight}kg,高于标准体重,过度肥胖不仅形体臃肿,更是各种慢性疾病的主要导火线,请减少高脂肪、高热量食物的摄入,制定健身计划,加强锻炼,努力恢复健康体重和好身材。`, | |||
| }; | |||
| } else if (Level > 0.2) { | |||
| return { | |||
| standard: "超重", | |||
| text: `肥胖的程度,表现实际体重与理想体重的差距。肥胖等级是判定肥胖症的一个指标。当前体重为${weight}kg,高于标准体重,过度肥胖不仅形体臃肿,更是各种慢性疾病的主要导火线,请减少高脂肪、高热量食物的摄入,制定健身计划,加强锻炼,努力恢复健康体重和好身材。`, | |||
| }; | |||
| } | |||
| } | |||
| //体型 | |||
| function getBodyLevel(BFRResult, ROMResult) { | |||
| if ((BFRResult == 2 || BFRResult == 3) && ROMResult == 0) { | |||
| return "隐形肥胖"; | |||
| } else if ((BFRResult == 2 || BFRResult == 3) && ROMResult == 1) { | |||
| return "偏胖"; | |||
| } else if ((BFRResult == 2 || BFRResult == 3) && ROMResult == 2) { | |||
| return "结实型偏胖"; | |||
| } else if (BFRResult == 1 && ROMResult == 0) { | |||
| return "缺乏肌肉型"; | |||
| } else if (BFRResult == 1 && ROMResult == 1) { | |||
| return "标准型"; | |||
| } else if (BFRResult == 1 && ROMResult == 2) { | |||
| return "标准肌肉型"; | |||
| } else if (BFRResult == 0 && ROMResult == 0) { | |||
| return "偏瘦"; | |||
| } else if (BFRResult == 0 && ROMResult == 1) { | |||
| return "偏瘦肌肉型"; | |||
| } else if (BFRResult == 0 && ROMResult == 2) { | |||
| return "健美肌肉型"; | |||
| } | |||
| } | |||
| //身体评分 | |||
| function getWeightScore(bmi) { | |||
| if (bmi < 21.6) { | |||
| return bmi / 21.6 * 100; | |||
| } else { | |||
| return 21.6 / bmi * 100; | |||
| } | |||
| } | |||
| @@ -0,0 +1,5 @@ | |||
| const standard = require("./standard") | |||
| module.exports = { | |||
| ...standard, | |||
| } | |||