ReedawFoodApp/pageTwo/devices/PCL22.vue

191 lines
4.8 KiB
Vue
Raw Normal View History

2025-05-30 11:14:38 +08:00
<template>
<view class="weightPages">
<view class="content ">
<view class="title">连接成功开始测量</view>
<view class="text">{{text}}</view>
<view class="image">
<image src="/pageTwo/static/PCL.gif" class="image3"></image>
</view>
<view class="tips">
<view>提示</view>
<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>{{weight}}{{unit}}</text>
</view>
<view class="Blue-box">
上次测量身高为<input v-model="height" type="digit" placeholder="请输入身高" />cm
</view>
<view class="Blue-btn Blue-close" @click="handleBack">取消</view>
<view class="Blue-btn" @click="handleGetMeasure">保存测量结果</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
let myTime;
export default {
data() {
return {
text: "",
imp: "",
weight: "",
height: "",
deviceId: "",
unit: "kg",
isHeight: false,
stopblue: false,
typeInfo: -1
}
},
computed: {
...mapState(["user"]),
info() {
return this.user
},
},
onUnload: function() {
let that = this
2026-03-23 09:50:49 +08:00
that.useBluetooth.clearBluetoothStatus()
2025-05-30 11:14:38 +08:00
},
onLoad(options) {
let that = this
that.text = ""
that.typeInfo = -1
that.deviceId = options.deviceId
that.height = that.user.height
2026-03-23 09:50:49 +08:00
uni.onBluetoothDeviceFound(handleDeviceFound)
2025-05-30 11:14:38 +08:00
},
watch: {
stopblue: function() {
let that = this
if (!that.stopblue) {
that.isHeight = false
return
}
if (that.stopblue && that.typeInfo == 1) {
that.isHeight = true
}
}
},
methods: {
/**
* 发现外围设备
*/
2026-03-23 09:50:49 +08:00
onBluetoothDeviceFound(res) {
2025-05-30 11:14:38 +08:00
var that = this;
2026-03-23 09:50:49 +08:00
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) //类型 0体重1体脂
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") {
2025-05-30 11:14:38 +08:00
if (unit == "10") {
that.unit = "lb"
weight = weight / 10
2026-03-23 09:50:49 +08:00
} else {
weight = weight / 100
2025-05-30 11:14:38 +08:00
}
2026-03-23 09:50:49 +08:00
}
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
2025-05-30 11:14:38 +08:00
}
2026-03-23 09:50:49 +08:00
that.typeInfo = 1
that.text = "您的稳定体重是:" + weight + that.unit
that.weight = weight
that.stopblue = true
that.useBluetooth.stopSearchBluetooth() //取消蓝牙搜索
console.log("测量完成", that.weight)
2025-05-30 11:14:38 +08:00
}
2026-03-23 09:50:49 +08:00
return;
2025-05-30 11:14:38 +08:00
}
2026-03-23 09:50:49 +08:00
})
2025-05-30 11:14:38 +08:00
},
// 保存测量结果
handleGetMeasure() {
let that = this
if (!that.height) {
this.$tools.msg("请输入身高")
return
}
that.$model.getmeasurefunit({
adc: that.imp,
weight: that.weight + that.unit,
height: that.height,
aud_id: that.info.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')
})
that.$store.dispatch("getResult", {
aud_id: uni.getStorageSync('userid')
})
that.$tools.msg("测量成功")
} else {
that.$tools.msg("测量失败")
}
setTimeout(function() {
uni.switchTab({
2026-03-23 09:50:49 +08:00
url: "/pages/body/body"
2025-05-30 11:14:38 +08:00
})
}, 200)
})
},
//
handleBack() {
let that = this
that.text = ""
2026-03-23 09:50:49 +08:00
that.$store.commit("getIsUseBluetooth", {
isBleLink: true,
BleBodyMsg: "开始测量",
isUseConnect: false,
});
that.useBluetooth.stopSearchBluetooth() //取消蓝牙搜索
2025-05-30 11:14:38 +08:00
uni.switchTab({
2026-03-23 09:50:49 +08:00
url: "/pages/body/body"
2025-05-30 11:14:38 +08:00
})
},
},
}
</script>
<style scoped lang="scss">
.image3 {
width: 200px !important;
height: 340px !important;
}
</style>