蓝牙设备对接

This commit is contained in:
qcl_123 2026-03-25 17:27:29 +08:00
parent 3400c47db8
commit 8f2e28012e
198 changed files with 3513 additions and 2719 deletions

View File

@ -302,9 +302,9 @@
watch: {
bleValue: {
handler(newVal, oldVal) {
this.realTimeWeight(newVal.countWeight, newVal.unit)
if (newVal.type == 2 && Number(newVal.countWeight) > 0) {
this.handletoggleUnit(newVal.countWeight, newVal.unit, this.activeType.nutrients_four)
this.realTimeWeight(newVal.foodWeight, newVal.foodUnit)
if (newVal.foodType == 2 && Number(newVal.foodWeight) > 0) {
this.handletoggleUnit(newVal.foodWeight, newVal.foodUnit, this.activeType.nutrients_four)
}
},
deep: true
@ -384,7 +384,7 @@
//
realTimeWeight(weight, unit) {
this.activeType = Object.assign({}, this.activeType, {
weight: this.convertToGrams(weight, unit)
weight: this.$ble.convertToGrams(weight, unit)
})
},
//
@ -398,17 +398,17 @@
that.activeType = ite
that.weightKcal = ite.kcal
if (that.bleValue.serviceId != "") {
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)
that.realTimeWeight(that.bleValue.foodWeight, that.bleValue.foodUnit)
if (that.bleValue.foodType == 2 && Number(that.bleValue.foodWeight) > 0) {
that.handletoggleUnit(that.bleValue.foodWeight, that.bleValue.foodUnit, ite.nutrients_four)
}
} else {
let weight = Number(that.bleValue.countWeight) > 0 ? Number(that.bleValue.countWeight) : 100
let weight = Number(that.bleValue.foodWeight) > 0 ? Number(that.bleValue.foodWeight) : 100
that.$store.commit("changeBluetoothValue", {
countWeight: weight,
unit: that.bleValue.unit
foodWeight: weight,
foodUnit: that.bleValue.foodUnit
})
that.realTimeWeight(weight, that.bleValue.unit)
that.realTimeWeight(weight, that.bleValue.foodUnit)
}
},
@ -523,14 +523,10 @@
eat_log_id: ite.food_id
}).then(res => {
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
if (that.time == that.countFoodInfo.date) {
that.$store.dispatch("getUserInfoFood")
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
})
}
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
})
that.handleAddEveryMealFood()
})
}
@ -570,30 +566,10 @@
}
return 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];
},
//
handletoggleUnit(val, unit, ite) {
let that = this
let weight = Number(that.convertToGrams(val, unit)) / 100
let weight = Number(that.$ble.convertToGrams(val, unit)) / 100
const dataArray = that.buildNutritionData({
fat: weight * ite[2].value,
calorie: weight * ite[0].value,
@ -676,7 +652,7 @@
uni.writeBLECharacteristicValue({
deviceId: that.bleValue.deviceId,
serviceId: that.bleValue.serviceId,
characteristicId: that.bleValue.write,
characteristicId: that.bleValue.foodWrite,
value: buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
@ -1246,7 +1222,6 @@
justify-content: space-between;
border-bottom: 1px solid #f1f1f1;
padding: 16rpx 0;
font-size: 24rpx;
margin-top: 10rpx;
}

View File

@ -298,14 +298,18 @@
time: that.$tools.getDate("start")
}).then(res => {
if (res.code != 0) return
that.$store.dispatch("getUserInfoFood")
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.$tools.getDate("start")
})
uni.showToast({
title: '保存成功',
icon: 'success'
})
// uni.switchTab({
// url: "/pages/count/count"
// })
that.$store.commit("changehomeCard", 1);
uni.switchTab({
url: "/pages/index/index"
})
})
}
that.showSaveFood = false

View File

@ -137,7 +137,7 @@
})
setTimeout(function() {
uni.reLaunch({
url: "/pages/home/home"
url: "/pages/index/index"
})
}, 1000)
}).catch(err => {})
@ -285,7 +285,6 @@
button {
line-height: initial;
background: #fff;
display: flex;
flex-wrap: wrap;
padding: 0;

View File

@ -58,6 +58,7 @@
that.$store.dispatch("getResult", {
aud_id: val.id
})
that.$store.commit("changehomeCard", 0);
that.$store.commit("changeDrawe", false);
// that.handlePublicRecord(val.id)
},

View File

@ -26,7 +26,7 @@
<input type="digit" v-model="weight" placeholder="请输入体重">kg
</view>
</view>
<view class="editem" v-if="userInfo.stage=='婴儿'">
<view class="editem" v-if="userInfo.stage==3">
<view class="left">头围</view>
<view class="right">
<input v-model="head" type="digit" placeholder="请输入" />cm

View File

@ -1,7 +1,7 @@
<template>
<view class="weightPages">
<view class="table">
<view class="text">
<view class="texttip">
<image src="/static/zhong.png"></image>
<text @click="openBluetoothAdapter">{{bleTipsText}}</text>
</view>
@ -14,7 +14,7 @@
<view class="weight-wrap">
<view class="weight" @click="inputDialogToggle">
<text class="val">{{weight == '' ? '0.0':weight}}</text>
<text class="unit">{{unitConversion(unit)}}</text>
<text class="unit">{{unit}}</text>
</view>
<view class="weight">
<text class="val">{{kcal?kcal:0}}</text>
@ -25,8 +25,7 @@
<view class="btn danwei">
<view class="lan border-bottom">
<view class="right">
<picker mode="selector" :range="unitA" range-key="name" @change="changleUnits"
:value="unitListIndex">
<picker mode="selector" :range="unitA" @change="changleUnits" :value="unitListIndex">
<view class="uni-input">
单位
</view>
@ -55,9 +54,11 @@
data() {
return {
kcal: "",
weightALL: "",
bleTipsText: "",
unit: 'g',
deviceId: "",
serviceId: "",
notify: "",
write: "",
unitA: [],
stopblue: false,
unitListIndex: 0,
@ -78,48 +79,50 @@
}
},
computed: {
...mapState(["user", "isBluetoothTyle", "bleValue"]),
...mapState(["user", "bleValue", "countFoodInfo"]),
weight() {
let weightNew = this.convertToGrams(this.bleValue.countWeight, this.bleValue.unit)
let weightNew = this.$ble.convertToGrams(this.bleValue.foodWeight, this.bleValue.foodUnit)
this.kcal = (Number(this.weightKcal) * weightNew).toFixed(1)
this.unit = this.bleValue.unit
return this.bleValue.countWeight
this.unit = this.bleValue.foodUnit
return this.bleValue.foodWeight
},
isConnection() {
this.bleTipsText = this.bleValue.bleTipsText
return this.bleValue.isConnectStatus
},
isShow() {
return this.bleValue.serviceId != '' ? true : false
},
},
mounted() {
let that = this
uni.onBluetoothAdapterStateChange(function(res) {
// that.$store.commit("changeBluetooth", res.available);
})
bleTipsText() {
return this.bleValue.bleTipsText
},
// unitA() {
// let that = this
// that.unitListIndex = that.bleValue.unitList.findIndex(ite => ite.unit == that.bleValue.foodUnit)
// return that.bleValue.unitList
// }
},
watch: {
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.handleBack()
}
bleValue: {
handler(newVal, oldVal) {
let that = this
if (!newVal.isBluetoothTyle) {
that.handleBack()
}
if (newVal.serviceId) {
that.deviceId = newVal.deviceId
that.serviceId = newVal.serviceId
that.getBLEDeviceCharacteristics()
}
that.unitA = newVal.unitList
that.unitListIndex = newVal.unitList.findIndex(ite => ite.unit == newVal.foodUnit)
},
deep: true,
immediate: true
},
isLast: {
handler(newVal, oldVal) {
this.stopblue = newVal
},
// deep: true,
immediate: true
},
bleValue: {
handler(newVal, oldVal) {
this.unitA = newVal.unitList
this.unitListIndex = newVal.unitList.findIndex(ite => ite.unit == newVal.unit)
},
deep: true,
immediate: true
},
},
@ -127,80 +130,173 @@
//
openBluetoothAdapter() {
let that = this
if (that.isConnection == 0) return
if (that.isConnection != 1) return
that.kcal = ""
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
notify: '',
write: '',
unit: "g",
type: 1,
unitList: that.$json.unitMinus,
countWeight: "",
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0,
isBleLink: false,
deviceId: "",
serviceId: "",
foodNotify: "",
foodType: 1,
foodWrite: "",
foodWeight: 0,
})
that.$ble.openBluetoothAdapter()
},
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics() {
let that = this
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
that.write = item.uuid
} else if (item.uuid.indexOf('0000FFF1') != -1) {
that.notify = item.uuid
}
}
that.getBLECharacteristicValueChange()
},
fail: res => {
that.$store.commit("changeBluetoothValue", {
foodType: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
getBLECharacteristicValueChange() {
let that = this
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.notify,
state: true,
success: () => {
that.$store.commit('changeBluetoothValue', {
deviceId: that.deviceId,
serviceId: that.serviceId,
foodNotify: that.notify,
foodWrite: that.write,
bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 2
})
uni.onBLECharacteristicValueChange(function(res) {
const value = res.value
const dataView = new DataView(value)
const header = dataView.getUint8(0)
// MCU
if (header === 0xC7) {
const cmd = dataView.getUint8(2)
switch (cmd) {
case 0x02:
const statusByte = dataView.getUint8(4)
const isNegative = !!(statusByte & 0x80) //
const statusType = statusByte & 0x0F //
// 24 ()
const weightValue =
(dataView.getUint8(5) << 16) |
(dataView.getUint8(6) << 8) |
dataView.getUint8(7)
//
const unitByte = dataView.getUint8(8)
const precision = (unitByte & 0xF0) >> 4 // 4
const unitIndex = unitByte & 0x0F // 4
//
let finalWeight = weightValue / Math.pow(10, precision)
if (isNegative) finalWeight = -finalWeight
that.$store.commit("changeBluetoothValue", {
foodWeight: finalWeight,
foodUnit: that.$json.units[unitIndex],
foodType: statusType
})
console.log('重量:' + finalWeight, "状态:" + statusType)
console.log('单位:' + that.$json.units[unitIndex])
break
case 0x03:
break
case 0x08:
const start0 = []
const value2 = that.$tools.ab2hex(value, "");
const start = that.$tools.parseUnitMask(value2.substring(8,
10), that.$json.units.slice(0, 7))
const start1 = that.$tools.parseUnitMask(value2.substring(10,
12), that.$json.units.slice(8, 10))
start.push.apply(start, start1)
if (start.length) {
that.$json.unitMinus.forEach(item => {
start.forEach(item2 => {
if (item == item2) {
start0.push(item)
}
})
})
}
that.$store.commit("changeBluetoothValue", {
unitList: start0.length ? start0 : that.$json
.unitMinus
})
console.log("22222222222222", start, start0)
break
}
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
//
handleDetailSub() {
let that = this
if (Number(that.weight) > 0) {
that.$emit("handleDetailSub", that.weight, that.unit, that.kcal)
} else {
that.$tools.msg("数据异常,请清零后重新测量!")
}
},
//
handleDetailNext() {
let that = this
if (Number(that.weight) > 0) {
that.$emit("handleDetailNext", that.weight, that.unit, that.kcal)
} else {
that.$tools.msg("数据异常,请清零后重新测量!")
}
},
changleUnits(e) {
let that = this
let name = that.unitA[e.detail.value].name
let val = that.unitA[e.detail.value].unit
if (that.isShow && that.unit != name) {
that.handletoggleUnit(that.unitConversion2(val))
let unit = that.unitA[e.detail.value]
console.log("danwei", that.unit, unit)
if (that.isShow && that.unit != unit) {
that.handletoggleUnit(that.$ble.unitInstruction(unit))
}
if (that.bleValue.serviceId == '') {
that.unitListIndex = [e.detail.value]
that.$store.commit('changeBluetoothValue', {
unit: that.unitA[e.detail.value].unit,
foodUnit: that.unitA[e.detail.value],
})
}
},
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
};
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) {
let that = this
@ -226,7 +322,7 @@
uni.writeBLECharacteristicValue({
deviceId: that.bleValue.deviceId,
serviceId: that.bleValue.serviceId,
characteristicId: that.bleValue.write,
characteristicId: that.bleValue.foodWrite,
value: buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
@ -238,68 +334,26 @@
},
handleBack() {
let that = this
that.unitA = that.$json.unitMinus
that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接失败,点击重新连接",
unitList: that.$json.unitMinus,
isConnectStatus: 1,
foodType: 1
})
that.$ble.stopBluetoothDevicesDiscovery() //
that.$ble.closeBLEConnection(that.bleValue.deviceId)
that.$ble.closeBLEConnection(that.deviceId)
that.$ble.closeBluetoothAdapter()
},
unitConversion(unit) {
if (unit == 'kg') {
return '千克'
} else if (unit == '斤') {
return '斤'
} else if (unit == 'stlb') {
return 'stlb'
} else if (unit == 'lb') {
return '磅'
} else if (unit == 'g') {
return '克'
} else if (unit == 'ml') {
return '毫升'
} else if (unit == 'Waterml') {
return 'Waterml'
} else if (unit == 'milkml') {
return 'milkml'
} else if (unit == 'oz') {
return '盎司'
} else if (unit == 'floz') {
return 'floz'
} else if (unit == 'lboz') {
return 'lboz'
}
return unit
},
//
handleDetailSub() {
let that = this
if (Number(that.weight) > 0) {
that.$emit("handleDetailSub", that.weight, that.unit, that.kcal)
} else {
that.$tools.msg("数据异常,请清零后重新测量!")
}
},
//
handleDetailNext() {
let that = this
if (Number(that.weight) > 0) {
that.$emit("handleDetailNext", that.weight, that.unit, that.kcal)
} else {
that.$tools.msg("数据异常,请清零后重新测量!")
}
},
confirm(value) {
console.log(value)
let that = this
this.$store.commit("changeBluetoothValue", {
countWeight: value,
unit: this.unitA[this.unitListIndex].unit
that.$store.commit("changeBluetoothValue", {
foodWeight: value,
foodUnit: that.$json.unitMinus[that.unitListIndex]
})
this.$refs.popup.close()
that.$refs.popup.close()
},
close() {
this.$refs.popup.close()
@ -321,7 +375,7 @@
display: flex;
justify-content: space-between;
.text {
.texttip {
color: #8284f0;
display: flex;

View File

@ -1,7 +1,7 @@
<template>
<view class="weightPages">
<view class="table">
<view class="text">
<view class="textTipe">
<image src="/static/zhong.png"></image>
<text @click="openBluetoothAdapter">{{bleTipsText}}</text>
</view>
@ -14,7 +14,7 @@
<!-- 蓝牙称重 -->
<view class="weight" @click="inputDialogToggle">
<text class="val">{{weight == '' ? '0.0':weight}}</text>
<text class="unit">{{unitConversion(unit)}}</text>
<text class="unit">{{unit}}</text>
</view>
</view>
<!-- -->
@ -22,8 +22,7 @@
<view class="btn danwei">
<view class="lan border-bottom">
<view class="right">
<picker mode="selector" :range="unitA" range-key="name" @change="changleUnits"
:value="unitListIndex">
<picker mode="selector" :range="unitA" @change="changleUnits" :value="unitListIndex">
<view class="uni-input">
单位
</view>
@ -55,9 +54,13 @@
data() {
return {
kcal: 0,
unit: '',
inputDialog: false,
unit: 'g',
deviceId: "",
serviceId: "",
notify: "",
write: "",
unitA: [],
inputDialog: false,
unitListIndex: 0,
}
},
@ -72,12 +75,12 @@
}
},
computed: {
...mapState(["bleValue", "isBluetoothTyle", "countFoodInfo"]),
...mapState(["bleValue", "countFoodInfo", "user"]),
weight() {
let weightNew = this.convertToGrams(this.bleValue.countWeight, this.bleValue.unit)
let weightNew = this.$ble.convertToGrams(this.bleValue.foodWeight, this.bleValue.foodUnit)
this.kcal = (Number(this.weightKcal) / 100 * weightNew).toFixed(1)
this.unit = this.bleValue.unit
return this.bleValue.countWeight
this.unit = this.bleValue.foodUnit
return this.bleValue.foodWeight
},
isConnection() {
return this.bleValue.isConnectStatus
@ -87,30 +90,22 @@
},
bleTipsText() {
return this.bleValue.bleTipsText
}
},
mounted() {
let that = this
uni.onBluetoothAdapterStateChange(function(res) {
// that.$store.commit("changeBluetooth", res.available);
})
},
destroyed() {
// this.isConnection = 1
// this.closeBLEConnection()
// this.closeBluetoothAdapter()
},
},
watch: {
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.handleBack()
}
},
bleValue: {
handler(newVal, oldVal) {
this.unitA = newVal.unitList
this.unitListIndex = newVal.unitList.findIndex(ite => ite.unit == newVal.unit)
let that = this
if (!newVal.isBluetoothTyle) {
that.handleBack()
}
if (newVal.serviceId) {
that.deviceId = newVal.deviceId
that.serviceId = newVal.serviceId
that.getBLEDeviceCharacteristics()
}
that.unitA = newVal.unitList
that.unitListIndex = newVal.unitList.findIndex(ite => ite.unit == newVal.foodUnit)
},
deep: true,
immediate: true
@ -120,80 +115,157 @@
//
openBluetoothAdapter() {
let that = this
if (that.isConnection == 2) return
if (that.isConnection != 1) return
that.kcal = ""
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
notify: '',
write: '',
unit: "g",
type: 1,
unitList: that.$json.unitMinus,
countWeight: "",
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0,
isBleLink: false,
deviceId: "",
serviceId: "",
foodNotify: "",
foodType: 1,
foodWrite: "",
foodWeight: 0
})
that.$ble.openBluetoothAdapter()
},
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics() {
let that = this
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
that.write = item.uuid
} else if (item.uuid.indexOf('0000FFF1') != -1) {
that.notify = item.uuid
}
}
that.getBLECharacteristicValueChange()
},
fail: res => {
that.$store.commit("changeBluetoothValue", {
foodType: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
getBLECharacteristicValueChange() {
let that = this
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.notify,
state: true,
success: () => {
that.$store.commit('changeBluetoothValue', {
deviceId: that.deviceId,
serviceId: that.serviceId,
foodNotify: that.notify,
foodWrite: that.write,
bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 2
})
uni.onBLECharacteristicValueChange(function(res) {
const value = res.value
const dataView = new DataView(value)
const header = dataView.getUint8(0)
// MCU
if (header === 0xC7) {
const cmd = dataView.getUint8(2)
switch (cmd) {
case 0x02:
const statusByte = dataView.getUint8(4)
const isNegative = !!(statusByte & 0x80) //
const statusType = statusByte & 0x0F //
// 24 ()
const weightValue =
(dataView.getUint8(5) << 16) |
(dataView.getUint8(6) << 8) |
dataView.getUint8(7)
//
const unitByte = dataView.getUint8(8)
const precision = (unitByte & 0xF0) >> 4 // 4
const unitIndex = unitByte & 0x0F // 4
//
let finalWeight = weightValue / Math.pow(10, precision)
if (isNegative) finalWeight = -finalWeight
that.$store.commit("changeBluetoothValue", {
foodWeight: finalWeight,
foodUnit: that.$json.units[unitIndex],
foodType: statusType
})
console.log('重量:' + finalWeight, "状态:" + statusType)
console.log('单位:' + that.$json.units[unitIndex])
break
case 0x03:
break
case 0x08:
const start0 = []
const value2 = that.$tools.ab2hex(value, "");
const start = that.$tools.parseUnitMask(value2.substring(8,
10), that.$json.units.slice(0, 7))
const start1 = that.$tools.parseUnitMask(value2.substring(10,
12), that.$json.units.slice(8, 10))
start.push.apply(start, start1)
if (start.length) {
that.$json.unitMinus.forEach(item => {
start.forEach(item2 => {
if (item == item2) {
start0.push(item)
}
})
})
}
that.$store.commit("changeBluetoothValue", {
unitList: start0.length ? start0 : that.$json
.unitMinus
})
console.log("22222222222222", start, start0)
break
}
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
changleUnits(e) {
let that = this
let name = that.unitA[e.detail.value].name
let val = that.unitA[e.detail.value].unit
if (that.isShow && that.unit != name) {
that.handletoggleUnit(that.unitConversion2(val))
let unit = that.unitA[e.detail.value]
console.log("danwei", that.unit, unit)
if (that.isShow && that.unit != unit) {
that.handletoggleUnit(that.$ble.unitInstruction(unit))
}
if (that.bleValue.serviceId == '') {
that.unitListIndex = [e.detail.value]
that.$store.commit('changeBluetoothValue', {
unit: that.unitA[e.detail.value].unit,
foodUnit: that.unitA[e.detail.value],
})
}
},
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) {
let that = this
@ -218,9 +290,9 @@
sendData(buffer) {
let that = this
uni.writeBLECharacteristicValue({
deviceId: that.bleValue.deviceId,
serviceId: that.bleValue.serviceId,
characteristicId: that.bleValue.write,
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.write,
value: buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
@ -246,38 +318,14 @@
bleTipsText: "连接失败,点击重新连接",
unitList: that.$json.unitMinus,
isConnectStatus: 1,
foodType: 1
})
that.$ble.stopBluetoothDevicesDiscovery() //
that.$ble.closeBLEConnection(that.bleValue.deviceId)
that.$ble.closeBLEConnection(that.deviceId)
that.$ble.closeBluetoothAdapter()
},
unitConversion(unit) {
if (unit == 'kg') {
return '千克'
} else if (unit == '斤') {
return '斤'
} else if (unit == 'stlb') {
return 'stlb'
} else if (unit == 'lb') {
return '磅'
} else if (unit == 'g') {
return '克'
} else if (unit == 'ml') {
return '毫升'
} else if (unit == 'Waterml') {
return 'Waterml'
} else if (unit == 'milkml') {
return 'milkml'
} else if (unit == 'oz') {
return '盎司'
} else if (unit == 'floz') {
return 'floz'
} else if (unit == 'lboz') {
return 'lboz'
}
return unit
},
//
handleAddFood() {
uni.navigateTo({
@ -289,13 +337,12 @@
},
//
confirm(value) {
console.log(value)
let that = this
this.$store.commit("changeBluetoothValue", {
countWeight: value,
unit: this.unitA[this.unitListIndex].unit
that.$store.commit("changeBluetoothValue", {
foodWeight: value,
foodUnit: that.$json.unitMinus[that.unitListIndex]
})
this.$refs.popup.close()
that.$refs.popup.close()
},
close() {
this.$refs.popup.close()
@ -324,7 +371,6 @@
position: relative;
background: #fff;
border-radius: 20rpx;
margin: 10px;
justify-content: space-around;
.weight-wrap {
@ -409,7 +455,7 @@
display: flex;
justify-content: space-between;
.text {
.textTipe {
color: #8284f0;
display: flex;
}

View File

@ -55,26 +55,7 @@
"unit": "lboz"
}
],
"unitMinus": [{
"name": "千克",
"unit": "kg"
},
{
"name": "磅",
"unit": "lb"
}, {
"name": "克",
"unit": "g"
}, {
"name": "毫升",
"unit": "ml"
},
{
"name": "盎司",
"unit": "oz"
}
],
"unitMinus": ["g", "kg", "lb", "ml", "oz"],
"units": ["kg", "斤", "stlb", "lb", "g", "ml", "Waterml", "milkml", "oz", "floz", "lboz"]
}

View File

@ -1,8 +1,8 @@
<template>
<view class="weightPages">
<view class="content ">
<view class="status">{{UseBlueConfig.BleConnectMsg}}</view>
<view class="quan">
<view class="status">{{bleTipsText}}</view>
<view class="quan2">
<view>
<text class="weight">{{weight?weight:'0.00'}}</text>{{unit}}
</view>
@ -29,7 +29,7 @@
<view class="Blue-box">
上次测量身高是<input v-model="height" type="digit" placeholder="请输入身高" />cm
</view>
<view class="Blue-box" v-if="userInfo.stage=='婴儿'">
<view class="Blue-box" v-if="userInfo.stage==3">
上次测量头围是<input v-model="head" type="digit" placeholder="请输入头围" />cm
</view>
<view class="Blue-btn Blue-close" @click="handleBack">重新测量</view>
@ -59,43 +59,54 @@
write: "",
notify: "",
isFinished: false, //
devicesList: [],
IsLing: false, //
IsNum: false, //
}
},
computed: {
...mapState(["user", "UseBlueConfig"]),
...mapState(["user", "bleValue"]),
userInfo() {
return this.user
},
bleTipsText() {
return this.bleValue.bleTipsText
}
},
onUnload: function() {
let that = this
that.useBluetooth.clearBluetoothStatus()
},
onLoad(options) {
let that = this
that.typeInfo = 0
that.height = that.userInfo.height
that.head = that.userInfo.head_data
that.deviceId = options.deviceId
that.useBluetooth.createBLEConnection("FFF0")
that.useBluetooth.onBLEConnectionStateChange()
that.useBluetooth.onBluetoothAdapterStateChange()
that.$ble.createBLEConnection("FFF0")
that.$ble.onBLEConnectionStateChange()
},
onUnload: function() {
let that = this
that.$ble.closeBLEConnection()
that.$ble.closeBluetoothAdapter()
console.log("返回首页onUnload")
},
watch: {
'UseBlueConfig.isUseConnect'() {
let that = this
if (!that.UseBlueConfig.isUseConnect) {
that.$tools.showModal('蓝牙连接已断开,请重新连接后测量')
}
},
'UseBlueConfig.serviceId'() {
let that = this
if (that.UseBlueConfig.serviceId) {
that.getBLEDeviceCharacteristics(that.UseBlueConfig.serviceId)
}
bleValue: {
handler(newVal, oldVal) {
let that = this
if (!newVal.isBluetoothTyle) {
that.$tools.showModal('蓝牙连接已断开,请重新连接后测量')
setTimeout(function() {
uni.switchTab({
url: "/pages/index/index"
})
}, 1000)
}
if (newVal.serviceId) {
that.deviceId = newVal.deviceId
that.serviceId = newVal.serviceId
that.getBLEDeviceCharacteristics()
}
},
deep: true,
immediate: true
},
isFinished: function() {
let that = this
@ -131,9 +142,11 @@
that.writeBLECharacteristicValue("A6020500076A") //
}
}
that.$store.commit("getIsUseBluetooth", {
BleConnectMsg: "蓝牙连接成功,请开始测量",
});
that.$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 2,
bleTipsText: "蓝牙连接成功,请上秤测量",
})
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: that.serviceId,
@ -277,32 +290,29 @@
return
}
that.$model.getmeasurefunit({
adc: 0,
weight: that.weight + that.unit,
height: that.height,
aud_id: that.userInfo.id,
head_data: that.head ? that.head : 0
aud_id: that.userInfo.aud_id,
head_data: that.head ? that.head : 0,
}).then(res => {
that.isHeight = false
that.isSave = false
if (res.code == 0) {
that.$store.dispatch("getResult", {
aud_id: uni.getStorageSync('userid')
})
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: that.user.aud_id
})
that.$tools.msg("测量成功")
} else {
that.$tools.msg("测量失败")
}
uni.switchTab({
url: "/pages/body/body"
})
// setTimeout(function() {
// that.closeBLEConnection()
// that.closeBluetoothAdapter()
// }, 200)
setTimeout(function(){
uni.switchTab({
url: "/pages/index/index"
})
},500)
})
},
//
@ -354,9 +364,9 @@
background: linear-gradient(-90deg, #feaa50, #e96b13 80%) !important;
}
.quan {
width: 400rpx;
height: 400rpx;
.quan2 {
width: 460rpx;
height: 460rpx;
border: 8px solid #feaa50;
border-radius: 50%;
margin: 15px auto;

View File

@ -68,26 +68,33 @@
that.deviceId = options.deviceId
that.$ble.createBLEConnection("FFF0")
that.$ble.onBLEConnectionStateChange()
that.$ble.onBluetoothAdapterStateChange()
},
onUnload: function() {
let that = this
that.$ble.closeBLEConnection()
that.$ble.closeBluetoothAdapter()
console.log("返回首页onUnload")
},
watch: {
'bleValue.isBluetoothTyle'() {
let that = this
if (!that.bleValue.isBluetoothTyle) {
that.$tools.showModal('蓝牙连接已断开,请重新连接后测量')
setTimeout(function() {
uni.switchTab({
url: "/pages/index/index"
})
}, 1000)
}
},
'bleValue.serviceId'() {
let that = this
if (that.bleValue.serviceId) {
console.log("serviceId", that.bleValue.serviceId)
that.getBLEDeviceCharacteristics(that.bleValue.serviceId)
}
bleValue: {
handler(newVal, oldVal) {
let that = this
if (!newVal.isBluetoothTyle) {
that.$tools.showModal('蓝牙连接已断开,请重新连接后测量')
setTimeout(function() {
uni.switchTab({
url: "/pages/index/index"
})
}, 1000)
}
if (newVal.serviceId) {
that.deviceId = newVal.deviceId
that.serviceId = newVal.serviceId
that.getBLEDeviceCharacteristics(newVal.serviceId)
}
},
deep: true,
immediate: true
},
},
methods: {
@ -112,7 +119,7 @@
that.$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 2,
bleTipsText: "蓝牙连接成功,请上秤测量",
bleTipsText: "蓝牙连接成功,请开始测量",
})
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
@ -200,14 +207,9 @@
}
that.$model.getmeasurefunit({
adc: 0,
weight: that.weight,
weight: that.weight + 'kg',
height: height,
aud_id: that.user.aud_id,
lefthand: 0,
righthand: 0,
leftfoot: 0,
rightfoot: 0,
heart_rate: 0,
}).then(res => {
that.isHeight = false
console.log("报告", res)
@ -215,13 +217,18 @@
that.$store.dispatch('getUserInfo', {
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: that.user.aud_id
})
that.$tools.msg("测量成功")
} else {
that.$tools.msg("测量失败")
}
uni.switchTab({
url: "/pages/index/index"
})
setTimeout(function(){
uni.switchTab({
url: "/pages/index/index"
})
},500)
})
},
handleHeight() {

View File

@ -49,22 +49,18 @@
}
},
computed: {
...mapState(["user"]),
...mapState(["user", "bleValue"]),
info() {
return this.user
},
},
onUnload: function() {
let that = this
that.useBluetooth.clearBluetoothStatus()
},
onLoad(options) {
let that = this
that.text = ""
that.stopblue = true
that.deviceId = options.deviceId
that.height = that.user.height
uni.onBluetoothDeviceFound(handleDeviceFound)
that.onBluetoothDeviceFound()
},
watch: {
stopblue: function() {
@ -79,48 +75,50 @@
/**
* 发现外围设备
*/
onBluetoothDeviceFound(res) {
var that = this;
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
if (device.name.toLowerCase().indexOf("pcl") !== -1 && device.deviceId.indexOf(that
.deviceId) != -1) {
let value = that.$tools.ab2hex(device.advertisData, "")
let data = parseInt(value.substring(4, 8), 16)
let msg = parseInt(value.substring(16, 18), 16).toString(2)
let type = msg.substring(5, 6) //0,1
let num = msg.substring(3, 5) //
let dw = msg.substring(1, 3) //
if (dw == "01") {
that.unit = "斤"
}
if (dw == "10") {
that.unit = "lb"
}
if (num == "00") {
data = data / 10
}
if (num == "10") {
onBluetoothDeviceFound() {
var that = this
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
if (device.name.toLowerCase().indexOf("pcl") !== -1 && device.deviceId.indexOf(that
.deviceId) != -1) {
let value = that.$tools.ab2hex(device.advertisData, "")
let data = parseInt(value.substring(4, 8), 16)
let msg = parseInt(value.substring(16, 18), 16).toString(2)
let type = msg.substring(5, 6) //0,1
let num = msg.substring(3, 5) //
let dw = msg.substring(1, 3) //
if (dw == "01") {
that.unit = "斤"
}
if (dw == "10") {
that.unit = "lb"
data = data / 10
} else {
data = data / 100
}
if (num == "00") {
data = data / 10
}
if (num == "10") {
if (dw == "10") {
that.unit = "lb"
data = data / 10
} else {
data = data / 100
}
}
that.text = "您的实时体重是:" + data + that.unit
if (type == "1") {
that.text = "您的稳定体重是:" + data + that.unit
that.imp = parseInt(value.substring(8, 12), 16) / 10
that.deviceId = device.deviceId
that.weight = data
that.stopblue = false
that.$ble.stopBluetoothDevicesDiscovery() //
return
}
return;
}
that.text = "您的实时体重是:" + data + that.unit
if (type == "1") {
that.text = "您的稳定体重是:" + data + that.unit
that.imp = parseInt(value.substring(8, 12), 16) / 10
that.deviceId = device.deviceId
that.weight = data
that.stopblue = false
that.useBluetooth.stopSearchBluetooth() //
return
}
return;
}
})
})
});
},
//
handleGetMeasure() {
@ -133,16 +131,16 @@
adc: that.imp,
weight: that.weight + that.unit,
height: that.height,
aud_id: that.info.id
aud_id: that.user.aud_id,
}).then(res => {
that.isHeight = false
console.log("res", res, that.imp)
if (res.code == 0) {
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$tools.msg("测量成功")
} else {
@ -150,7 +148,7 @@
}
setTimeout(function() {
uni.switchTab({
url: "/pages/body/body"
url: "/pages/index/index"
})
}, 200)
})
@ -159,14 +157,16 @@
handleBack() {
let that = this
that.text = ""
that.$store.commit("getIsUseBluetooth", {
isBleLink: true,
BleBodyMsg: "开始测量",
isUseConnect: false,
that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1,
isBleLink: false,
deviceId: "",
serviceId: "",
});
that.useBluetooth.stopSearchBluetooth() //
that.$ble.stopBluetoothDevicesDiscovery() //
uni.switchTab({
url: "/pages/body/body"
url: "/pages/index/index"
})
},
},

View File

@ -50,22 +50,18 @@
}
},
computed: {
...mapState(["user"]),
...mapState(["user", "bleValue"]),
info() {
return this.user
},
},
onUnload: function() {
let that = this
that.useBluetooth.clearBluetoothStatus()
},
onLoad(options) {
let that = this
that.text = ""
that.typeInfo = -1
that.deviceId = options.deviceId
that.height = that.user.height
uni.onBluetoothDeviceFound(handleDeviceFound)
that.onBluetoothDeviceFound()
},
watch: {
stopblue: function() {
@ -83,54 +79,56 @@
/**
* 发现外围设备
*/
onBluetoothDeviceFound(res) {
var that = this;
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
let value = that.$tools.ab2hex(device.advertisData, "")
let type = value.substring(0, 2)
if (type.toLowerCase() == 'c0') {
let msg = parseInt(value.substring(16, 18), 16).toString(2)
let type = msg.substring(0, 1) // 01
let unit = msg.substring(1, 3) //
let num = msg.substring(3, 5) //
let weight = parseInt(value.substring(4, 8), 16)
let status = msg.substring(5, 6) //0,1
console.log("value", value, "状态:", status, "类型:", type, )
console.log('体重:', weight, "小数点:", num, "单位:", unit)
if (unit == "10") {
that.unit = "lb"
}
if (num == "00") {
weight = weight / 10
}
if (num == "10") {
onBluetoothDeviceFound() {
var that = this
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
let value = that.$tools.ab2hex(device.advertisData, "")
let type = value.substring(0, 2)
if (type.toLowerCase() == 'c0') {
let msg = parseInt(value.substring(16, 18), 16).toString(2)
let type = msg.substring(0, 1) // 01
let unit = msg.substring(1, 3) //
let num = msg.substring(3, 5) //
let weight = parseInt(value.substring(4, 8), 16)
let status = msg.substring(5, 6) //0,1
console.log("value", value, "状态:", status, "类型:", type, )
console.log('体重:', weight, "小数点:", num, "单位:", unit)
if (unit == "10") {
that.unit = "lb"
}
if (num == "00") {
weight = weight / 10
} else {
weight = weight / 100
}
}
if (status == "0") {
that.typeInfo = 0
that.stopblue = false
that.text = "您的实时体重是:" + weight + that.unit
}
if (status == "1") {
if (type == '1') {
that.imp = parseInt(value.substring(8, 12), 16) / 10
if (num == "10") {
if (unit == "10") {
that.unit = "lb"
weight = weight / 10
} else {
weight = weight / 100
}
}
that.typeInfo = 1
that.text = "您的稳定体重是:" + weight + that.unit
that.weight = weight
that.stopblue = true
that.useBluetooth.stopSearchBluetooth() //
console.log("测量完成", that.weight)
if (status == "0") {
that.typeInfo = 0
that.stopblue = false
that.text = "您的实时体重是:" + weight + that.unit
}
if (status == "1") {
if (type == '1') {
that.imp = parseInt(value.substring(8, 12), 16) / 10
}
that.typeInfo = 1
that.text = "您的稳定体重是:" + weight + that.unit
that.weight = weight
that.stopblue = true
that.$ble.stopBluetoothDevicesDiscovery() //
console.log("测量完成", that.weight, that.imp)
}
return;
}
return;
}
})
})
});
},
//
handleGetMeasure() {
@ -143,16 +141,15 @@
adc: that.imp,
weight: that.weight + that.unit,
height: that.height,
aud_id: that.info.id
aud_id: that.user.aud_id,
}).then(res => {
that.isHeight = false
console.log("res", res, that.imp)
if (res.code == 0) {
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$tools.msg("测量成功")
} else {
@ -160,7 +157,7 @@
}
setTimeout(function() {
uni.switchTab({
url: "/pages/body/body"
url: "/pages/index/index"
})
}, 200)
})
@ -169,14 +166,16 @@
handleBack() {
let that = this
that.text = ""
that.$store.commit("getIsUseBluetooth", {
isBleLink: true,
BleBodyMsg: "开始测量",
isUseConnect: false,
that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1,
isBleLink: false,
deviceId: "",
serviceId: "",
});
that.useBluetooth.stopSearchBluetooth() //
that.$ble.stopBluetoothDevicesDiscovery() //
uni.switchTab({
url: "/pages/body/body"
url: "/pages/index/index"
})
},
},

View File

@ -50,15 +50,11 @@
}
},
computed: {
...mapState(["user"]),
...mapState(["user", "bleValue"]),
info() {
return this.user
},
},
onUnload: function() {
let that = this
that.useBluetooth.clearBluetoothStatus()
},
onLoad(options) {
let that = this
that.text = ""
@ -66,7 +62,7 @@
that.stopblue = false
that.deviceId = options.deviceId
that.height = that.user.height
uni.onBluetoothDeviceFound(handleDeviceFound)
that.onBluetoothDeviceFound()
},
watch: {
stopblue: function() {
@ -84,34 +80,36 @@
/**
* 发现外围设备
*/
onBluetoothDeviceFound(res) {
var that = this;
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
if (device.name.toLowerCase().indexOf("da") !== -1) {
clearTimeout(myTime);
let value = that.$tools.ab2hex(device.advertisData, "")
let type = value.substring(0, 1) //de
let type2 = value.substring(1, 2) //0~9A~F
let weight = parseInt(value.substring(2, 6), 16) / 100
console.log("VALUE", value, type, isNaN(type2), weight)
if (type == "d") {
that.typeInfo = 0
that.stopblue = false
that.text = "您的实时体重是:" + weight + 'kg'
onBluetoothDeviceFound() {
var that = this
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
if (device.name.toLowerCase().indexOf("da") !== -1) {
clearTimeout(myTime);
let value = that.$tools.ab2hex(device.advertisData, "")
let type = value.substring(0, 1) //de
let type2 = value.substring(1, 2) //0~9A~F
let weight = parseInt(value.substring(2, 6), 16) / 100
console.log("VALUE", value, type, isNaN(type2), weight)
if (type == "d") {
that.typeInfo = 0
that.stopblue = false
that.text = "您的实时体重是:" + weight + 'kg'
}
if (type == "e") {
that.typeInfo = 1
that.text = "您的稳定体重是:" + weight + 'kg'
that.imp = !isNaN(type2) ? parseInt(value.substring(6, 10), 16) : ''
that.weight = weight
that.stopblue = true
that.$ble.stopBluetoothDevicesDiscovery() //
return
}
return;
}
if (type == "e") {
that.typeInfo = 1
that.text = "您的稳定体重是:" + weight + 'kg'
that.imp = !isNaN(type2) ? parseInt(value.substring(6, 10), 16) : ''
that.weight = weight
that.stopblue = true
that.useBluetooth.stopSearchBluetooth() //
return
}
return;
}
})
})
});
},
//
handleGetMeasure() {
@ -124,16 +122,16 @@
adc: that.imp,
weight: that.weight + that.unit,
height: that.height,
aud_id: that.info.id
aud_id: that.user.aud_id,
}).then(res => {
that.isHeight = false
console.log("res", res, that.imp)
if (res.code == 0) {
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: uni.getStorageSync('userid')
aud_id: that.user.aud_id
})
that.$tools.msg("测量成功")
} else {
@ -141,7 +139,7 @@
}
setTimeout(function() {
uni.switchTab({
url: "/pages/body/body"
url: "/pages/index/index"
})
}, 200)
})
@ -150,14 +148,16 @@
handleBack() {
let that = this
that.text = ""
that.$store.commit("getIsUseBluetooth", {
isBleLink: true,
BleBodyMsg: "开始测量",
isUseConnect: false,
that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1,
isBleLink: false,
deviceId: "",
serviceId: "",
});
that.useBluetooth.stopSearchBluetooth() //
that.$ble.stopBluetoothDevicesDiscovery() //
uni.switchTab({
url: "/pages/body/body"
url: "/pages/index/index"
})
},
},

View File

@ -87,7 +87,7 @@
}
},
computed: {
...mapState(["isConnected", "isBluetoothTyle"]),
...mapState(["bleValue","user"]),
},
onLoad(options) {
let that = this
@ -104,10 +104,7 @@
}, 1200)
}
that.handleAudioStart()
that.$Bluetooth.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
// that.$store.commit("changeBluetooth", res.available);
})
that.$ble.onBLEConnectionStateChange()
},
onUnload: function() {
let that = this
@ -118,9 +115,9 @@
console.log("PCT01返回onUnload")
},
watch: {
isConnected: function() {
"bleValue.isBluetoothTyle": function() {
let that = this
if (!that.isConnected) {
if (!bleValue.isBluetoothTyle) {
uni.showModal({
title: '连接已断开',
content: '训练过程中已与设备连接中断,请重新连接设备再开始训练',
@ -134,12 +131,7 @@
console.log("蓝牙是否连接", that.isConnected)
}
},
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
console.log("蓝牙是否打开", that.isBluetoothTyle)
}
},
//
isStart: function() {
let that = this
@ -399,8 +391,8 @@
that.time_s = that.time % 60
}
console.log("111111保存", that.weight, that.Ycount, that.time_m, that.time_s)
that.$model.getskipResult({
aud_id: uni.getStorageSync('userid'),
that.$model.getSkipResult({
aud_id: that.user.aud_id,
kcal: Math.floor(that.kcal),
num: that.weight,
time_m: Number(that.time_m),
@ -414,8 +406,8 @@
that.bpm = that.weight / (that.time / 60)
that.iswrapper = true
that.info.isSuccessful = true
that.$store.dispatch('getUserInfo', {
aud_id: uni.getStorageSync('userid')
that.$store.dispatch("getSkipResult", {
aud_id: that.user.aud_id
})
} else {
that.$tools.msg(res.msg)

423
pageTwo/devices/pcL06.vue Normal file
View File

@ -0,0 +1,423 @@
<template>
<view class="weightPages">
<view class="content ">
<view class="status">{{bleTipsText}}</view>
<view class="quan">
<view>
<text class="weight">{{weight?weight:'0.00'}}</text>{{unit}}
</view>
<view class="typeInfo" v-if="typeInfo!=0">{{typeInfo==2?'稳定重量':'实时重量'}}</view>
</view>
<view class="tips">
<text>提示</text>
<text>1.请确定设备是开机状态</text>
<text>2.请确定手机蓝牙位置信息已打开</text>
</view>
</view>
<!-- 手动记录 -->
<view class="wrapper" v-if="isHeight">
<view class="bg"></view>
<view class="Blue">
<view class="h4">测量结果提示</view>
<view class="Blue-box">
本次测量身高为<text>{{height}}{{unit}}</text>
</view>
<view class="Blue-box">
上次测量体重为<input v-model="weight" type="digit" placeholder="请输入体重" />kg
</view>
<view class="Blue-btn Blue-close" @click="handleHeight">重新测量</view>
<view class="Blue-btn" @click="handleGetMeasure">保存测量结果</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
export default {
data() {
return {
text: "",
typeInfo: 0,
head: "",
weight: "",
height: "",
unit: "kg",
isHeight: false,
isSave: true, //
deviceId: "",
serviceId: "",
write: "",
notify: "",
isFinished: false, //
devicesList: [],
IsLing: false, //
IsNum: false, //
}
},
computed: {
...mapState(["user", "bleValue"]),
userInfo() {
return this.user
},
bleTipsText() {
return this.bleValue.bleTipsText
}
},
onLoad(options) {
let that = this
that.typeInfo = 0
that.height = that.userInfo.height
that.head = that.userInfo.head_data
that.deviceId = options.deviceId
that.$ble.createBLEConnection("FFF0")
that.$ble.onBLEConnectionStateChange()
},
watch: {
'bleValue.isBluetoothTyle'() {
let that = this
if (!that.bleValue.isBluetoothTyle) {
that.$tools.showModal('蓝牙连接已断开,请重新连接后测量')
setTimeout(function() {
uni.switchTab({
url: "/pages/index/index"
})
}, 1000)
}
},
'bleValue.serviceId'() {
let that = this
if (that.bleValue.serviceId) {
that.serviceId = that.bleValue.serviceId
that.getBLEDeviceCharacteristics(that.bleValue.serviceId)
}
},
isFinished: function() {
let that = this
console.log("是否开启弹框", that.weight, that.isFinished, that.typeInfo)
if (!that.isFinished) {
that.isHeight = false
return
}
if (that.isFinished && that.typeInfo == 2) {
setTimeout(function() {
that.isHeight = true
}, 1500)
}
}
},
methods: {
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics(serviceId) {
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: serviceId,
success: res => {
// * read: true, //,write: true, //,notify: true
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF1') != -1) {
that.notify = item.uuid
} else if (item.uuid.indexOf('0000FFF2') != -1) {
that.write = item.uuid
that.writeBLECharacteristicValue("A6020500076A") //
}
}
that.$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 2,
bleTipsText: "蓝牙连接成功,请上秤测量",
})
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: serviceId,
characteristicId: that.notify,
state: true,
})
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: serviceId,
characteristicId: that.write,
state: true,
})
that.isFinished = false
setTimeout(function() {
that.notifyBLECharacteristicValue(serviceId)
}, 800)
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
/**
* 开启订阅特征值
* read: true, //,write: true, //,notify: true, //广
*/
notifyBLECharacteristicValue(serviceId) {
let that = this;
uni.notifyBLECharacteristicValueChange({
state: true, // notify
deviceId: that.deviceId,
serviceId: serviceId,
characteristicId: that.notify,
success(res) {
that.isSave = true
uni.onBLECharacteristicValueChange(function(res) {
let value = that.$tools.ab2hex(res.value, "");
let type = value.substring(4, 6) //
let typeInfo = value.substring(6, 8) //
let weight = parseInt(value.substring(8, 14), 16) //
let digit = value.substring(18, 19) //
let unit = value.substring(19, 20) //
let weight1 = ""
let weight2 = ""
//
if (digit == "0") {
weight = weight
}
if (digit == "1") {
weight = weight / 10
}
if (digit == '2') {
weight = weight / 100
}
if (digit == "3") {
weight = weight / 1000
}
//
if (unit == "0") {
that.unit = "kg"
}
if (unit == "1") {
that.unit = "斤"
}
if (unit == "2") {
console.log("st:lb", weight)
weight1 = Math.floor(weight / 14)
weight2 = weight - weight1 * 14
weight = weight1 + ":" + weight2.toFixed(2)
that.unit = "st:lb"
}
if (unit == "3") {
that.unit = "lb"
}
if (unit == "4") {
that.unit = "g"
}
//
if (typeInfo == "01") {
that.typeInfo = 1
that.weight = weight
that.IsLing = false
that.isHeight = false
that.isFinished = false
}
//
if (typeInfo == "02" && !that.isFinished) {
that.typeInfo = 2
that.weight = weight
if (weight > 0 || toString(weight) != '0:0.00') {
that.isFinished = true
}
}
console.log("状态:", value, type, typeInfo, weight, that.unit, that.isFinished)
});
},
fail(res) {
console.log("测量失败", res.value);
}
});
},
//
handleIsLing() {
let that = this
if (!that.IsLing) {
that.writeBLECharacteristicValue("A6020500076A")
that.IsLing = true
}
},
//
handleIsNum() {
let that = this
that.writeBLECharacteristicValue("A6020400066A")
},
writeBLECharacteristicValue(str) {
var that = this;
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
return parseInt(h, 16)
}))
console.log("buffer", str, buf)
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.write,
value: buf.buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
},
fail: res => {
console.log("下发指令失败", res);
},
})
},
//
handleGetMeasure() {
let that = this
if (!that.height) {
this.$tools.msg("请输入身高")
return
}
that.$model.getmeasurefunit({
weight: that.weight + that.unit,
height: that.height,
aud_id: that.userInfo.aud_id,
head_data: that.head ? that.head : 0,
lefthand: 0,
righthand: 0,
leftfoot: 0,
rightfoot: 0,
heart_rate: 0,
}).then(res => {
that.isHeight = false
that.isSave = false
if (res.code == 0) {
that.$store.dispatch('getUserInfo', {
aud_id: that.user.aud_id
})
that.$store.dispatch("getResult", {
aud_id: that.user.aud_id
})
that.$tools.msg("测量成功")
} else {
that.$tools.msg("测量失败")
}
uni.switchTab({
url: "/pages/index/index"
})
})
},
//
handleBack() {
let that = this
let str = "A6020500076A"
let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
return parseInt(h, 16)
}))
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.write,
value: buf.buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
uni.showToast({
title: '数据重置中',
icon: "none"
})
console.log("重置", that.typeInfo, that.weight)
},
fail: res => {
console.log("下发指令失败", res);
},
})
},
},
}
</script>
<style scoped lang="scss">
.content {
background: #fff;
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.btnClose {
color: #fff;
background: linear-gradient(-90deg, #fccf4f, #fba418 80%) !important;
}
.baocun {
color: #fff;
background: linear-gradient(-90deg, #feaa50, #e96b13 80%) !important;
}
.quan {
width: 460rpx;
height: 460rpx;
border: 8px solid #feaa50;
border-radius: 50%;
margin: 15px auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
box-shadow: 0px 0px 25px 10px #e96b13;
animation: pulse 1s infinite;
.weight {
font-size: 50px;
color: #000;
font-weight: bold;
}
.typeInfo {
width: 100%;
text-align: center;
font-size: 16px;
color: #f0ae43;
}
}
@keyframes pulse {
0% {
box-shadow: 0px 0px 25px 10px #e96b13;
}
50% {
box-shadow: 0px 0px 25px 10px #fba418;
}
100% {
box-shadow: 0px 0px 25px 10px #e96b13;
}
}
.status {
width: 70%;
font-size: 16px;
height: 35px;
line-height: 35px;
text-align: center;
border-radius: 15px;
margin: 15px auto;
background-color: #ffdda6;
}
.disabled {
width: 150px;
background-color: #DFDFDF;
border: 1px solid #f7f7f7;
color: #fff;
text-align: center;
padding: 7px;
border-radius: 10px;
margin: 15px auto;
}
.tips {
font-size: 14px !important;
margin-bottom: 20px;
}
</style>

View File

@ -36,7 +36,6 @@
height: 70px;
line-height: 70px;
background: $btncolor;
margin-left: calc(50% - 35px);
border-radius: 50px;
text-align: center;
box-shadow: 0px 1px 5px 2px #dfe2e1fc;

View File

@ -3,9 +3,9 @@
<!-- -->
<view class="skiptop">
<view class="status" @click="handleisSdevice()">
<text>{{textLink}}</text>
<image v-if="islink!=1" :class="[islink==-1?'':'icon_link']" src="../../static/zhuan.png"></image>
<image v-if="islink==1" src="../../static/dui.png"></image>
<text>{{bleTipsText}}</text>
<image v-if="islink!=2" :class="[islink==1?'':'icon_link']" src="../../static/zhuan.png"></image>
<image v-if="islink==2" src="../../static/dui.png"></image>
</view>
<view class="item">
<view class="item-ite">今日个数<text>{{info?info.today_jump_num:'--'}}</text></view>
@ -25,7 +25,7 @@
<text class="item-set item-set0">自由</text>
<text class="tips">无限制</text>
</view>
<view :class="[islink==1?'start':'start Nstart']" @click="handleStart(1)">开始</view>
<view :class="[islink==2?'start':'start Nstart']" @click="handleStart(1)">开始</view>
</view>
<!--定时训练 -->
<view class="box1 box" v-if="active==2">
@ -69,29 +69,33 @@
data() {
return {
active: 1,
acd_id: 6,
weight: 50,
disabled: false,
isDevice: 0,
isConnection: false,
time_m: "",
time_s: "",
timeList: [],
devicesList: [],
timesTndex: [1, 0],
deviceId: "",
serviceId: "",
write: "",
notify: "",
islink: 0, //01-1
textLink: ""
}
},
computed: {
...mapState(['user', "MeasureSkip", "isConnected", "isBluetoothTyle"]),
...mapState(['user', "MeasureSkip", "bleValue"]),
info() {
return this.MeasureSkip
},
bleTipsText() {
return this.bleValue.bleTipsText
},
isConnection() {
return this.bleValue.isBluetoothTyle
},
islink() {
return this.bleValue.isConnectStatus
}
},
mounted() {
let that = this
@ -101,27 +105,11 @@
},
onLoad(options) {
let that = this
//
if (options && options.deviceId) {
that.deviceId = options.deviceId
setTimeout(function() {
that.createBLEConnection()
}, 500)
}
if (options && options.acd_id) {
that.$Bluetooth.stopBluetoothDevicesDiscovery()
setTimeout(function() {
that.handleisSdevice()
}, 500)
}
that.deviceId = options.deviceId
that.$store.dispatch("getSkipResult", {
aud_id: that.user.aud_id
})
that.isConnection = that.isConnected
that.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetooth", res.available);
})
that.$ble.onBLEConnectionStateChange()
},
onPullDownRefresh() {
setTimeout(() => {
@ -133,180 +121,66 @@
//
uni.$on('updateData', function(info) {
let data = JSON.parse(info)
that.acd_id = data.acd_id
that.isDevice = data.device
that.active = data.active
that.deviceId = data.deviceId
that.serviceId = data.serviceId
that.write = data.write
that.notify = data.notify
that.islink = !that.isConnected ? -1 : 1
that.isConnection = that.isConnected
that.notifyBLECharacteristicValue()
if (data.isSuccessful) {
that.$store.dispatch("getSkipResult", {
aud_id: that.user.aud_id
})
}
that.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetooth", res.available);
})
that.$ble.onBLEConnectionStateChange()
console.log('监听到事件来自 updateData', data);
})
},
onUnload: function() {
let that = this
clearTimeout(myTime);
that.islink = -1
that.isConnection = false
that.closeBLEConnection()
that.closeBluetoothAdapter()
that.$ble.closeBLEConnection()
that.$ble.closeBluetoothAdapter()
uni.$off("updateData")
setTimeout(() => {
uni.switchTab({
url: '/pages/home/home'
})
}, 300)
console.log("返回首页onUnload")
},
watch: {
isConnected() {
let that = this
if (!that.isConnected) {
that.islink = -1
that.textLink = "重新连接"
}
that.isConnection = that.isConnected
console.log("蓝牙是否连接", that.isConnected)
bleValue: {
handler(newVal, oldVal) {
let that = this
if (newVal.serviceId) {
that.deviceId = newVal.deviceId
that.serviceId = newVal.serviceId
that.getBLEDeviceCharacteristics()
}
if (!newVal.isBluetoothTyle) {
that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接失败,点击重新连接",
isConnectStatus: 1,
})
}
},
deep: true,
immediate: true
},
isBluetoothTyle() {
let that = this
if (!that.isBluetoothTyle) {
that.isConnection = false
that.textLink = "请打开手机蓝牙"
that.islink = -1
}
console.log("蓝牙是否打开", that.isBluetoothTyle)
}
},
methods: {
//
handleisSdevice() {
let that = this
if (that.isConnected) return
that.devicesList = []
that.$Bluetooth.stopBluetoothDevicesDiscovery()
uni.openBluetoothAdapter({
success: e => {
that.islink = 0
that.handleMyTime()
that.textLink = "蓝牙搜索中"
that.startBluetoothDeviceDiscovery()
that.$store.commit("changeBluetooth", true)
console.log('初始化蓝牙成功:' + e.errMsg);
},
fail: e => {
that.islink = -1
that.textLink = that.$tools.getBluetoothAdapter(e)
return
}
});
},
//
startBluetoothDeviceDiscovery() {
let that = this
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
interval: 200, //
services: [],
success: res => {
that.onBluetoothDeviceFound();
},
fail: res => {}
});
},
/**
* 发现外围设备
*/
onBluetoothDeviceFound() {
var that = this;
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
if (!device.name && !device.localName) {
return
}
if (device.name.indexOf('YPC') != -1) {
device.deviceId = device.deviceId
that.deviceId = device.deviceId
that.$Bluetooth.stopBluetoothDevicesDiscovery()
that.handleDevice(device)
return
}
})
});
that.handleMyTime()
},
handleDevice(device) {
let that = this
const foundDevices = that.devicesList
const idx = that.$tools.inArray(foundDevices, "deviceId", device.deviceId)
if (idx === -1) {
that.devicesList.push(device);
that.createBLEConnection()
}
},
//
createBLEConnection() {
let that = this;
uni.createBLEConnection({
deviceId: that.deviceId,
success: res => {
that.textLink = "蓝牙连接中"
setTimeout(function() {
that.islink = 1
that.getBLEDeviceServices()
}, 1000)
},
fail: res => {
that.textLink = "重新连接"
console.log("设备连接失败,请重新连接", res, that.deviceId);
}
});
},
/**
* 获取设备的UUID
*/
getBLEDeviceServices() {
let serviceList = [];
let that = this;
uni.getBLEDeviceServices({
deviceId: that.deviceId,
success: res => {
console.log("获取设备的UUID成功", res)
serviceList = res.services;
for (let i = 0; i < serviceList.length; i++) {
let service = serviceList[i];
if (service.uuid.indexOf("FFE0") != -1) {
that.serviceId = service.uuid;
that.isConnection = true
that.textLink = "连接成功"
that.getBLEDeviceCharacteristics();
console.log("设备的FFE0的serviceId " + that.serviceId);
break;
}
}
},
fail: res => {
console.log('获取设备的UUID失败:', res)
that.islink = -1
that.textLink = "重新连接"
clearTimeout(myTime);
that.isConnection = false
}
});
if (that.islink == 2) return
that.$store.commit('changeBluetoothValue', {
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0,
isBleLink: false,
deviceId: "",
serviceId: "",
})
that.$ble.openBluetoothAdapter()
},
/**
* 获取指定服务的特征值
*/
@ -364,6 +238,14 @@
serviceId: that.serviceId,
characteristicId: that.notify,
success(res) {
that.$store.commit('changeBluetoothValue', {
deviceId: that.deviceId,
serviceId: that.serviceId,
foodNotify: that.notify,
foodWrite: that.write,
bleTipsText: "连接成功",
isConnectStatus: 2
})
uni.onBLECharacteristicValueChange(function(res) {
let value = that.$tools.ab2hex(res.value, "");
if (value == '5a05090169') { //
@ -373,15 +255,13 @@
serviceId: that.serviceId,
notify: that.notify,
write: that.write,
acd_id: that.acd_id,
isDevice: that.isDevice,
isSuccessful: false
}
setTimeout(function() {
uni.$off("updateData")
uni.navigateTo({
url: "/pageTwo/devices/PCT01?info=" + JSON
.stringify(info)
url: "/pageTwo/devices/PCT01?info=" + JSON.stringify(info)
})
}, 200)
}
@ -415,7 +295,7 @@
let that = this
let m = null
let send = null
if (!that.isConnected) {
if (!that.bleValue.isBluetoothTyle) {
that.$tools.msg("请先连接设备!")
return
}
@ -441,16 +321,7 @@
send = "A50508" + Number(num).toString(16) + m.substr(m.length - 2, 2)
}
that.SendData(send)
that.$Bluetooth.stopBluetoothDevicesDiscovery()
},
//
reload() {
let that = this
this.$nextTick(() => {
that.$store.dispatch("getSkipResult", {
aud_id: that.user.aud_id
})
})
that.$ble.stopBluetoothDevicesDiscovery()
},
//
//
@ -507,51 +378,6 @@
that.weight = Number(that.weight) + 50
}
},
//
handleMyTime() {
let that = this
myTime = setTimeout(function() {
if (!that.devicesList.length) {
that.islink = -1
that.textLink = "重新搜索"
that.$tools.showModal("没有查找到设备")
}
clearTimeout(myTime)
that.$Bluetooth.stopBluetoothDevicesDiscovery()
}, 20000);
},
//
onBLEConnectionStateChange() {
let that = this
uni.onBLEConnectionStateChange(function(res) {
console.log("监听蓝牙连接状态", res.connected)
that.$store.commit("changeConnected", res.connected);
})
},
/**
* 断开蓝牙模块
*/
closeBluetoothAdapter() {
let that = this;
uni.closeBluetoothAdapter({
success: res => {
console.log('蓝牙模块关闭成功');
}
})
},
/**
* 断开蓝牙连接
*/
closeBLEConnection() {
var that = this;
uni.closeBLEConnection({
deviceId: that.deviceId,
success: res => {
console.log('断开蓝牙连接成功');
that.$store.commit("changeConnected", false);
}
});
},
}
}
</script>

View File

@ -318,6 +318,12 @@
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "devices/pcL06",
"style": {
"navigationBarTitleText": ""
}
}
]
}

View File

@ -22,7 +22,7 @@
</view>
</view>
<!-- 蓝牙 -->
<view class="bluetooth" v-if="userList.length">
<view class="bluetooth" v-if="userList.length" :class="[bleValue.isConnectStatus==1?'activs':'']">
<view class="bleTips" @click="openBluetoothAdapter">
{{bleTipsText}}
</view>
@ -37,9 +37,9 @@
<!-- 数据 -->
<view class="toggle">
<view :class="{'active':toolsIndex==0}" class="toolsItem" @click="toolsIndex=0">身体数据</view>
<view :class="{'active':toolsIndex==1}" class="toolsItem" @click="toolsIndex=1">饮食数据</view>
<view :class="{'active':toolsIndex==2}" class="toolsItem" @click="toolsIndex=2">健康工具</view>
<view :class="{'active':toolsIndex==0}" class="toolsItem" @click="handleToolsIndex(0)">身体数据</view>
<view :class="{'active':toolsIndex==1}" class="toolsItem" @click="handleToolsIndex(1)">饮食数据</view>
<view :class="{'active':toolsIndex==2}" class="toolsItem" @click="handleToolsIndex(2)">健康工具</view>
</view>
<view v-if="token">
<body v-if="toolsIndex==0"></body>
@ -51,7 +51,7 @@
<text>暂无数据</text>
</view>
<!-- -->
<drawer></drawer>
<drawer @handleToolsIndex="handleToolsIndex(0)"></drawer>
</view>
</template>
@ -67,7 +67,7 @@
data() {
return {
token: "",
toolsIndex: 0
// toolsIndex: 0
}
},
components: {
@ -77,7 +77,7 @@
drawer,
},
computed: {
...mapState(["user", "familayList", 'MeasureResult', "configInfo", "bleValue"]),
...mapState(["user", "familayList", 'MeasureResult', "configInfo", "bleValue", "homeCardIndex"]),
info() {
return this.user
},
@ -92,6 +92,9 @@
},
bleTipsText() {
return this.bleValue.bleTipsText
},
toolsIndex(){
return this.homeCardIndex
}
},
onLoad() {
@ -113,12 +116,25 @@
uni.stopPullDownRefresh()
},
watch: {
isBluetoothTyle: function() {
'bleValue.isBluetoothTyle'() {
let that = this
if (!that.isBluetoothTyle) {
if (!that.bleValue.isBluetoothTyle) {
that.handleBack()
}
},
'bleValue.isFood'() {
let that = this
if (that.bleValue.isFood) {
that.$store.commit("changehomeCard", 1);
}
},
// homeCardIndex: {
// handler(newVal, oldVal) {
// this.toolsIndex = newVal
// },
// deep: true,
// immediate: true
// }
},
methods: {
//
@ -165,7 +181,9 @@
aud_id: userid
})
that.handlePublicRecord(userid)
that.$ble.openBluetoothAdapter()
if (that.bleValue.isConnectStatus != 2) {
that.$ble.openBluetoothAdapter()
}
}
}).catch(err => {})
},
@ -184,17 +202,17 @@
//
openBluetoothAdapter() {
let that = this
if (that.isConnection == 2) return
if (that.isConnection != 1) return
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
// notify: '',
// write: '',
// unit: "g",
// type: 1,
// unitList: that.$json.unitMinus,
// countWeight: "",
isBleLink: false, //
isFood: false,
foodWeight: 100,
foodUnit: "g",
foodNotify: "",
foodWrite: "",
unitList: that.$json.unitMinus,
foodType: 1,
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0,
})
@ -222,9 +240,12 @@
that.$tools("登录后查看更多")
}
},
handleToolsIndex(ind) {
this.$store.commit("changehomeCard", ind);
},
handleLogin() {
uni.redirectTo({
url: "/pageTwo/login/login"
url: "/body/login/login"
})
},
}
@ -232,6 +253,10 @@
</script>
<style lang="scss" scoped>
.activs {
background: #ffc800 !important;
}
.header {
width: 100%;
height: 240rpx;

View File

@ -668,6 +668,7 @@
font-size: 32rpx;
padding: 20px 10px 5px;
color: #fff;
width: calc(100% - 50px);
.status {
float: right;

View File

@ -64,7 +64,7 @@
width: 250rpx;
height: 250rpx;
margin-top: -30rpx;
margin-left: -5px;
margin-left: 5px;
display: flex;
flex-wrap: wrap;

BIN
static/lianjie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
static/qie.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

View File

@ -47,19 +47,16 @@ export default new Vuex.Store({
bleValue: {
deviceId: "",
serviceId: "",
isBleLink: false,
isFood: false,
foodWeight: 100,
foodUnit: "g",
foodNotify: "",
foodWrite: "",
foodunitList: json.unitArray,
foodType: 1, //食物称 1实时2锁定 状态类型
bleTipsText: "", //蓝牙提示语
isConnectStatus: 0, //蓝牙连接状态 0搜索中1失败2成功
isBluetoothTyle: false, //蓝牙状态
// notify: "",
// write: "",
// unit: "g",
// type: 1,
// unitList: json.unitArray,
// isSendVal: false,
// oldCountWeight: 0,
// countWeight: 100,
},
// 计食器
countFoodInfo: {
@ -113,6 +110,7 @@ export default new Vuex.Store({
chosen_yes: [],
chosen_no: []
},
homeCardIndex: 0,
isDrawe: false, //左侧弹框
isTarget: false, //目标体重
isFirst: false, //初始体重
@ -128,6 +126,10 @@ export default new Vuex.Store({
changeUser(state, newData) {
Object.assign(state.user, newData)
},
// 首页卡片当前项
changehomeCard(state, newData) {
state.homeCardIndex = newData
},
//获取家庭成员
changeFamilay(state, newData) {
if (newData.length == 0) {

View File

@ -2,32 +2,38 @@ import $store from '@/store'
import useBluetooth from '@/toolJs/Bluetooth.js'
import $tools from '@/toolJs/tools.js'
import $data from '@/content.json'
import $model from '@/toolJs/model.js'
// // 蓝牙连接
let deviceId = ""
let deviceName = ""
let devicesList = []
let searchTimer = null
export default {
unitInstruction,
convertToGrams,
unitConversion,
openBluetoothAdapter,
startBluetoothDeviceDiscovery,
onBluetoothDeviceFound,
Bluetoothfilter,
createBLEConnection,
getBLEDeviceServices,
getBLEDeviceCharacteristics,
closeBluetoothAdapter,
closeBLEConnection,
getBLECharacteristicValueChange,
onBLEConnectionStateChange,
stopBluetoothDevicesDiscovery
}
// // 初始化蓝牙
function openBluetoothAdapter() {
devicesList = []
deviceId = ""
deviceName = ""
clearTimeout(searchTimer);
uni.openBluetoothAdapter({
success: e => {
$store.commit("changeBluetoothValue", {
bleTipsText: "蓝牙搜索中",
unitList: $data.unitMinus,
isConnectStatus: 0,
isBleLink: false,
deviceId: "",
@ -38,6 +44,7 @@ function openBluetoothAdapter() {
fail: err => {
$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
unitList: $data.unitMinus,
isConnectStatus: 1,
isBleLink: false,
deviceId: "",
@ -52,6 +59,7 @@ function startBluetoothDeviceDiscovery() {
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
interval: 200, //上报设备的间隔
services: [],
success: res => {
onBluetoothDeviceFound();
searchTimer = setTimeout(() => {
@ -87,11 +95,12 @@ function onBluetoothDeviceFound() {
let id = value.substring(12, 16)
if (type.toLowerCase() == 'c0') {
clearTimeout(searchTimer);
device.deviceName = "c00002"
device.name = "c00002"
Bluetoothfilter(device)
}
return
}
console.log("device.name", device.name)
if (device.name.toLowerCase().indexOf('pc-c06pro') != -1 ||
device.name.toLowerCase().indexOf('pc-c02pro') != -1 ||
device.name.toLowerCase().indexOf('pc-c09pro') != -1 ||
@ -103,16 +112,20 @@ function onBluetoothDeviceFound() {
(device.localName && device.localName.toLowerCase().indexOf('pc-c02pro') != -1) ||
(device.localName && device.localName.toLowerCase().indexOf('pc-c09pro') != -1)) {
clearTimeout(searchTimer);
const bytes = new Uint8Array(device.advertisData);
const macBytes = bytes.slice(6, 12);
device.macAddr = $tools.ab2hex(macBytes, ':').toUpperCase()
stopBluetoothDevicesDiscovery()
Bluetoothfilter(device)
return
}
if (device.name.toLowerCase().indexOf("g02") != -1 ||
device.name.toLowerCase().indexOf('ypc') != -1 ||
device.name.toLowerCase().indexOf('pc-x01') != -1 ||
device.name.toLowerCase().indexOf('da') != -1 ||
device.name.toLowerCase().indexOf('pcl') != -1 ||
device.name.toLowerCase().indexOf('aiLink_') != -1 ||
device.name.toLowerCase().indexOf('pcf01') != -1 ||
device.name.toLowerCase().indexOf('chipsea_ble') != -1 ||
device.name.toLowerCase().indexOf('Yihejia_Lung') != -1) {
clearTimeout(searchTimer);
stopBluetoothDevicesDiscovery()
@ -152,30 +165,27 @@ function Bluetoothfilter(device) {
}
// 身高仪
if (device.name.indexOf("G02") != -1) {
uni.navigateTo({
url: "/pageTwo/devices/G02?deviceId=" + device.deviceId
})
deviceName = 'G02'
createBLEConnection("FFF0")
return
}
// 跳绳
if (device.name.indexOf("YPC") != -1) {
uni.navigateTo({
url: "/pages/skiping/skip?deviceId=" + device.deviceId
})
deviceName = 'YPC'
createBLEConnection("FFE0")
return
}
// 婴儿秤
if (device.name.indexOf("Chipsea_BLE") != -1) {
uni.navigateTo({
url: "/pageTwo/devices/B20?deviceId=" + device.deviceId
})
deviceName = 'Chipsea_BLE'
createBLEConnection("FFF0")
return
}
// 心率秤
if (device.name.toLowerCase().indexOf('pc-x01') != -1) {
uni.navigateTo({
url: "/pageTwo/devices/PCX01?deviceId=" + device.deviceId
})
// 八电极
if (device.name.toLowerCase().indexOf('aiLink_') != -1) {
deviceName = 'aiLink'
createBLEConnection("FFE0")
return
}
//厨房秤
@ -189,7 +199,8 @@ function Bluetoothfilter(device) {
(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)) {
handleDevType(device)
deviceName = 'CFC'
createBLEConnection("FFF0")
return
}
}
@ -201,12 +212,13 @@ function handleDevType(device) {
}).then(res => {
console.log("排查设备:", device, res)
if (res.code == 0) {
createBLEConnection(device.deviceId)
createBLEConnection("FFF0")
} else {
devicesList = []
$tools.msg('设备未登记,请联系出售方进行系统认证')
$store.commit("changeBluetoothValue", {
type: 1,
foodType: 1,
isFood: false,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
@ -224,7 +236,7 @@ function createBLEConnection(serviceId) {
},
fail: res => {
$store.commit("changeBluetoothValue", {
type: 1,
foodType: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
@ -241,16 +253,39 @@ function getBLEDeviceServices(serviceId) {
success: res => {
console.log("获取设备的UUID成功", res)
stopBluetoothDevicesDiscovery();
if (deviceName == 'CFC') { //厨房秤
$store.commit("changeBluetoothValue", {
isFood: true,
})
} else if (deviceName == 'YPC') {
uni.navigateTo({
url: "/pageTwo/skiping/skip?deviceId=" + deviceId
})
} else if (deviceName == 'aiLink') {
uni.navigateTo({
url: "/pageTwo/devices/pcL06?deviceId=" + deviceId
})
} else if (deviceName == 'Chipsea_BLE') {
uni.navigateTo({
url: "/pageTwo/devices/B20?deviceId=" + deviceId
})
}else if (deviceName == 'G02') {
uni.navigateTo({
url: "/pageTwo/devices/G02?deviceId=" + deviceId
})
}
serviceList = res.services;
for (let i = 0; i < serviceList.length; i++) {
let service = serviceList[i];
if (service.uuid.indexOf(serviceId) != -1) {
$store.commit("changeBluetoothValue", {
type: 1,
foodType: 1,
isConnectStatus: 0,
deviceId: deviceId,
serviceId: service.uuid,
bleTipsText: "蓝牙链接中",
bleTipsText: "蓝牙接中",
})
break;
}
@ -258,7 +293,7 @@ function getBLEDeviceServices(serviceId) {
},
fail: res => {
$store.commit("changeBluetoothValue", {
type: 1,
foodType: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
@ -267,154 +302,6 @@ function getBLEDeviceServices(serviceId) {
});
}
/**
* 获取指定服务的特征值
*/
function getBLEDeviceCharacteristics(deviceId, serviceId) {
let characteristicsList = [];
uni.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId,
success: res => {
let write, notify
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
write = item.uuid
} else if (item.uuid.indexOf('0000FFF1') != -1) {
notify = item.uuid
}
}
getBLECharacteristicValueChange(deviceId, serviceId, notify, write)
},
fail: res => {
$store.commit("changeBluetoothValue", {
type: 1,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
})
console.log('获取特征值失败:', JSON.stringify(res))
}
})
}
function getBLECharacteristicValueChange(deviceId, serviceId, notify, write) {
let that = this
uni.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: notify,
state: true,
success: () => {
$store.commit('changeBluetoothValue', {
deviceId: deviceId,
serviceId: serviceId,
notify: notify,
write: write,
unit: "g",
type: 1,
countWeight: "",
bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 2
})
uni.onBLECharacteristicValueChange(function(res) {
const value = res.value
const dataView = new DataView(value)
const header = dataView.getUint8(0)
// MCU主动上报数据
if (header === 0xC7) {
const cmd = dataView.getUint8(2)
switch (cmd) {
case 0x02:
const statusByte = dataView.getUint8(4)
const isNegative = !!(statusByte & 0x80) // 最高位表示正负
const statusType = statusByte & 0x0F // 状态类型
// 组合24位重量值 (大端序)
const weightValue =
(dataView.getUint8(5) << 16) |
(dataView.getUint8(6) << 8) |
dataView.getUint8(7)
// 精度和单位
const unitByte = dataView.getUint8(8)
const precision = (unitByte & 0xF0) >> 4 // 高4位精度
const unitIndex = unitByte & 0x0F // 低4位单位
// 计算实际重量
let finalWeight = weightValue / Math.pow(10, precision)
console.log("类型:", cmd, "重量",
finalWeight, "小数点", precision, "单位", UNIT_MAP[unitIndex])
if (isNegative) finalWeight = -finalWeight
$store.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: UNIT_MAP[unitIndex],
type: statusType
})
break
case 0x03:
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
}
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
}
// 获取服务
// function getBLEDeviceServices(uuid) {
// let serviceList = [];
// let serviceId = ""
// uni.getBLEDeviceServices({
// deviceId: deviceId,
// success: res => {
// console.log("获取设备的UUID成功", res)
// serviceList = res.services;
// for (let i = 0; i < serviceList.length; i++) {
// let service = serviceList[i];
// if (service.uuid.indexOf(uuid) != -1) {
// serviceId = service.uuid
// break;
// }
// }
// $store.commit("getIsUseBluetooth", {
// serviceId: serviceId
// });
// },
// fail: res => {
// console.log('获取设备的UUID失败:', res)
// }
// });
// }
/**
* 断开蓝牙模块
*/
@ -425,11 +312,11 @@ function closeBluetoothAdapter() {
$store.commit("changeBluetoothValue", {
deviceId: "",
serviceId: "",
notify: "",
write: "",
unit: "g",
countWeight: '',
type: 1,
foodUnit: "g",
foodNotify: "",
foodWrite: "",
foodType: 1,
foodWeight: 100,
unitList: $data.unitMinus,
isConnectStatus: 1,
bleTipsText: "连接超时,点击重新连接",
@ -441,7 +328,7 @@ function closeBluetoothAdapter() {
/**
* 断开蓝牙连接
*/
function closeBLEConnection(deviceId) {
function closeBLEConnection() {
uni.closeBLEConnection({
deviceId: deviceId,
success: res => {
@ -458,7 +345,10 @@ function onBLEConnectionStateChange() {
bleTipsText: "连接超时,点击重新连接",
unitList: $data.unitMinus,
isConnectStatus: 1,
type: 1,
foodUnit: "g",
foodNotify: "",
foodWrite: "",
foodType: 1,
})
closeBLEConnection()
closeBluetoothAdapter()
@ -479,6 +369,78 @@ function stopBluetoothDevicesDiscovery() {
});
}
function unitConversion(unit) {
if (unit == 'kg') {
return '千克'
} else if (unit == '斤') {
return '斤'
} else if (unit == 'stlb') {
return 'stlb'
} else if (unit == 'lb') {
return '磅'
} else if (unit == 'g') {
return '克'
} else if (unit == 'ml') {
return '毫升'
} else if (unit == 'Waterml') {
return 'Waterml'
} else if (unit == 'milkml') {
return 'milkml'
} else if (unit == 'oz') {
return '盎司'
} else if (unit == 'floz') {
return 'floz'
} else if (unit == 'lboz') {
return 'lboz'
}
return unit
}
function 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
};
if (!conversionFactors.hasOwnProperty(fromUnit)) {
return ''
}
return value * conversionFactors[fromUnit];
}
function unitInstruction(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
}
function parseUnitMask(hexValue, UNIT_MAP) {
// 转换为数字
const mask = typeof hexValue === 'string' ? parseInt(hexValue, 16) : hexValue;

View File

@ -16,7 +16,7 @@ const httpRequest = (url, method = "get", data) => {
uni.request(httpDefaultOpts).then(
(res) => {
uni.hideLoading()
console.log("request", url, res,)
// console.log("request", url, res,)
if (res[1].data.code == 20001) {
uni.clearStorageSync()
uni.setStorageSync('token', null)

View File

@ -19,7 +19,31 @@ export default {
validatePhoneEmail,
checkPrivacyAgreement,
mergeAndDeduplicate,
handleCancelUpdate
handleCancelUpdate,
parseUnitMask
}
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;
}
function NewsPtype(con) {

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

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

@ -0,0 +1 @@
{"version":3,"sources":["uni-app:///main.js"],"names":["wx","__webpack_require_UNI_MP_PLUGIN__","__webpack_require__","createPage","Page"],"mappings":";;;;;;;;;;;;;AAAA;AAGA;AACA;AAHA;AACAA,EAAE,CAACC,iCAAiC,GAAGC,mBAAmB;AAG1DC,UAAU,CAACC,YAAI,CAAC,C","file":"pageTwo/pcL06/pcL06.js","sourcesContent":["import 'uni-pages';\n// @ts-ignore\nwx.__webpack_require_UNI_MP_PLUGIN__ = __webpack_require__;\nimport Vue from 'vue'\nimport Page from './pageTwo/pcL06/pcL06.vue'\ncreatePage(Page)"],"sourceRoot":""}

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

Some files were not shown because too many files have changed in this diff Show More