新增扫描条形码获取食物

This commit is contained in:
qcl_123 2026-01-27 16:10:01 +08:00
parent 022b1b3a37
commit 8e28df3158
61 changed files with 993 additions and 262 deletions

View File

@ -5,7 +5,7 @@
<image src="/static/zhong.png"></image> <image src="/static/zhong.png"></image>
<text @click="openBluetoothAdapter">{{bleTipsText}}</text> <text @click="openBluetoothAdapter">{{bleTipsText}}</text>
</view> </view>
<view class="duan" @click="handleBack" v-if="isShow&&isConnection == 0"> <view class="duan" @click="handleBack" v-if="isShow&&isConnection == 2">
断开连接 断开连接
</view> </view>
</view> </view>
@ -22,7 +22,7 @@
<view class="btn danwei"> <view class="btn danwei">
<view class="lan border-bottom"> <view class="lan border-bottom">
<view class="right"> <view class="right">
<picker mode="selector" :range="unitList" range-key="name" @change="changleUnits" <picker mode="selector" :range="unitA" range-key="name" @change="changleUnits"
:value="unitListIndex"> :value="unitListIndex">
<view class="uni-input"> <view class="uni-input">
单位 单位
@ -56,22 +56,10 @@
return { return {
kcal: 0, kcal: 0,
unit: '', unit: '',
// weight: "",
bleTipsText: "", bleTipsText: "",
inputDialog: false, inputDialog: false,
unitList: [{ unitA: [],
name: "克",
id: '00',
unit: "g"
}, {
name: "盎司",
id: "08",
unit: "oz"
}],
unitListIndex: 0, unitListIndex: 0,
units: ['kg', '斤', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
'milkml', 'oz', 'floz', 'lboz'
]
} }
}, },
props: { props: {
@ -82,12 +70,13 @@
btnType: { btnType: {
type: Number, type: Number,
default: 1 //12 default: 1 //12
}, }
}, },
computed: { computed: {
...mapState(["bleValue", "isBluetoothTyle", "countFoodInfo"]), ...mapState(["bleValue", "isBluetoothTyle", "countFoodInfo"]),
weight() { weight() {
this.kcal = (Number(this.weightKcal) / 100 * this.bleValue.countWeight).toFixed(2) let weightNew = this.convertToGrams(this.bleValue.countWeight, this.bleValue.unit)
this.kcal = (Number(this.weightKcal) / 100 * weightNew).toFixed(1)
this.unit = this.bleValue.unit this.unit = this.bleValue.unit
return this.bleValue.countWeight return this.bleValue.countWeight
}, },
@ -97,8 +86,7 @@
}, },
isShow() { isShow() {
return this.bleValue.serviceId != '' ? true : false return this.bleValue.serviceId != '' ? true : false
} },
}, },
mounted() { mounted() {
let that = this let that = this
@ -118,12 +106,19 @@
that.handleBack() that.handleBack()
} }
}, },
bleValue: {
handler(newVal, oldVal) {
this.unitA = newVal.unitList
},
deep: true,
immediate: true
},
}, },
methods: { methods: {
// //
openBluetoothAdapter() { openBluetoothAdapter() {
let that = this let that = this
if (that.isConnection == 0) return if (that.isConnection == 2) return
that.kcal = "" that.kcal = ""
that.$store.commit('changeBluetoothValue', { that.$store.commit('changeBluetoothValue', {
deviceId: "", deviceId: "",
@ -131,26 +126,74 @@
notify: '', notify: '',
write: '', write: '',
unit: "g", unit: "g",
type: 1,
unitList: that.$json.unitMinus,
countWeight: "", countWeight: "",
bleTipsText: "蓝牙搜索中", bleTipsText: "蓝牙搜索中",
isConnectStatus: 0, isConnectStatus: 0,
}) })
that.$ble.openBluetoothAdapter() that.$ble.openBluetoothAdapter()
}, },
changleUnits(e) { changleUnits(e) {
let that = this let that = this
let name = that.unitList[e.detail.value].name let name = that.unitA[e.detail.value].name
console.log("单位切换", name, that.unit) let val = that.unitA[e.detail.value].unit
if (that.isShow && that.unit != name) { if (that.isShow && that.unit != name) {
that.handletoggleUnit(name == '盎司' ? 0x08 : 0x04) that.handletoggleUnit(that.unitConversion2(val))
} }
if (that.bleValue.serviceId == '') {
that.unitListIndex = [e.detail.value] that.unitListIndex = [e.detail.value]
that.$store.commit('changeBluetoothValue', { that.$store.commit('changeBluetoothValue', {
unit: that.unitList[e.detail.value].unit unit: that.unitA[e.detail.value].unit,
}) })
}
}, },
convertToGrams(value, fromUnit) {
const conversionFactors = {
'lb': 453.59237, // 1 = 453.59237
'oz': 28.349523125, // 1 = 28.349523125
'kg': 1000, // 1 = 1000
'g': 1,
'ml': 1,
'斤': 500,
'Waterml': 1,
'milkml': 1.03
// "stlb": "floz": "lboz":
};
if (!conversionFactors.hasOwnProperty(fromUnit)) {
return ''
}
return value * conversionFactors[fromUnit];
},
unitConversion2(unit) {
if (unit == 'kg') {
return 0x00
} else if (unit == '斤') {
return 0x01
} else if (unit == 'st:lb') {
return 0x02
} else if (unit == 'lb') {
return 0x03
} else if (unit == 'g') {
return 0x04
} else if (unit == 'ml') {
return 0x05
} else if (unit == 'Waterml') {
return 0x06
} else if (unit == 'milkml') {
return 0x07
} else if (unit == 'oz') {
return 0x08
} else if (unit == 'floz') {
return 0x09
} else if (unit == 'lboz') {
return 0x0A
}
return unit
},
//
handletoggleUnit(unit) { handletoggleUnit(unit) {
let that = this let that = this
let checksum = 0; let checksum = 0;
@ -162,6 +205,7 @@
bytes[5] = checksum bytes[5] = checksum
that.sendData(new Uint8Array(bytes).buffer) that.sendData(new Uint8Array(bytes).buffer)
}, },
//
handleqingling() { handleqingling() {
let that = this let that = this
let str = "C503071100D0" let str = "C503071100D0"
@ -199,6 +243,7 @@
let that = this let that = this
that.$store.commit("changeBluetoothValue", { that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接失败,点击重新连接", bleTipsText: "连接失败,点击重新连接",
unitList: that.$json.unitMinus,
isConnectStatus: 1 isConnectStatus: 1
}) })
that.$ble.stopBluetoothDevicesDiscovery() // that.$ble.stopBluetoothDevicesDiscovery() //
@ -207,14 +252,28 @@
}, },
unitConversion(unit) { unitConversion(unit) {
if (unit == 'kcal') { if (unit == 'kg') {
return '千卡' return '千克'
} else if (unit == '斤') {
return '斤'
} else if (unit == 'stlb') {
return 'stlb'
} else if (unit == '磅') {
return '磅'
} else if (unit == 'g') { } else if (unit == 'g') {
return '克' return '克'
} else if (unit == 'lb') { } else if (unit == 'ml') {
return '磅' return '毫升'
} else if (unit == 'Waterml') {
return 'Waterml'
} else if (unit == 'milkml') {
return 'milkml'
} else if (unit == 'oz') { } else if (unit == 'oz') {
return '盎司' return '盎司'
} else if (unit == 'floz') {
return 'floz'
} else if (unit == 'lboz') {
return 'lboz'
} }
return unit return unit
}, },
@ -229,9 +288,11 @@
}, },
confirm(value) { confirm(value) {
console.log(value) console.log(value)
let that = this
this.$store.commit("changeBluetoothValue", { this.$store.commit("changeBluetoothValue", {
countWeight: value, countWeight: value,
unit: this.unitList[this.unitListIndex].unit unitList: that.$json.unitMinus,
unit: this.unitA[this.unitListIndex].unit
}) })
this.$refs.popup.close() this.$refs.popup.close()
}, },

View File

@ -10,6 +10,71 @@
"name": "晚加餐", "name": "晚加餐",
"id": 5 "id": 5
} }
] ],
"unitArray": [{
"name": "千克",
"unit": "kg"
},
{
"name": "斤",
"unit": "斤"
},
{
"name": "stlb",
"unit": "stlb"
},
{
"name": "磅",
"unit": "lb"
}, {
"name": "克",
"unit": "g"
}, {
"name": "毫升",
"unit": "ml"
},
{
"name": "Waterml",
"unit": "Waterml"
},
{
"name": "milkml",
"unit": "milkml"
},
{
"name": "盎司",
"unit": "oz"
},
{
"name": "floz",
"unit": "floz"
},
{
"name": "lboz",
"unit": "lboz"
}
],
"unitMinus": [{
"name": "千克",
"unit": "kg"
},
{
"name": "磅",
"unit": "lb"
}, {
"name": "克",
"unit": "g"
}, {
"name": "毫升",
"unit": "ml"
},
{
"name": "盎司",
"unit": "oz"
}
],
"units": ["kg", "斤", "stlb", "lb", "g", "ml", "Waterml", "milkml", "oz", "floz", "lboz"]
} }

View File

@ -2,8 +2,8 @@
"name" : "kitchendDevice", "name" : "kitchendDevice",
"appid" : "__UNI__20604F1", "appid" : "__UNI__20604F1",
"description" : "", "description" : "",
"versionName" : "1.0.0", "versionName" : "2.0.0",
"versionCode" : "100", "versionCode" : 200,
"transformPx" : false, "transformPx" : false,
"sassImplementationName" : "node-sass", "sassImplementationName" : "node-sass",
/* 5+App */ /* 5+App */

View File

@ -69,6 +69,10 @@
<uni-icons type="mic-filled" size="20" color="#fff"></uni-icons> <uni-icons type="mic-filled" size="20" color="#fff"></uni-icons>
语音搜索 语音搜索
</view> </view>
<view class="mic-icon mic-icon2" @click="scanCode">
<uni-icons type="scan" size="20" color="#fff"></uni-icons>
扫一扫
</view>
</view> </view>
<!-- 搜索列表 --> <!-- 搜索列表 -->
<view class="search_list" v-if="search_list.length"> <view class="search_list" v-if="search_list.length">
@ -180,7 +184,8 @@
v-if="item.color != ''"></view> v-if="item.color != ''"></view>
<text>{{item.name}}({{unitConversion(item.unit)}})</text> <text>{{item.name}}({{unitConversion(item.unit)}})</text>
</view> </view>
<view class="value">{{ Number(activeType.weight/100 * item.value).toFixed(1) }} <view class="value">
{{Number((activeType.weight)/100 * item.value).toFixed(1) }}
</view> </view>
</view> </view>
</view> </view>
@ -195,14 +200,14 @@
<view class="foodContent"> <view class="foodContent">
<view class="tips"> <view class="tips">
<text>营养素</text> <text>营养素</text>
<text>{{Math.floor(activeType.weight)}}克含量</text> <text>{{(activeType.weight).toFixed(1)}}克含量</text>
</view> </view>
<view class="foodDetailList"> <view class="foodDetailList">
<view class="foodDetailItem" v-for="(item,index) in activeType.nutrients_list" <view class="foodDetailItem" v-for="(item,index) in activeType.nutrients_list"
:key="index"> :key="index">
<view class="name">{{item.name_ch}}</view> <view class="name">{{item.name_ch}}</view>
<view class="value"> <view class="value">
{{Number(item.value*activeType.weight/100).toFixed(2)}}{{item.unit}} {{Number((activeType.weight)/100 * item.value).toFixed(1)}}{{item.unit}}
</view> </view>
</view> </view>
</view> </view>
@ -291,9 +296,12 @@
bleValue: { bleValue: {
handler(newVal, oldVal) { handler(newVal, oldVal) {
this.realTimeWeight(newVal.countWeight, newVal.unit) this.realTimeWeight(newVal.countWeight, newVal.unit)
if (newVal.type == 2 && Number(newVal.countWeight) > 0) {
this.handletoggleUnit(newVal.countWeight, newVal.unit, this.activeType.nutrients_four)
}
}, },
deep: true deep: true
} },
}, },
mounted() { mounted() {
let that = this let that = this
@ -345,6 +353,29 @@
} }
// #endif // #endif
}, },
scanCode() {
let that = this
uni.scanCode({
onlyFromCamera: true,
success: function(res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
that.$model.getPhotoSearch({
barcode: "6920584471017",
}).then(res => {
if (res.code != 0) {
that.$tools.msg(res.msg)
return
}
that.handleDetail(res.data)
})
},
fail: res => {
that.$api.msg("您已取消操作")
return
}
});
},
// //
handleToggle(name) { handleToggle(name) {
this.search_value = "" this.search_value = ""
@ -354,7 +385,6 @@
}, },
// //
realTimeWeight(weight, unit) { realTimeWeight(weight, unit) {
// console.log("", weight, unit)
this.activeType = Object.assign({}, this.activeType, { this.activeType = Object.assign({}, this.activeType, {
weight: this.convertToGrams(weight, unit) weight: this.convertToGrams(weight, unit)
}) })
@ -369,10 +399,15 @@
}, },
convertToGrams(value, fromUnit) { convertToGrams(value, fromUnit) {
const conversionFactors = { const conversionFactors = {
'lb': 453.59, // 1 = 453.59237 'lb': 453.59237, // 1 = 453.59237
'oz': 28.35, // 1 = 28.349523125 'oz': 28.349523125, // 1 = 28.349523125
'kg': 1000, // 1 = 1000 'kg': 1000, // 1 = 1000
'g': 1 'g': 1,
'ml': 1,
'斤': 500,
'Waterml': 1,
'milkml': 1.03
// "stlb": "floz": "lboz":
}; };
if (!conversionFactors.hasOwnProperty(fromUnit)) { if (!conversionFactors.hasOwnProperty(fromUnit)) {
@ -392,14 +427,113 @@
that.weightKcal = ite.kcal that.weightKcal = ite.kcal
if (that.bleValue.serviceId != "") { if (that.bleValue.serviceId != "") {
that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit) that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit)
if (that.bleValue.type == 2 && Number(that.bleValue.countWeight) > 0) {
that.handletoggleUnit(that.bleValue.countWeight, that.bleValue.unit, ite.nutrients_four)
}
} else { } else {
that.$store.commit("changeBluetoothValue", { that.$store.commit("changeBluetoothValue", {
countWeight: 100, countWeight: 100,
unit: "g" unit: that.bleValue.unit
}) })
that.realTimeWeight(100, "g") that.realTimeWeight(100, that.bleValue.unit)
} }
}, },
//
handletoggleUnit(val, unit, ite) {
let that = this
let weight = Number(that.convertToGrams(val, unit)) / 100
const dataArray = that.buildNutritionData({
fat: weight * ite[2].value,
calorie: weight * ite[0].value,
carbohydrate: weight * ite[3].value,
protein: weight * ite[1].value,
fiber: 0
});
const arrayBuffer = new ArrayBuffer(dataArray.length);
const uint8Array = new Uint8Array(arrayBuffer);
dataArray.forEach((value, index) => {
uint8Array[index] = value;
});
console.log("营养数据", arrayBuffer)
that.sendArrayBuffer(arrayBuffer);
},
//
buildNutritionData(data) {
//
const header = 0xC5; //
const dataLength = 0x11; // 17
const cmd = 0x04; // CMD
const packetInfo = 0x41; // 11
// ×10
const fatValue = Math.round(data.fat * 10);
const calorieValue = Math.round(data.calorie * 10);
const carbValue = Math.round(data.carbohydrate * 10);
const fiberValue = Math.round(data.fiber * 10);
const proteinValue = Math.round(data.protein * 10);
//
const dataArray = [];
//
dataArray.push(header); // 0xC5
dataArray.push(dataLength); // 0x11
dataArray.push(cmd); // 0x04
dataArray.push(packetInfo); // 0x41
// 3
dataArray.push((fatValue >> 16) & 0xFF); //
dataArray.push((fatValue >> 8) & 0xFF); //
dataArray.push(fatValue & 0xFF); //
// 3
dataArray.push((calorieValue >> 16) & 0xFF);
dataArray.push((calorieValue >> 8) & 0xFF);
dataArray.push(calorieValue & 0xFF);
// 3
dataArray.push((carbValue >> 16) & 0xFF);
dataArray.push((carbValue >> 8) & 0xFF);
dataArray.push(carbValue & 0xFF);
// 3
dataArray.push((fiberValue >> 16) & 0xFF);
dataArray.push((fiberValue >> 8) & 0xFF);
dataArray.push(fiberValue & 0xFF);
// 3
dataArray.push((proteinValue >> 16) & 0xFF);
dataArray.push((proteinValue >> 8) & 0xFF);
dataArray.push(proteinValue & 0xFF);
// 8
let checksum = 0;
for (let i = 1; i < dataArray.length; i++) {
checksum = (checksum + dataArray[i]) & 0xFF;
}
//
dataArray.push(checksum);
console.log('构建的数据包:', dataArray);
console.log('十六进制:', dataArray.map(b => b.toString(16).padStart(2, '0')).join(' '));
return dataArray;
},
sendArrayBuffer(buffer) {
let that = this
uni.writeBLECharacteristicValue({
deviceId: that.bleValue.deviceId,
serviceId: that.bleValue.serviceId,
characteristicId: that.bleValue.write,
value: buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
},
fail: res => {
console.log("下发指令失败", res);
},
})
},
// //
handleBle(weight, unit, kcal) { handleBle(weight, unit, kcal) {
let that = this let that = this
@ -838,7 +972,7 @@
} }
.left { .left {
width: 110px; width: 31%;
display: flex; display: flex;
align-items: center; align-items: center;
@ -881,7 +1015,7 @@
.mic-icon { .mic-icon {
color: #fff; color: #fff;
width: calc(100% - 120px); width: 31%;
padding: 8px 0; padding: 8px 0;
background: $maincolor; background: $maincolor;
display: flex; display: flex;
@ -889,6 +1023,10 @@
justify-content: center; justify-content: center;
border-radius: 20rpx; border-radius: 20rpx;
} }
.mic-icon2 {
background: $yellowcolor ;
}
} }
.wrapper { .wrapper {

View File

@ -69,8 +69,8 @@
page: that.page, page: that.page,
}).then(res => { }).then(res => {
if (res.code == 0) { if (res.code == 0) {
that.infoList = that.infoList.concat(res.content_list) that.infoList = that.infoList.concat(res.data.content_list)
that.lastPage = res.page_total that.lastPage = res.data.page_total
} }
}) })
}, },

29
project.config.json Normal file
View File

@ -0,0 +1,29 @@
{
"appid": "wx1f32af4f93c913f6",
"compileType": "miniprogram",
"libVersion": "3.14.0",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"coverView": true,
"es6": true,
"postcss": true,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": true,
"packNpmRelationList": [],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"condition": false
},
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}

View File

@ -0,0 +1,7 @@
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "kitchendDevice",
"setting": {
"compileHotReLoad": true
}
}

View File

@ -1,6 +1,7 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import actions from './actions.js' import actions from './actions.js'
import json from '@/content.json'
Vue.use(Vuex) Vue.use(Vuex)
export default new Vuex.Store({ export default new Vuex.Store({
// state: 存储基本数据 // state: 存储基本数据
@ -58,10 +59,13 @@ export default new Vuex.Store({
notify: "", notify: "",
write: "", write: "",
unit: "g", unit: "g",
type: 1,
unitList: json.unitArray,
isSendVal: false,
oldCountWeight: 0, oldCountWeight: 0,
countWeight: 100, countWeight: 100,
bleTipsText: "", bleTipsText: "",
isConnectStatus: null, isConnectStatus: 0,
}, },
isBluetoothTyle: false, isBluetoothTyle: false,
}, },

View File

@ -1,20 +1,31 @@
import $store from '@/store' import $store from '@/store'
let searchTimer = null import $model from '@/tools/model.js'
import $tools from '@/tools/tools.js'
import $data from '@/content.json'
let unitList = []
let devicesList = [] let devicesList = []
let searchTimer = null
let UNIT_MAP = $data.units
// 初始化蓝牙 // 初始化蓝牙
function openBluetoothAdapter() { function openBluetoothAdapter() {
devicesList = []
unitList = []
clearTimeout(searchTimer);
uni.openBluetoothAdapter({ uni.openBluetoothAdapter({
success: e => { success: e => {
$store.commit("changeBluetoothValue", { $store.commit("changeBluetoothValue", {
bleTipsText: "蓝牙搜索中", bleTipsText: "蓝牙搜索中",
isConnectStatus: 0 isConnectStatus: 0,
unitList: $data.unitMinus,
}) })
startBluetoothDeviceDiscovery() startBluetoothDeviceDiscovery()
}, },
fail: e => { fail: e => {
$store.commit("changeBluetoothValue", { $store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接", bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1 isConnectStatus: 1,
unitList: $data.unitMinus,
}) })
} }
}); });
@ -23,7 +34,7 @@ function openBluetoothAdapter() {
function startBluetoothDeviceDiscovery() { function startBluetoothDeviceDiscovery() {
uni.startBluetoothDevicesDiscovery({ uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true, allowDuplicatesKey: true,
services: [], interval: 200,
success: res => { success: res => {
onBluetoothDeviceFound(); onBluetoothDeviceFound();
searchTimer = setTimeout(() => { searchTimer = setTimeout(() => {
@ -57,25 +68,52 @@ function onBluetoothDeviceFound() {
if (!device.name && !device.localName) { if (!device.name && !device.localName) {
return return
} }
if (device.name.indexOf('Chipsea-BLE') != -1 || (device.localName && device if (device.name.toLowerCase().indexOf('pc-c06pro') != -1 ||
.localName.indexOf('Chipsea-BLE') != -1) || id == 'a5fe') { device.name.toLowerCase().indexOf('pc-c02pro') != -1 ||
device.name.toLowerCase().indexOf('pc-c09pro') != -1 ||
(device.localName && device.localName.toLowerCase().indexOf('pc-c06pro') != -1) ||
(device.localName && device.localName.toLowerCase().indexOf('pc-c02pro') != -1) ||
(device.localName && device.localName.toLowerCase().indexOf('pc-c09pro') != -1)) {
clearTimeout(searchTimer); clearTimeout(searchTimer);
const bytes = new Uint8Array(device.advertisData);
const macBytes = bytes.slice(6, 12);
device.macAddr = $tools.ab2hex(macBytes, ':').toUpperCase()
stopBluetoothDevicesDiscovery() stopBluetoothDevicesDiscovery()
Bluetoothfilter(device.deviceId) Bluetoothfilter(device)
return return
} }
}) })
}); });
} }
// 过滤蓝牙 // 过滤蓝牙
function Bluetoothfilter(device_id) { function Bluetoothfilter(device) {
const foundDevices = devicesList const foundDevices = devicesList
const idx = inArray(foundDevices, "deviceId", device_id) const idx = inArray(foundDevices, "deviceId", device.deviceId)
if (idx === -1) { if (idx === -1) {
devicesList.push(device_id); devicesList.push(device);
connectDevice(device_id) // handleDevType(device)
connectDevice(device.deviceId)
} }
} }
// 排查设备
function handleDevType(device) {
$model.getCheckDevice({
mac: device.macAddr,
}).then(res => {
console.log("排查设备:", device, res)
if (res.code == 0) {
connectDevice(device.deviceId)
} else {
devicesList = []
$tools.msg('设备未登记,请联系出售方进行系统认证')
$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
}
})
}
//连接设备 //连接设备
function connectDevice(device_id) { function connectDevice(device_id) {
@ -87,7 +125,11 @@ function connectDevice(device_id) {
}, 200) }, 200)
}, },
fail: res => { fail: res => {
console.log("连接失败,点击重新连接", res); $store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
} }
}); });
} }
@ -100,6 +142,7 @@ function getBLEDeviceServices(device_id) {
deviceId: device_id, deviceId: device_id,
success: res => { success: res => {
console.log("获取设备的UUID成功", res) console.log("获取设备的UUID成功", res)
stopBluetoothDevicesDiscovery();
serviceList = res.services; serviceList = res.services;
for (let i = 0; i < serviceList.length; i++) { for (let i = 0; i < serviceList.length; i++) {
let service = serviceList[i]; let service = serviceList[i];
@ -110,6 +153,11 @@ function getBLEDeviceServices(device_id) {
} }
}, },
fail: res => { fail: res => {
$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
console.log('获取设备的UUID失败:', res) console.log('获取设备的UUID失败:', res)
} }
}); });
@ -136,6 +184,11 @@ function getBLEDeviceCharacteristics(deviceId, serviceId) {
getBLECharacteristicValueChange(deviceId, serviceId, notify, write) getBLECharacteristicValueChange(deviceId, serviceId, notify, write)
}, },
fail: res => { fail: res => {
$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
console.log('获取特征值失败:', JSON.stringify(res)) console.log('获取特征值失败:', JSON.stringify(res))
} }
}) })
@ -155,13 +208,11 @@ function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
notify: notify, notify: notify,
write: write, write: write,
unit: "g", unit: "g",
type: 1,
countWeight: "", countWeight: "",
bleTipsText: "测量中,请将食物放到秤上", bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 0 isConnectStatus: 2
}) })
const units = ['kg', '斤', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
'milkml', 'oz', 'floz', 'lboz'
]
uni.onBLECharacteristicValueChange(function(res) { uni.onBLECharacteristicValueChange(function(res) {
const value = res.value const value = res.value
const dataView = new DataView(value) const dataView = new DataView(value)
@ -189,15 +240,42 @@ function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
// 计算实际重量 // 计算实际重量
let finalWeight = weightValue / Math.pow(10, precision) let finalWeight = weightValue / Math.pow(10, precision)
console.log("类型:", cmd, "重量",
finalWeight, "小数点", precision, "单位", UNIT_MAP[unitIndex])
if (isNegative) finalWeight = -finalWeight if (isNegative) finalWeight = -finalWeight
$store.commit("changeBluetoothValue", { $store.commit("changeBluetoothValue", {
countWeight: finalWeight, countWeight: finalWeight,
unit: units[unitIndex], unit: UNIT_MAP[unitIndex],
type: statusType
}) })
break break
case 0x03: case 0x03:
break break
case 0x08:
const start0 = []
const value2 = $tools.ab2hex(res.value, "");
const start = parseUnitMask(value2.substring(8, 10), UNIT_MAP.slice(0,
7))
const start1 = parseUnitMask(value2.substring(10, 12), UNIT_MAP.slice(8,
10))
start.push.apply(start, start1)
if (start.length) {
$data.unitMinus.forEach(item => {
start.forEach(item2 => {
if (item.unit == item2) {
start0.push(item)
}
})
})
}
$store.commit("changeBluetoothValue", {
unitList: start0.length ? start0 : $data.unitMinus
})
console.log("2222222", start, start0)
break
} }
} }
}) })
@ -239,6 +317,7 @@ function ab2hex(buffer, split) {
function closeBluetoothAdapter() { function closeBluetoothAdapter() {
uni.closeBluetoothAdapter({ uni.closeBluetoothAdapter({
success: res => { success: res => {
clearTimeout(searchTimer);
$store.commit("changeBluetoothValue", { $store.commit("changeBluetoothValue", {
deviceId: "", deviceId: "",
serviceId: "", serviceId: "",
@ -246,6 +325,10 @@ function closeBluetoothAdapter() {
write: "", write: "",
unit: "g", unit: "g",
countWeight: '', countWeight: '',
type: 1,
unitList: $data.unitMinus,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
}) })
console.log('蓝牙模块关闭成功'); console.log('蓝牙模块关闭成功');
} }
@ -269,7 +352,9 @@ function onBLEConnectionStateChange() {
if (!res.connected) { if (!res.connected) {
$store.commit("changeBluetoothValue", { $store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接", bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1 unitList: $data.unitMinus,
isConnectStatus: 1,
type: 1,
}) })
closeBLEConnection() closeBLEConnection()
closeBluetoothAdapter() closeBluetoothAdapter()
@ -287,9 +372,38 @@ function stopBluetoothDevicesDiscovery() {
}, },
}); });
} }
//@param {number|string} hexValue - 16进制值如 0x19 或 '0x19'
// @returns {Array} 使用的单位列表
function parseUnitMask(hexValue, UNIT_MAP) {
// 转换为数字
const mask = typeof hexValue === 'string' ? parseInt(hexValue, 16) : hexValue;
// 验证输入
if (isNaN(mask) || mask < 0 || mask > 0xFF) {
console.error('无效的位掩码值');
return [];
}
// 存储结果
const usedUnits = [];
// 遍历每一位
for (let i = 0; i < 8; i++) {
// 使用位运算检查第 i 位是否为 1
if (mask & (1 << i)) {
usedUnits.push(UNIT_MAP[i]);
}
}
return usedUnits;
}
export default { export default {
ab2hex, ab2hex,
inArray, inArray,
unitList,
openBluetoothAdapter, openBluetoothAdapter,
startBluetoothDeviceDiscovery, startBluetoothDeviceDiscovery,
onBluetoothDeviceFound, onBluetoothDeviceFound,

View File

@ -23,6 +23,11 @@ export default {
return res return res
}) })
}, },
getCheckDevice(param) { // 设备过滤
return http.post("/de/check_device_msg", param).then(res => {
return res
})
},
getRegisterPhone(param) { // 手机号快捷登录 getRegisterPhone(param) { // 手机号快捷登录
return http.post("/kitchenscale2/wechat_quick_login", param).then(res => { return http.post("/kitchenscale2/wechat_quick_login", param).then(res => {
return res return res
@ -91,7 +96,7 @@ export default {
}) })
}, },
getPhotoSearch(param) { //图像识别 getPhotoSearch(param) { //图像识别
return http.post("/kitchenscale2/baidu_identify_food", param).then(res => { return http.post("/kitchenscale2/search_food_barcode", param).then(res => {
return res return res
}) })
}, },
@ -222,7 +227,7 @@ export default {
// } // }
// } // }
// res.data.pkList = pkList // res.data.pkList = pkList
return res.data return res
}) })
}, },
// 计食器 // 计食器

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4088,10 +4088,7 @@ var render = function () {
), ),
1 1
), ),
], _c(
1
)
: _c(
"uni-view", "uni-view",
{ {
staticClass: _vm._$g(59, "sc"), staticClass: _vm._$g(59, "sc"),
@ -4102,49 +4099,50 @@ var render = function () {
}, },
}, },
}, },
[
_c(
"uni-view",
{ staticClass: _vm._$g(60, "sc"), attrs: { _i: 60 } },
[ [
_c("v-uni-image", { _c("v-uni-image", {
attrs: { src: "/static/none.png", _i: 61 }, attrs: { src: "/static/fenxi.png", _i: 60 },
}), }),
_c("v-uni-text", { attrs: { _i: 62 } }, [ _vm._v("营养分析"),
_vm._v("完善资料后,记录更准确哦!"),
]),
], ],
1 1
), ),
_c(
"uni-view",
{ staticClass: _vm._$g(63, "sc"), attrs: { _i: 63 } },
[_vm._v("完善资料")]
),
], ],
1 1
), )
_vm._$g(64, "i") : _c(
? _c(
"uni-view", "uni-view",
{ {
staticClass: _vm._$g(64, "sc"), staticClass: _vm._$g(61, "sc"),
attrs: { _i: 64 }, attrs: { _i: 61 },
on: { on: {
click: function ($event) { click: function ($event) {
return _vm.$handleViewEvent($event) return _vm.$handleViewEvent($event)
}, },
}, },
}, },
[
_c(
"uni-view",
{ staticClass: _vm._$g(62, "sc"), attrs: { _i: 62 } },
[ [
_c("v-uni-image", { _c("v-uni-image", {
attrs: { src: "/static/fenxi.png", _i: 65 }, attrs: { src: "/static/none.png", _i: 63 },
}), }),
_vm._v("营养分析"), _c("v-uni-text", { attrs: { _i: 64 } }, [
_vm._v("完善资料后,记录更准确哦!"),
]),
], ],
1 1
) ),
: _vm._e(), _c(
"uni-view",
{ staticClass: _vm._$g(65, "sc"), attrs: { _i: 65 } },
[_vm._v("完善资料")]
),
],
1
),
], ],
1 1
), ),

View File

@ -16,10 +16,10 @@ __webpack_require__(/*! uni-pages */ 26);
var _App = _interopRequireDefault(__webpack_require__(/*! ./App */ 27)); var _App = _interopRequireDefault(__webpack_require__(/*! ./App */ 27));
var _store = _interopRequireDefault(__webpack_require__(/*! ./store */ 34)); var _store = _interopRequireDefault(__webpack_require__(/*! ./store */ 34));
var _tools = _interopRequireDefault(__webpack_require__(/*! @/tools/tools.js */ 38)); var _tools = _interopRequireDefault(__webpack_require__(/*! @/tools/tools.js */ 38));
var _bluetooth = _interopRequireDefault(__webpack_require__(/*! @/tools/bluetooth.js */ 40)); var _bluetooth = _interopRequireDefault(__webpack_require__(/*! @/tools/bluetooth.js */ 41));
var _https = _interopRequireDefault(__webpack_require__(/*! @/tools/https.js */ 37)); var _https = _interopRequireDefault(__webpack_require__(/*! @/tools/https.js */ 37));
var _model = _interopRequireDefault(__webpack_require__(/*! @/tools/model.js */ 36)); var _model = _interopRequireDefault(__webpack_require__(/*! @/tools/model.js */ 36));
var _content = _interopRequireDefault(__webpack_require__(/*! @/content.json */ 41)); var _content = _interopRequireDefault(__webpack_require__(/*! @/content.json */ 40));
var _vue = _interopRequireDefault(__webpack_require__(/*! vue */ 25)); var _vue = _interopRequireDefault(__webpack_require__(/*! vue */ 25));
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

View File

@ -1027,8 +1027,8 @@ function populateParameters(result) {
var parameters = { var parameters = {
appId: "__UNI__20604F1", appId: "__UNI__20604F1",
appName: "kitchendDevice", appName: "kitchendDevice",
appVersion: "1.0.0", appVersion: "2.0.0",
appVersionCode: "100", appVersionCode: "200",
appLanguage: getAppLanguage(hostLanguage), appLanguage: getAppLanguage(hostLanguage),
uniCompileVersion: "4.76", uniCompileVersion: "4.76",
uniCompilerVersion: "4.76", uniCompilerVersion: "4.76",
@ -1128,8 +1128,8 @@ var getAppBaseInfo = {
result = sortObject(Object.assign(result, { result = sortObject(Object.assign(result, {
appId: "__UNI__20604F1", appId: "__UNI__20604F1",
appName: "kitchendDevice", appName: "kitchendDevice",
appVersion: "1.0.0", appVersion: "2.0.0",
appVersionCode: "100", appVersionCode: "200",
appLanguage: getAppLanguage(hostLanguage), appLanguage: getAppLanguage(hostLanguage),
hostVersion: version, hostVersion: version,
hostLanguage: hostLanguage, hostLanguage: hostLanguage,
@ -28032,6 +28032,7 @@ exports.default = void 0;
var _vue = _interopRequireDefault(__webpack_require__(/*! vue */ 25)); var _vue = _interopRequireDefault(__webpack_require__(/*! vue */ 25));
var _vuex = _interopRequireDefault(__webpack_require__(/*! vuex */ 30)); var _vuex = _interopRequireDefault(__webpack_require__(/*! vuex */ 30));
var _actions = _interopRequireDefault(__webpack_require__(/*! ./actions.js */ 35)); var _actions = _interopRequireDefault(__webpack_require__(/*! ./actions.js */ 35));
var _content = _interopRequireDefault(__webpack_require__(/*! @/content.json */ 40));
_vue.default.use(_vuex.default); _vue.default.use(_vuex.default);
var _default = new _vuex.default.Store({ var _default = new _vuex.default.Store({
// state: 存储基本数据 // state: 存储基本数据
@ -28089,10 +28090,13 @@ var _default = new _vuex.default.Store({
notify: "", notify: "",
write: "", write: "",
unit: "g", unit: "g",
type: 1,
unitList: _content.default.unitArray,
isSendVal: false,
oldCountWeight: 0, oldCountWeight: 0,
countWeight: 100, countWeight: 100,
bleTipsText: "", bleTipsText: "",
isConnectStatus: null isConnectStatus: 0
}, },
isBluetoothTyle: false isBluetoothTyle: false
}, },
@ -28290,6 +28294,12 @@ var _default = (_getonlogin$getSendCo = {
return res; return res;
}); });
}, },
getCheckDevice: function getCheckDevice(param) {
// 设备过滤
return _https.default.post("/de/check_device_msg", param).then(function (res) {
return res;
});
},
getRegisterPhone: function getRegisterPhone(param) { getRegisterPhone: function getRegisterPhone(param) {
// 手机号快捷登录 // 手机号快捷登录
return _https.default.post("/kitchenscale2/wechat_quick_login", param).then(function (res) { return _https.default.post("/kitchenscale2/wechat_quick_login", param).then(function (res) {
@ -28371,7 +28381,7 @@ var _default = (_getonlogin$getSendCo = {
}, },
getPhotoSearch: function getPhotoSearch(param) { getPhotoSearch: function getPhotoSearch(param) {
//图像识别 //图像识别
return _https.default.post("/kitchenscale2/baidu_identify_food", param).then(function (res) { return _https.default.post("/kitchenscale2/search_food_barcode", param).then(function (res) {
return res; return res;
}); });
}, },
@ -28522,7 +28532,7 @@ var _default = (_getonlogin$getSendCo = {
// } // }
// } // }
// res.data.pkList = pkList // res.data.pkList = pkList
return res.data; return res;
}); });
} }
}, (0, _defineProperty2.default)(_getonlogin$getSendCo, "getAddIntakeFood", function getAddIntakeFood(param) { }, (0, _defineProperty2.default)(_getonlogin$getSendCo, "getAddIntakeFood", function getAddIntakeFood(param) {
@ -29087,6 +29097,17 @@ module.exports = _interopRequireDefault, module.exports.__esModule = true, modul
/***/ }), /***/ }),
/***/ 40: /***/ 40:
/*!***********************************************************!*\
!*** E:/qiaocongli///kitchendDevice/content.json ***!
\***********************************************************/
/*! exports provided: addfoodList, unitArray, unitMinus, units, default */
/***/ (function(module) {
module.exports = JSON.parse("{\"addfoodList\":[{\"name\":\"早加餐\",\"id\":3},{\"name\":\"午加餐\",\"id\":4},{\"name\":\"晚加餐\",\"id\":5}],\"unitArray\":[{\"name\":\"千克\",\"unit\":\"kg\"},{\"name\":\"斤\",\"unit\":\"斤\"},{\"name\":\"stlb\",\"unit\":\"stlb\"},{\"name\":\"磅\",\"unit\":\"lb\"},{\"name\":\"克\",\"unit\":\"g\"},{\"name\":\"毫升\",\"unit\":\"ml\"},{\"name\":\"Waterml\",\"unit\":\"Waterml\"},{\"name\":\"milkml\",\"unit\":\"milkml\"},{\"name\":\"盎司\",\"unit\":\"oz\"},{\"name\":\"floz\",\"unit\":\"floz\"},{\"name\":\"lboz\",\"unit\":\"lboz\"}],\"unitMinus\":[{\"name\":\"千克\",\"unit\":\"kg\"},{\"name\":\"磅\",\"unit\":\"lb\"},{\"name\":\"克\",\"unit\":\"g\"},{\"name\":\"毫升\",\"unit\":\"ml\"},{\"name\":\"盎司\",\"unit\":\"oz\"}],\"units\":[\"kg\",\"斤\",\"stlb\",\"lb\",\"g\",\"ml\",\"Waterml\",\"milkml\",\"oz\",\"floz\",\"lboz\"]}");
/***/ }),
/***/ 41:
/*!*****************************************************************!*\ /*!*****************************************************************!*\
!*** E:/qiaocongli///kitchendDevice/tools/bluetooth.js ***! !*** E:/qiaocongli///kitchendDevice/tools/bluetooth.js ***!
\*****************************************************************/ \*****************************************************************/
@ -29103,22 +29124,33 @@ Object.defineProperty(exports, "__esModule", {
exports.default = void 0; exports.default = void 0;
var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13)); var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13));
var _store = _interopRequireDefault(__webpack_require__(/*! @/store */ 34)); var _store = _interopRequireDefault(__webpack_require__(/*! @/store */ 34));
var searchTimer = null; var _model = _interopRequireDefault(__webpack_require__(/*! @/tools/model.js */ 36));
var _tools = _interopRequireDefault(__webpack_require__(/*! @/tools/tools.js */ 38));
var _content = _interopRequireDefault(__webpack_require__(/*! @/content.json */ 40));
var unitList = [];
var devicesList = []; var devicesList = [];
var searchTimer = null;
var UNIT_MAP = _content.default.units;
// 初始化蓝牙 // 初始化蓝牙
function openBluetoothAdapter() { function openBluetoothAdapter() {
devicesList = [];
unitList = [];
clearTimeout(searchTimer);
uni.openBluetoothAdapter({ uni.openBluetoothAdapter({
success: function success(e) { success: function success(e) {
_store.default.commit("changeBluetoothValue", { _store.default.commit("changeBluetoothValue", {
bleTipsText: "蓝牙搜索中", bleTipsText: "蓝牙搜索中",
isConnectStatus: 0 isConnectStatus: 0,
unitList: _content.default.unitMinus
}); });
startBluetoothDeviceDiscovery(); startBluetoothDeviceDiscovery();
}, },
fail: function fail(e) { fail: function fail(e) {
_store.default.commit("changeBluetoothValue", { _store.default.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接", bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1 isConnectStatus: 1,
unitList: _content.default.unitMinus
}); });
} }
}); });
@ -29127,7 +29159,7 @@ function openBluetoothAdapter() {
function startBluetoothDeviceDiscovery() { function startBluetoothDeviceDiscovery() {
uni.startBluetoothDevicesDiscovery({ uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true, allowDuplicatesKey: true,
services: [], interval: 200,
success: function success(res) { success: function success(res) {
onBluetoothDeviceFound(); onBluetoothDeviceFound();
searchTimer = setTimeout(function () { searchTimer = setTimeout(function () {
@ -29162,24 +29194,47 @@ function onBluetoothDeviceFound() {
if (!device.name && !device.localName) { if (!device.name && !device.localName) {
return; return;
} }
if (device.name.indexOf('Chipsea-BLE') != -1 || device.localName && device.localName.indexOf('Chipsea-BLE') != -1 || id == 'a5fe') { if (device.name.toLowerCase().indexOf('pc-c06pro') != -1 || device.name.toLowerCase().indexOf('pc-c02pro') != -1 || device.name.toLowerCase().indexOf('pc-c09pro') != -1 || device.localName && device.localName.toLowerCase().indexOf('pc-c06pro') != -1 || device.localName && device.localName.toLowerCase().indexOf('pc-c02pro') != -1 || device.localName && device.localName.toLowerCase().indexOf('pc-c09pro') != -1) {
clearTimeout(searchTimer); clearTimeout(searchTimer);
var bytes = new Uint8Array(device.advertisData);
var macBytes = bytes.slice(6, 12);
device.macAddr = _tools.default.ab2hex(macBytes, ':').toUpperCase();
stopBluetoothDevicesDiscovery(); stopBluetoothDevicesDiscovery();
Bluetoothfilter(device.deviceId); Bluetoothfilter(device);
return; return;
} }
}); });
}); });
} }
// 过滤蓝牙 // 过滤蓝牙
function Bluetoothfilter(device_id) { function Bluetoothfilter(device) {
var foundDevices = devicesList; var foundDevices = devicesList;
var idx = inArray(foundDevices, "deviceId", device_id); var idx = inArray(foundDevices, "deviceId", device.deviceId);
if (idx === -1) { if (idx === -1) {
devicesList.push(device_id); devicesList.push(device);
connectDevice(device_id); // handleDevType(device)
connectDevice(device.deviceId);
} }
} }
// 排查设备
function handleDevType(device) {
_model.default.getCheckDevice({
mac: device.macAddr
}).then(function (res) {
console.log("排查设备:", device, res);
if (res.code == 0) {
connectDevice(device.deviceId);
} else {
devicesList = [];
_tools.default.msg('设备未登记,请联系出售方进行系统认证');
_store.default.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接"
});
}
});
}
//连接设备 //连接设备
function connectDevice(device_id) { function connectDevice(device_id) {
@ -29191,7 +29246,11 @@ function connectDevice(device_id) {
}, 200); }, 200);
}, },
fail: function fail(res) { fail: function fail(res) {
console.log("连接失败,点击重新连接", res); _store.default.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接"
});
} }
}); });
} }
@ -29204,6 +29263,7 @@ function getBLEDeviceServices(device_id) {
deviceId: device_id, deviceId: device_id,
success: function success(res) { success: function success(res) {
console.log("获取设备的UUID成功", res); console.log("获取设备的UUID成功", res);
stopBluetoothDevicesDiscovery();
serviceList = res.services; serviceList = res.services;
for (var i = 0; i < serviceList.length; i++) { for (var i = 0; i < serviceList.length; i++) {
var service = serviceList[i]; var service = serviceList[i];
@ -29214,6 +29274,11 @@ function getBLEDeviceServices(device_id) {
} }
}, },
fail: function fail(res) { fail: function fail(res) {
_store.default.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接"
});
console.log('获取设备的UUID失败:', res); console.log('获取设备的UUID失败:', res);
} }
}); });
@ -29240,6 +29305,11 @@ function getBLEDeviceCharacteristics(deviceId, serviceId) {
getBLECharacteristicValueChange(deviceId, serviceId, notify, write); getBLECharacteristicValueChange(deviceId, serviceId, notify, write);
}, },
fail: function fail(res) { fail: function fail(res) {
_store.default.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接"
});
console.log('获取特征值失败:', JSON.stringify(res)); console.log('获取特征值失败:', JSON.stringify(res));
} }
}); });
@ -29258,11 +29328,11 @@ function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
notify: notify, notify: notify,
write: write, write: write,
unit: "g", unit: "g",
type: 1,
countWeight: "", countWeight: "",
bleTipsText: "测量中,请将食物放到秤上", bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 0 isConnectStatus: 2
}); });
var units = ['kg', '斤', 'st:lb', 'lb', 'g', 'ml', 'Waterml', 'milkml', 'oz', 'floz', 'lboz'];
uni.onBLECharacteristicValueChange(function (res) { uni.onBLECharacteristicValueChange(function (res) {
var value = res.value; var value = res.value;
var dataView = new DataView(value); var dataView = new DataView(value);
@ -29286,14 +29356,36 @@ function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
// 计算实际重量 // 计算实际重量
var finalWeight = weightValue / Math.pow(10, precision); var finalWeight = weightValue / Math.pow(10, precision);
console.log("类型:", cmd, "重量", finalWeight, "小数点", precision, "单位", UNIT_MAP[unitIndex]);
if (isNegative) finalWeight = -finalWeight; if (isNegative) finalWeight = -finalWeight;
_store.default.commit("changeBluetoothValue", { _store.default.commit("changeBluetoothValue", {
countWeight: finalWeight, countWeight: finalWeight,
unit: units[unitIndex] unit: UNIT_MAP[unitIndex],
type: statusType
}); });
break; break;
case 0x03: case 0x03:
break; break;
case 0x08:
var start0 = [];
var value2 = _tools.default.ab2hex(res.value, "");
var start = parseUnitMask(value2.substring(8, 10), UNIT_MAP.slice(0, 7));
var start1 = parseUnitMask(value2.substring(10, 12), UNIT_MAP.slice(8, 10));
start.push.apply(start, start1);
if (start.length) {
_content.default.unitMinus.forEach(function (item) {
start.forEach(function (item2) {
if (item.unit == item2) {
start0.push(item);
}
});
});
}
_store.default.commit("changeBluetoothValue", {
unitList: start0.length ? start0 : _content.default.unitMinus
});
console.log("2222222", start, start0);
break;
} }
} }
}); });
@ -29330,13 +29422,18 @@ function ab2hex(buffer, split) {
function closeBluetoothAdapter() { function closeBluetoothAdapter() {
uni.closeBluetoothAdapter({ uni.closeBluetoothAdapter({
success: function success(res) { success: function success(res) {
clearTimeout(searchTimer);
_store.default.commit("changeBluetoothValue", { _store.default.commit("changeBluetoothValue", {
deviceId: "", deviceId: "",
serviceId: "", serviceId: "",
notify: "", notify: "",
write: "", write: "",
unit: "g", unit: "g",
countWeight: '' countWeight: '',
type: 1,
unitList: _content.default.unitMinus,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接"
}); });
console.log('蓝牙模块关闭成功'); console.log('蓝牙模块关闭成功');
} }
@ -29360,7 +29457,9 @@ function onBLEConnectionStateChange() {
if (!res.connected) { if (!res.connected) {
_store.default.commit("changeBluetoothValue", { _store.default.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接", bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1 unitList: _content.default.unitMinus,
isConnectStatus: 1,
type: 1
}); });
closeBLEConnection(); closeBLEConnection();
closeBluetoothAdapter(); closeBluetoothAdapter();
@ -29378,9 +29477,36 @@ function stopBluetoothDevicesDiscovery() {
} }
}); });
} }
//@param {number|string} hexValue - 16进制值如 0x19 或 '0x19'
// @returns {Array} 使用的单位列表
function parseUnitMask(hexValue, UNIT_MAP) {
// 转换为数字
var mask = typeof hexValue === 'string' ? parseInt(hexValue, 16) : hexValue;
// 验证输入
if (isNaN(mask) || mask < 0 || mask > 0xFF) {
console.error('无效的位掩码值');
return [];
}
// 存储结果
var usedUnits = [];
// 遍历每一位
for (var i = 0; i < 8; i++) {
// 使用位运算检查第 i 位是否为 1
if (mask & 1 << i) {
usedUnits.push(UNIT_MAP[i]);
}
}
return usedUnits;
}
var _default = { var _default = {
ab2hex: ab2hex, ab2hex: ab2hex,
inArray: inArray, inArray: inArray,
unitList: unitList,
openBluetoothAdapter: openBluetoothAdapter, openBluetoothAdapter: openBluetoothAdapter,
startBluetoothDeviceDiscovery: startBluetoothDeviceDiscovery, startBluetoothDeviceDiscovery: startBluetoothDeviceDiscovery,
onBluetoothDeviceFound: onBluetoothDeviceFound, onBluetoothDeviceFound: onBluetoothDeviceFound,
@ -29399,17 +29525,6 @@ exports.default = _default;
/***/ }), /***/ }),
/***/ 41:
/*!***********************************************************!*\
!*** E:/qiaocongli///kitchendDevice/content.json ***!
\***********************************************************/
/*! exports provided: addfoodList, default */
/***/ (function(module) {
module.exports = JSON.parse("{\"addfoodList\":[{\"name\":\"早加餐\",\"id\":3},{\"name\":\"午加餐\",\"id\":4},{\"name\":\"晚加餐\",\"id\":5}]}");
/***/ }),
/***/ 5: /***/ 5:
/*!**************************************************************!*\ /*!**************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***! !*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***!

View File

@ -167,20 +167,10 @@ var _default = {
return { return {
kcal: 0, kcal: 0,
unit: '', unit: '',
// weight: "",
bleTipsText: "", bleTipsText: "",
inputDialog: false, inputDialog: false,
unitList: [{ unitA: [],
name: "克", unitListIndex: 0
id: '00',
unit: "g"
}, {
name: "盎司",
id: "08",
unit: "oz"
}],
unitListIndex: 0,
units: ['kg', '斤', 'st:lb', 'lb', 'g', 'ml', 'Waterml', 'milkml', 'oz', 'floz', 'lboz']
}; };
}, },
props: { props: {
@ -197,7 +187,8 @@ var _default = {
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["bleValue", "isBluetoothTyle", "countFoodInfo"])), {}, { computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["bleValue", "isBluetoothTyle", "countFoodInfo"])), {}, {
weight: function weight() { weight: function weight() {
this.kcal = (Number(this.weightKcal) / 100 * this.bleValue.countWeight).toFixed(2); var weightNew = this.convertToGrams(this.bleValue.countWeight, this.bleValue.unit);
this.kcal = (Number(this.weightKcal) / 100 * weightNew).toFixed(1);
this.unit = this.bleValue.unit; this.unit = this.bleValue.unit;
return this.bleValue.countWeight; return this.bleValue.countWeight;
}, },
@ -226,13 +217,20 @@ var _default = {
if (!that.isBluetoothTyle) { if (!that.isBluetoothTyle) {
that.handleBack(); that.handleBack();
} }
},
bleValue: {
handler: function handler(newVal, oldVal) {
this.unitA = newVal.unitList;
},
deep: true,
immediate: true
} }
}, },
methods: { methods: {
// 初始化蓝牙 // 初始化蓝牙
openBluetoothAdapter: function openBluetoothAdapter() { openBluetoothAdapter: function openBluetoothAdapter() {
var that = this; var that = this;
if (that.isConnection == 0) return; if (that.isConnection == 2) return;
that.kcal = ""; that.kcal = "";
that.$store.commit('changeBluetoothValue', { that.$store.commit('changeBluetoothValue', {
deviceId: "", deviceId: "",
@ -240,6 +238,8 @@ var _default = {
notify: '', notify: '',
write: '', write: '',
unit: "g", unit: "g",
type: 1,
unitList: that.$json.unitMinus,
countWeight: "", countWeight: "",
bleTipsText: "蓝牙搜索中", bleTipsText: "蓝牙搜索中",
isConnectStatus: 0 isConnectStatus: 0
@ -248,16 +248,66 @@ var _default = {
}, },
changleUnits: function changleUnits(e) { changleUnits: function changleUnits(e) {
var that = this; var that = this;
var name = that.unitList[e.detail.value].name; var name = that.unitA[e.detail.value].name;
console.log("单位切换", name, that.unit); var val = that.unitA[e.detail.value].unit;
if (that.isShow && that.unit != name) { if (that.isShow && that.unit != name) {
that.handletoggleUnit(name == '盎司' ? 0x08 : 0x04); that.handletoggleUnit(that.unitConversion2(val));
} }
if (that.bleValue.serviceId == '') {
that.unitListIndex = [e.detail.value]; that.unitListIndex = [e.detail.value];
that.$store.commit('changeBluetoothValue', { that.$store.commit('changeBluetoothValue', {
unit: that.unitList[e.detail.value].unit unit: that.unitA[e.detail.value].unit
}); });
}
}, },
convertToGrams: function convertToGrams(value, fromUnit) {
var conversionFactors = {
'lb': 453.59237,
// 1磅 = 453.59237克
'oz': 28.349523125,
// 1盎司 = 28.349523125克
'kg': 1000,
// 1公斤 = 1000克
'g': 1,
'ml': 1,
'斤': 500,
'Waterml': 1,
'milkml': 1.03
// "stlb": "floz": "lboz":
};
if (!conversionFactors.hasOwnProperty(fromUnit)) {
return '';
}
return value * conversionFactors[fromUnit];
},
unitConversion2: function unitConversion2(unit) {
if (unit == 'kg') {
return 0x00;
} else if (unit == '斤') {
return 0x01;
} else if (unit == 'st:lb') {
return 0x02;
} else if (unit == 'lb') {
return 0x03;
} else if (unit == 'g') {
return 0x04;
} else if (unit == 'ml') {
return 0x05;
} else if (unit == 'Waterml') {
return 0x06;
} else if (unit == 'milkml') {
return 0x07;
} else if (unit == 'oz') {
return 0x08;
} else if (unit == 'floz') {
return 0x09;
} else if (unit == 'lboz') {
return 0x0A;
}
return unit;
},
// 下发单位
handletoggleUnit: function handletoggleUnit(unit) { handletoggleUnit: function handletoggleUnit(unit) {
var that = this; var that = this;
var checksum = 0; var checksum = 0;
@ -269,6 +319,7 @@ var _default = {
bytes[5] = checksum; bytes[5] = checksum;
that.sendData(new Uint8Array(bytes).buffer); that.sendData(new Uint8Array(bytes).buffer);
}, },
// 清零
handleqingling: function handleqingling() { handleqingling: function handleqingling() {
var that = this; var that = this;
var str = "C503071100D0"; var str = "C503071100D0";
@ -306,6 +357,7 @@ var _default = {
var that = this; var that = this;
that.$store.commit("changeBluetoothValue", { that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接失败,点击重新连接", bleTipsText: "连接失败,点击重新连接",
unitList: that.$json.unitMinus,
isConnectStatus: 1 isConnectStatus: 1
}); });
that.$ble.stopBluetoothDevicesDiscovery(); //取消蓝牙搜索 that.$ble.stopBluetoothDevicesDiscovery(); //取消蓝牙搜索
@ -313,14 +365,28 @@ var _default = {
that.$ble.closeBluetoothAdapter(); that.$ble.closeBluetoothAdapter();
}, },
unitConversion: function unitConversion(unit) { unitConversion: function unitConversion(unit) {
if (unit == 'kcal') { if (unit == 'kg') {
return '千卡'; return '千克';
} else if (unit == '斤') {
return '斤';
} else if (unit == 'stlb') {
return 'stlb';
} else if (unit == '磅') {
return '磅';
} else if (unit == 'g') { } else if (unit == 'g') {
return '克'; return '克';
} else if (unit == 'lb') { } else if (unit == 'ml') {
return '磅'; return '毫升';
} else if (unit == 'Waterml') {
return 'Waterml';
} else if (unit == 'milkml') {
return 'milkml';
} else if (unit == 'oz') { } else if (unit == 'oz') {
return '盎司'; return '盎司';
} else if (unit == 'floz') {
return 'floz';
} else if (unit == 'lboz') {
return 'lboz';
} }
return unit; return unit;
}, },
@ -335,9 +401,11 @@ var _default = {
}, },
confirm: function confirm(value) { confirm: function confirm(value) {
console.log(value); console.log(value);
var that = this;
this.$store.commit("changeBluetoothValue", { this.$store.commit("changeBluetoothValue", {
countWeight: value, countWeight: value,
unit: this.unitList[this.unitListIndex].unit unitList: that.$json.unitMinus,
unit: this.unitA[this.unitListIndex].unit
}); });
this.$refs.popup.close(); this.$refs.popup.close();
}, },

View File

@ -1 +1 @@
<view class="weightPages data-v-5fc22dca"><view class="table data-v-5fc22dca"><view class="text data-v-5fc22dca"><image src="/static/zhong.png" class="data-v-5fc22dca"></image><text data-event-opts="{{[['tap',[['openBluetoothAdapter',['$event']]]]]}}" bindtap="__e" class="data-v-5fc22dca">{{bleTipsText}}</text></view><block wx:if="{{isShow&&isConnection==0}}"><view data-event-opts="{{[['tap',[['handleBack',['$event']]]]]}}" class="duan data-v-5fc22dca" bindtap="__e">断开连接</view></block></view><view class="weight-wrap data-v-5fc22dca"><view data-event-opts="{{[['tap',[['inputDialogToggle',['$event']]]]]}}" class="weight data-v-5fc22dca" bindtap="__e"><text class="val data-v-5fc22dca">{{weight==''?'0.0':weight}}</text><text class="unit data-v-5fc22dca">{{$root.m0}}</text></view></view><view class="groupbtn data-v-5fc22dca"><view class="btn danwei data-v-5fc22dca"><view class="lan border-bottom data-v-5fc22dca"><view class="right data-v-5fc22dca"><picker mode="selector" range="{{unitList}}" range-key="name" value="{{unitListIndex}}" data-event-opts="{{[['change',[['changleUnits',['$event']]]]]}}" bindchange="__e" class="data-v-5fc22dca"><view class="uni-input data-v-5fc22dca">单位</view></picker></view></view></view><block wx:if="{{btnType==2}}"><view data-event-opts="{{[['tap',[['handlesub',['$event']]]]]}}" class="btn addbtn size14 data-v-5fc22dca" bindtap="__e">保存</view></block><block wx:if="{{btnType==1}}"><view data-event-opts="{{[['tap',[['handleAddFood',['$event']]]]]}}" class="btn addbtn data-v-5fc22dca" bindtap="__e">+</view></block><view data-event-opts="{{[['tap',[['handleqingling',['$event']]]]]}}" class="btn qingling data-v-5fc22dca" bindtap="__e">清零</view></view><view class="data-v-5fc22dca"><uni-popup vue-id="cef7e708-1" type="dialog" data-ref="popup" class="data-v-5fc22dca vue-ref" bind:__l="__l" vue-slots="{{['default']}}"><uni-popup-dialog vue-id="{{('cef7e708-2')+','+('cef7e708-1')}}" mode="input" title="重量" placeholder="请输入食物重量" data-event-opts="{{[['^close',[['close']]],['^confirm',[['confirm']]]]}}" bind:close="__e" bind:confirm="__e" class="data-v-5fc22dca" bind:__l="__l"></uni-popup-dialog></uni-popup></view></view> <view class="weightPages data-v-5fc22dca"><view class="table data-v-5fc22dca"><view class="text data-v-5fc22dca"><image src="/static/zhong.png" class="data-v-5fc22dca"></image><text data-event-opts="{{[['tap',[['openBluetoothAdapter',['$event']]]]]}}" bindtap="__e" class="data-v-5fc22dca">{{bleTipsText}}</text></view><block wx:if="{{isShow&&isConnection==2}}"><view data-event-opts="{{[['tap',[['handleBack',['$event']]]]]}}" class="duan data-v-5fc22dca" bindtap="__e">断开连接</view></block></view><view class="weight-wrap data-v-5fc22dca"><view data-event-opts="{{[['tap',[['inputDialogToggle',['$event']]]]]}}" class="weight data-v-5fc22dca" bindtap="__e"><text class="val data-v-5fc22dca">{{weight==''?'0.0':weight}}</text><text class="unit data-v-5fc22dca">{{$root.m0}}</text></view></view><view class="groupbtn data-v-5fc22dca"><view class="btn danwei data-v-5fc22dca"><view class="lan border-bottom data-v-5fc22dca"><view class="right data-v-5fc22dca"><picker mode="selector" range="{{unitA}}" range-key="name" value="{{unitListIndex}}" data-event-opts="{{[['change',[['changleUnits',['$event']]]]]}}" bindchange="__e" class="data-v-5fc22dca"><view class="uni-input data-v-5fc22dca">单位</view></picker></view></view></view><block wx:if="{{btnType==2}}"><view data-event-opts="{{[['tap',[['handlesub',['$event']]]]]}}" class="btn addbtn size14 data-v-5fc22dca" bindtap="__e">保存</view></block><block wx:if="{{btnType==1}}"><view data-event-opts="{{[['tap',[['handleAddFood',['$event']]]]]}}" class="btn addbtn data-v-5fc22dca" bindtap="__e">+</view></block><view data-event-opts="{{[['tap',[['handleqingling',['$event']]]]]}}" class="btn qingling data-v-5fc22dca" bindtap="__e">清零</view></view><view class="data-v-5fc22dca"><uni-popup vue-id="cef7e708-1" type="dialog" data-ref="popup" class="data-v-5fc22dca vue-ref" bind:__l="__l" vue-slots="{{['default']}}"><uni-popup-dialog vue-id="{{('cef7e708-2')+','+('cef7e708-1')}}" mode="input" title="重量" placeholder="请输入食物重量" data-event-opts="{{[['^close',[['close']]],['^confirm',[['confirm']]]]}}" bind:close="__e" bind:confirm="__e" class="data-v-5fc22dca" bind:__l="__l"></uni-popup-dialog></uni-popup></view></view>

View File

@ -154,11 +154,11 @@ var render = function () {
} }
}) })
: null : null
var g9 = _vm.IsWeight ? Math.floor(_vm.activeType.weight) : null var g9 = _vm.IsWeight ? _vm.activeType.weight.toFixed(1) : null
var l2 = _vm.IsWeight var l2 = _vm.IsWeight
? _vm.__map(_vm.activeType.nutrients_list, function (item, index) { ? _vm.__map(_vm.activeType.nutrients_list, function (item, index) {
var $orig = _vm.__get_orig(item) var $orig = _vm.__get_orig(item)
var g10 = Number((item.value * _vm.activeType.weight) / 100).toFixed(2) var g10 = Number((_vm.activeType.weight / 100) * item.value).toFixed(1)
return { return {
$orig: $orig, $orig: $orig,
g10: g10, g10: g10,
@ -320,6 +320,9 @@ var _default = {
bleValue: { bleValue: {
handler: function handler(newVal, oldVal) { handler: function handler(newVal, oldVal) {
this.realTimeWeight(newVal.countWeight, newVal.unit); this.realTimeWeight(newVal.countWeight, newVal.unit);
if (newVal.type == 2 && Number(newVal.countWeight) > 0) {
this.handletoggleUnit(newVal.countWeight, newVal.unit, this.activeType.nutrients_four);
}
}, },
deep: true deep: true
} }
@ -372,6 +375,29 @@ var _default = {
this.showAutoSearchDlg = false; this.showAutoSearchDlg = false;
} }
}, },
scanCode: function scanCode() {
var that = this;
uni.scanCode({
onlyFromCamera: true,
success: function success(res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
that.$model.getPhotoSearch({
barcode: "6920584471017"
}).then(function (res) {
if (res.code != 0) {
that.$tools.msg(res.msg);
return;
}
that.handleDetail(res.data);
});
},
fail: function fail(res) {
that.$api.msg("您已取消操作");
return;
}
});
},
// 购物车早午晚餐切换 // 购物车早午晚餐切换
handleToggle: function handleToggle(name) { handleToggle: function handleToggle(name) {
this.search_value = ""; this.search_value = "";
@ -381,7 +407,6 @@ var _default = {
}, },
//实时重量 //实时重量
realTimeWeight: function realTimeWeight(weight, unit) { realTimeWeight: function realTimeWeight(weight, unit) {
// console.log("实时重量", weight, unit)
this.activeType = Object.assign({}, this.activeType, { this.activeType = Object.assign({}, this.activeType, {
weight: this.convertToGrams(weight, unit) weight: this.convertToGrams(weight, unit)
}); });
@ -396,14 +421,20 @@ var _default = {
}, },
convertToGrams: function convertToGrams(value, fromUnit) { convertToGrams: function convertToGrams(value, fromUnit) {
var conversionFactors = { var conversionFactors = {
'lb': 453.59, 'lb': 453.59237,
// 1磅 = 453.59237克 // 1磅 = 453.59237克
'oz': 28.35, 'oz': 28.349523125,
// 1盎司 = 28.349523125克 // 1盎司 = 28.349523125克
'kg': 1000, 'kg': 1000,
// 1公斤 = 1000克 // 1公斤 = 1000克
'g': 1 'g': 1,
'ml': 1,
'斤': 500,
'Waterml': 1,
'milkml': 1.03
// "stlb": "floz": "lboz":
}; };
if (!conversionFactors.hasOwnProperty(fromUnit)) { if (!conversionFactors.hasOwnProperty(fromUnit)) {
return ''; return '';
} }
@ -420,14 +451,114 @@ var _default = {
that.weightKcal = ite.kcal; that.weightKcal = ite.kcal;
if (that.bleValue.serviceId != "") { if (that.bleValue.serviceId != "") {
that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit); that.realTimeWeight(that.bleValue.countWeight, that.bleValue.unit);
if (that.bleValue.type == 2 && Number(that.bleValue.countWeight) > 0) {
that.handletoggleUnit(that.bleValue.countWeight, that.bleValue.unit, ite.nutrients_four);
}
} else { } else {
that.$store.commit("changeBluetoothValue", { that.$store.commit("changeBluetoothValue", {
countWeight: 100, countWeight: 100,
unit: "g" unit: that.bleValue.unit
}); });
that.realTimeWeight(100, "g"); that.realTimeWeight(100, that.bleValue.unit);
} }
}, },
// 下发营养含量
handletoggleUnit: function handletoggleUnit(val, unit, ite) {
var that = this;
var weight = Number(that.convertToGrams(val, unit)) / 100;
var dataArray = that.buildNutritionData({
fat: weight * ite[2].value,
calorie: weight * ite[0].value,
carbohydrate: weight * ite[3].value,
protein: weight * ite[1].value,
fiber: 0
});
var arrayBuffer = new ArrayBuffer(dataArray.length);
var uint8Array = new Uint8Array(arrayBuffer);
dataArray.forEach(function (value, index) {
uint8Array[index] = value;
});
console.log("营养数据", arrayBuffer);
that.sendArrayBuffer(arrayBuffer);
},
// 构建营养成分数据包
buildNutritionData: function buildNutritionData(data) {
// 头信息
var header = 0xC5; // 同步头
var dataLength = 0x11; // 数据长度17字节
var cmd = 0x04; // CMD字节
var packetInfo = 0x41; // 包信息总1包第1包
// 转换营养成分值×10并取整
var fatValue = Math.round(data.fat * 10);
var calorieValue = Math.round(data.calorie * 10);
var carbValue = Math.round(data.carbohydrate * 10);
var fiberValue = Math.round(data.fiber * 10);
var proteinValue = Math.round(data.protein * 10);
// 构建数据数组
var dataArray = [];
// 添加头部
dataArray.push(header); // 0xC5
dataArray.push(dataLength); // 0x11
dataArray.push(cmd); // 0x04
dataArray.push(packetInfo); // 0x41
// 添加脂肪数据大端序3字节
dataArray.push(fatValue >> 16 & 0xFF); // 高位字节
dataArray.push(fatValue >> 8 & 0xFF); // 中位字节
dataArray.push(fatValue & 0xFF); // 低位字节
// 添加卡路里数据大端序3字节
dataArray.push(calorieValue >> 16 & 0xFF);
dataArray.push(calorieValue >> 8 & 0xFF);
dataArray.push(calorieValue & 0xFF);
// 添加碳水化合物数据大端序3字节
dataArray.push(carbValue >> 16 & 0xFF);
dataArray.push(carbValue >> 8 & 0xFF);
dataArray.push(carbValue & 0xFF);
// 添加膳食纤维数据大端序3字节
dataArray.push(fiberValue >> 16 & 0xFF);
dataArray.push(fiberValue >> 8 & 0xFF);
dataArray.push(fiberValue & 0xFF);
// 添加蛋白质数据大端序3字节
dataArray.push(proteinValue >> 16 & 0xFF);
dataArray.push(proteinValue >> 8 & 0xFF);
dataArray.push(proteinValue & 0xFF);
// 计算校验和除同步头外的所有字节的和取低8位
var checksum = 0;
for (var i = 1; i < dataArray.length; i++) {
checksum = checksum + dataArray[i] & 0xFF;
}
// 添加校验和
dataArray.push(checksum);
console.log('构建的数据包:', dataArray);
console.log('十六进制:', dataArray.map(function (b) {
return b.toString(16).padStart(2, '0');
}).join(' '));
return dataArray;
},
sendArrayBuffer: function sendArrayBuffer(buffer) {
var that = this;
uni.writeBLECharacteristicValue({
deviceId: that.bleValue.deviceId,
serviceId: that.bleValue.serviceId,
characteristicId: that.bleValue.write,
value: buffer,
success: function success(res) {
console.log('下发指令成功', res.errMsg);
},
fail: function fail(res) {
console.log("下发指令失败", res);
}
});
},
//测量返回 //测量返回
handleBle: function handleBle(weight, unit, kcal) { handleBle: function handleBle(weight, unit, kcal) {
var that = this; var that = this;

File diff suppressed because one or more lines are too long

View File

@ -287,7 +287,7 @@
background-color: #f0ae43; background-color: #f0ae43;
} }
.groupbtn .left.data-v-d4f38c70 { .groupbtn .left.data-v-d4f38c70 {
width: 110px; width: 31%;
display: flex; display: flex;
align-items: center; align-items: center;
} }
@ -322,7 +322,7 @@
} }
.groupbtn .mic-icon.data-v-d4f38c70 { .groupbtn .mic-icon.data-v-d4f38c70 {
color: #fff; color: #fff;
width: calc(100% - 120px); width: 31%;
padding: 8px 0; padding: 8px 0;
background: #3CB383; background: #3CB383;
display: flex; display: flex;
@ -330,6 +330,9 @@
justify-content: center; justify-content: center;
border-radius: 20rpx; border-radius: 20rpx;
} }
.groupbtn .mic-icon2.data-v-d4f38c70 {
background: #F7931E;
}
.wrapper .box.data-v-d4f38c70 { .wrapper .box.data-v-d4f38c70 {
top: 40px; top: 40px;
background-color: #dfdfdf; background-color: #dfdfdf;

View File

@ -219,8 +219,8 @@ var _default = {
page: that.page page: that.page
}).then(function (res) { }).then(function (res) {
if (res.code == 0) { if (res.code == 0) {
that.infoList = that.infoList.concat(res.content_list); that.infoList = that.infoList.concat(res.data.content_list);
that.lastPage = res.page_total; that.lastPage = res.data.page_total;
} }
}); });
}, },

View File

@ -1,5 +1,6 @@
{ {
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "kitchendDevice",
"setting": { "setting": {
"compileHotReLoad": false "compileHotReLoad": false
} }