2024-06-13 18:03:50 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view class="weightPages">
|
|
|
|
|
|
<view class="content ">
|
2024-11-12 15:38:28 +08:00
|
|
|
|
<view class="title">连接成功,开始测量</view>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
<view class="text">{{text}}</view>
|
|
|
|
|
|
<view class="image">
|
2024-08-22 09:48:00 +08:00
|
|
|
|
<image src="/static/HC.png" class="image3"></image>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</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">
|
2024-07-08 10:50:07 +08:00
|
|
|
|
本次测量身高为:<text>{{height}}{{unit}}</text>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<view class="Blue-box">
|
|
|
|
|
|
上次测量体重为:<input v-model="weight" type="digit" placeholder="请输入体重" />kg
|
|
|
|
|
|
</view>
|
2024-11-12 15:38:28 +08:00
|
|
|
|
<view class="Blue-btn Blue-close" @click="handleHeight">重新测量</view>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
<view class="Blue-btn" @click="handleGetMeasure">保存测量结果</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import {
|
|
|
|
|
|
mapState
|
|
|
|
|
|
} from "vuex";
|
|
|
|
|
|
let myTime;
|
|
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
text: "",
|
|
|
|
|
|
weight: "",
|
|
|
|
|
|
height: "",
|
|
|
|
|
|
deviceId: "",
|
|
|
|
|
|
macAddr: "",
|
|
|
|
|
|
unit: "cm",
|
|
|
|
|
|
Unload: false,
|
|
|
|
|
|
isHeight: false,
|
|
|
|
|
|
isConnection: 0,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
isdevice: false,
|
|
|
|
|
|
info: {}
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
...mapState(["user", "isConnected", "isBluetoothTyle"]),
|
2024-11-12 15:38:28 +08:00
|
|
|
|
userInfo() {
|
2024-06-13 18:03:50 +08:00
|
|
|
|
return this.user
|
2024-11-12 15:38:28 +08:00
|
|
|
|
}
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
onUnload: function() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.Unload) {
|
|
|
|
|
|
clearTimeout(myTime)
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.closeBLEConnection()
|
2024-06-13 18:03:50 +08:00
|
|
|
|
that.closeBluetoothAdapter()
|
|
|
|
|
|
console.log("页面返回onUnload")
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2024-08-22 09:48:00 +08:00
|
|
|
|
onLoad(options) {
|
2024-06-13 18:03:50 +08:00
|
|
|
|
let that = this
|
2024-11-12 15:38:28 +08:00
|
|
|
|
let info = options.info
|
|
|
|
|
|
that.info = JSON.parse(info)
|
|
|
|
|
|
that.weight = that.userInfo.weight
|
|
|
|
|
|
that.notifyBLECharacteristicValue()
|
|
|
|
|
|
that.onBLEConnectionStateChange()
|
|
|
|
|
|
uni.onBluetoothAdapterStateChange(function(res) {
|
|
|
|
|
|
that.$store.commit("changeBluetooth", res.available);
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
isConnected: function() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.isConnected) {
|
2024-11-12 15:38:28 +08:00
|
|
|
|
uni.showModal({
|
|
|
|
|
|
title: '连接已断开',
|
|
|
|
|
|
content: '测量过程中已与设备连接中断,请重新连接设备再开始测量',
|
|
|
|
|
|
showCancel: false,
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
uni.switchTab({ //返回
|
|
|
|
|
|
url: "/pages/home/home"
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
isBluetoothTyle: function() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.isBluetoothTyle) {
|
2024-11-12 15:38:28 +08:00
|
|
|
|
uni.showModal({
|
|
|
|
|
|
title: '连接已断开',
|
|
|
|
|
|
content: '蓝牙已关闭,请重新打开蓝牙后再开始测量',
|
|
|
|
|
|
showCancel: false,
|
|
|
|
|
|
success: function(res) {
|
|
|
|
|
|
if (res.confirm) {
|
|
|
|
|
|
uni.switchTab({ //返回
|
|
|
|
|
|
url: "/pages/home/home"
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2024-11-12 15:38:28 +08:00
|
|
|
|
// 接收蓝牙数据
|
|
|
|
|
|
notifyBLECharacteristicValue() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.notifyBLECharacteristicValueChange({
|
|
|
|
|
|
state: true, // 启用 notify 功能
|
|
|
|
|
|
deviceId: that.info.deviceId,
|
|
|
|
|
|
serviceId: that.info.serviceId,
|
|
|
|
|
|
characteristicId: that.info.notify,
|
|
|
|
|
|
success(res) {
|
|
|
|
|
|
uni.onBLECharacteristicValueChange(function(res) {
|
|
|
|
|
|
let value = that.$tools.ab2hex(res.value, "");
|
|
|
|
|
|
let data = parseInt(value.substring(7, 10), 16)
|
|
|
|
|
|
let unit = parseInt(value.substring(10, 12))
|
|
|
|
|
|
let digit = parseInt(value.substring(12, 14))
|
|
|
|
|
|
if (unit == "1") {
|
|
|
|
|
|
that.unit = "inch"
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
2024-11-12 15:38:28 +08:00
|
|
|
|
if (unit == "2") {
|
|
|
|
|
|
that.unit = "ft:in"
|
|
|
|
|
|
}
|
|
|
|
|
|
if (digit == "1") {
|
2024-06-13 18:03:50 +08:00
|
|
|
|
data = data / 10
|
|
|
|
|
|
}
|
2024-11-12 15:38:28 +08:00
|
|
|
|
if (digit == "2") {
|
2024-06-13 18:03:50 +08:00
|
|
|
|
data = data / 100
|
|
|
|
|
|
}
|
2024-11-12 15:38:28 +08:00
|
|
|
|
if (Number(data) < 20) {
|
|
|
|
|
|
that.text = "操作错误,请重新测量"
|
|
|
|
|
|
} else {
|
2024-07-08 10:50:07 +08:00
|
|
|
|
that.height = data
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.text = "您的身高是:" + data + that.unit
|
|
|
|
|
|
that.isHeight = true
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
2024-11-12 15:38:28 +08:00
|
|
|
|
console.log("G02", value, data)
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
2024-11-12 15:38:28 +08:00
|
|
|
|
fail(res) {
|
|
|
|
|
|
console.log("测量失败", res.value);
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
// 保存测量结果
|
|
|
|
|
|
handleGetMeasure() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.weight) {
|
|
|
|
|
|
this.$tools.msg("请输入体重")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
that.$model.getmeasurefunit({
|
2024-07-08 10:50:07 +08:00
|
|
|
|
adc: 0,
|
2024-06-13 18:03:50 +08:00
|
|
|
|
weight: that.weight,
|
|
|
|
|
|
height: that.height,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
aud_id: that.user.id
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
|
that.isHeight = false
|
|
|
|
|
|
if (res.code == 0) {
|
2024-07-08 10:50:07 +08:00
|
|
|
|
that.$store.dispatch("getResult", {
|
|
|
|
|
|
aud_id: uni.getStorageSync('userid')
|
|
|
|
|
|
})
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.$store.dispatch('getUserInfo', {
|
|
|
|
|
|
aud_id: uni.getStorageSync('userid')
|
2024-07-08 10:50:07 +08:00
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
that.$tools.msg("测量成功")
|
|
|
|
|
|
} else {
|
|
|
|
|
|
that.$tools.msg("测量失败")
|
|
|
|
|
|
}
|
|
|
|
|
|
that.Unload = true
|
2024-11-12 15:38:28 +08:00
|
|
|
|
uni.switchTab({
|
|
|
|
|
|
url: "/pages/home/home"
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
setTimeout(function() {
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.closeBLEConnection()
|
2024-06-13 18:03:50 +08:00
|
|
|
|
that.closeBluetoothAdapter()
|
2024-11-12 15:38:28 +08:00
|
|
|
|
}, 500)
|
2024-06-13 18:03:50 +08:00
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-11-12 15:38:28 +08:00
|
|
|
|
handleHeight() {
|
2024-06-13 18:03:50 +08:00
|
|
|
|
let that = this
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.isHeight = false
|
|
|
|
|
|
that.height = ""
|
2024-06-13 18:03:50 +08:00
|
|
|
|
that.text = ""
|
2024-11-12 15:38:28 +08:00
|
|
|
|
// let j = Number(2 + 3).toString(16)
|
|
|
|
|
|
// let str = "5A0203" + j.substr(j.length - 2, 2)
|
|
|
|
|
|
// let buf = new Uint8Array(str.match(/[\da-f]{2}/gi).map(function(h) {
|
|
|
|
|
|
// return parseInt(h, 16)
|
|
|
|
|
|
// }))
|
|
|
|
|
|
// uni.writeBLECharacteristicValue({
|
|
|
|
|
|
// deviceId: that.info.deviceId,
|
|
|
|
|
|
// serviceId: that.info.serviceId,
|
|
|
|
|
|
// characteristicId: that.info.write,
|
|
|
|
|
|
// value: buf.buffer,
|
|
|
|
|
|
// success: res => {
|
|
|
|
|
|
// console.log('下发指令成功', res.errMsg)
|
|
|
|
|
|
// },
|
|
|
|
|
|
// fail: res => {
|
|
|
|
|
|
// console.log("下发指令失败", res);
|
|
|
|
|
|
// },
|
|
|
|
|
|
// })
|
|
|
|
|
|
},
|
|
|
|
|
|
// 监听蓝牙连接状态
|
|
|
|
|
|
onBLEConnectionStateChange() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
uni.onBLEConnectionStateChange(function(res) {
|
|
|
|
|
|
console.log("监听蓝牙连接状态", res.connected)
|
|
|
|
|
|
that.$store.commit("changeConnected", res.connected);
|
|
|
|
|
|
})
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 断开蓝牙模块
|
|
|
|
|
|
*/
|
|
|
|
|
|
closeBluetoothAdapter() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.closeBluetoothAdapter({
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
console.log('蓝牙模块关闭成功');
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-11-12 15:38:28 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 断开蓝牙连接
|
|
|
|
|
|
*/
|
|
|
|
|
|
closeBLEConnection() {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
uni.closeBLEConnection({
|
|
|
|
|
|
deviceId: that.info.deviceId,
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
console.log('断开蓝牙连接成功');
|
|
|
|
|
|
that.$store.commit("changeBluetooth", false);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.image3 {
|
|
|
|
|
|
width: 200px !important;
|
|
|
|
|
|
height: 340px !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|