2024-06-13 18:03:50 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view class="weightPages">
|
|
|
|
|
|
<view class="content ">
|
2025-04-29 17:29:44 +08:00
|
|
|
|
<view class="status overflow">{{textLink}}</view>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
<view class="text">{{text}}</view>
|
|
|
|
|
|
<view class="image">
|
2024-12-14 09:42:21 +08:00
|
|
|
|
<image src="/pageTwo/static/HC.png" class="image3"></image>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<view class="tips">
|
2025-04-26 13:35:30 +08:00
|
|
|
|
<text>{{$t("tips.msgTitle")}}:</text>
|
2025-04-29 17:29:44 +08:00
|
|
|
|
<text>1,{{$t("linkBluetooth.onDeviceMeasureTips")}}</text>
|
|
|
|
|
|
<text>2,{{$t("linkBluetooth.openDeviceeMeasureTips")}}</text>
|
|
|
|
|
|
<text>3,{{$t("linkBluetooth.openDeviceeMeasureTips2")}}</text>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<!-- 手动记录 -->
|
|
|
|
|
|
<view class="wrapper" v-if="isHeight">
|
|
|
|
|
|
<view class="bg"></view>
|
|
|
|
|
|
<view class="Blue">
|
2025-04-26 13:35:30 +08:00
|
|
|
|
<view class="h4">{{$t("linkBluetooth.measureResultTips")}}</view>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
<view class="Blue-box">
|
2025-04-26 13:35:30 +08:00
|
|
|
|
{{$t('linkBluetooth.nowHeight')}}:<text>{{height}}{{unit}}</text>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<view class="Blue-box">
|
2025-04-26 13:35:30 +08:00
|
|
|
|
{{$t('linkBluetooth.lastWeight')}}:<input v-model="weight" type="digit"
|
|
|
|
|
|
:placeholder="$t('tips.verifyWeight')" />kg
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</view>
|
2025-04-26 13:35:30 +08:00
|
|
|
|
<view class="Blue-btn Blue-close" @click="handleHeight">{{$t("linkBluetooth.remeasure")}}</view>
|
|
|
|
|
|
<view class="Blue-btn" @click="handleGetMeasure">{{$t("linkBluetooth.SaveResult")}}</view>
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import {
|
|
|
|
|
|
mapState
|
|
|
|
|
|
} from "vuex";
|
|
|
|
|
|
let myTime;
|
|
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
text: "",
|
|
|
|
|
|
weight: "",
|
|
|
|
|
|
height: "",
|
2025-02-18 15:52:22 +08:00
|
|
|
|
height2: "",
|
2024-06-13 18:03:50 +08:00
|
|
|
|
deviceId: "",
|
|
|
|
|
|
macAddr: "",
|
2025-03-19 15:03:31 +08:00
|
|
|
|
write: "",
|
|
|
|
|
|
notify: "",
|
2024-06-13 18:03:50 +08:00
|
|
|
|
unit: "cm",
|
|
|
|
|
|
Unload: false,
|
|
|
|
|
|
isHeight: false,
|
|
|
|
|
|
isConnection: 0,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
isdevice: false,
|
2024-12-09 09:57:51 +08:00
|
|
|
|
textLink: ""
|
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
|
|
|
|
that.weight = that.userInfo.weight
|
2024-12-09 09:57:51 +08:00
|
|
|
|
that.deviceId = options.deviceId
|
|
|
|
|
|
that.createBLEConnection()
|
2024-11-12 15:38:28 +08:00
|
|
|
|
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) {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
let text = that.$t("linkBluetooth.deviceDisconnection")
|
2024-12-09 09:57:51 +08:00
|
|
|
|
that.$tools.showModal(text)
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
isBluetoothTyle: function() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.isBluetoothTyle) {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
let text = that.$t("linkBluetooth.offBluetooth")
|
2024-12-09 09:57:51 +08:00
|
|
|
|
that.$tools.showModal(text)
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2024-12-09 09:57:51 +08:00
|
|
|
|
// 连接蓝牙
|
|
|
|
|
|
createBLEConnection() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.createBLEConnection({
|
|
|
|
|
|
deviceId: that.deviceId,
|
|
|
|
|
|
success: res => {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.textLink = that.$t("linkBluetooth.linkBluetooth")
|
2024-12-09 09:57:51 +08:00
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
that.getBLEDeviceServices()
|
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: res => {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.textLink = that.$t("linkBluetooth.linkBluetoothFail")
|
2024-12-09 09:57:51 +08:00
|
|
|
|
console.log("设备连接失败,请重新连接", res, that.deviceId);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取设备的UUID
|
|
|
|
|
|
*/
|
|
|
|
|
|
getBLEDeviceServices() {
|
|
|
|
|
|
let serviceList = [];
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.getBLEDeviceServices({
|
|
|
|
|
|
deviceId: that.deviceId,
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
console.log("获取设备的UUID成功", res, that.deviceId)
|
|
|
|
|
|
serviceList = res.services;
|
|
|
|
|
|
for (let i = 0; i < serviceList.length; i++) {
|
|
|
|
|
|
let service = serviceList[i];
|
|
|
|
|
|
if (service.uuid.indexOf("FFF0") != -1) {
|
|
|
|
|
|
that.serviceId = service.uuid;
|
|
|
|
|
|
that.getBLEDeviceCharacteristics();
|
|
|
|
|
|
console.log("设备的FFE0的serviceId: " + that.serviceId);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: res => {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.textLink = that.$t("linkBluetooth.linkBluetoothFail")
|
2024-12-09 09:57:51 +08:00
|
|
|
|
console.log('获取设备的UUID失败:', res)
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取指定服务的特征值
|
|
|
|
|
|
*/
|
|
|
|
|
|
getBLEDeviceCharacteristics() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.getBLEDeviceCharacteristics({
|
|
|
|
|
|
deviceId: that.deviceId,
|
|
|
|
|
|
serviceId: that.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
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.textLink = that.$t("linkBluetooth.linkBluetoothSuccess")
|
2024-12-09 09:57:51 +08:00
|
|
|
|
uni.notifyBLECharacteristicValueChange({
|
|
|
|
|
|
deviceId: that.deviceId,
|
|
|
|
|
|
serviceId: that.serviceId,
|
|
|
|
|
|
characteristicId: that.notify,
|
|
|
|
|
|
state: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
uni.notifyBLECharacteristicValueChange({
|
|
|
|
|
|
deviceId: that.deviceId,
|
|
|
|
|
|
serviceId: that.serviceId,
|
|
|
|
|
|
characteristicId: that.write,
|
|
|
|
|
|
state: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
that.notifyBLECharacteristicValue()
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: res => {
|
|
|
|
|
|
console.log('获取特征值失败:', JSON.stringify(res))
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2024-11-12 15:38:28 +08:00
|
|
|
|
// 接收蓝牙数据
|
|
|
|
|
|
notifyBLECharacteristicValue() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.notifyBLECharacteristicValueChange({
|
|
|
|
|
|
state: true, // 启用 notify 功能
|
2024-12-09 09:57:51 +08:00
|
|
|
|
deviceId: that.deviceId,
|
|
|
|
|
|
serviceId: that.serviceId,
|
|
|
|
|
|
characteristicId: that.notify,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
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 (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
|
|
|
|
|
|
}
|
2025-02-18 15:52:22 +08:00
|
|
|
|
if (unit == "0") {
|
|
|
|
|
|
that.unit = "cm"
|
|
|
|
|
|
}
|
|
|
|
|
|
if (unit == "1") {
|
|
|
|
|
|
that.unit = "inch"
|
|
|
|
|
|
}
|
|
|
|
|
|
if (unit == "2") {
|
|
|
|
|
|
that.unit = "ft"
|
|
|
|
|
|
}
|
2024-11-12 15:38:28 +08:00
|
|
|
|
if (Number(data) < 20) {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.text = that.$t("linkBluetooth.errorOperation")
|
2024-11-12 15:38:28 +08:00
|
|
|
|
} else {
|
2025-02-18 15:52:22 +08:00
|
|
|
|
if (unit == "2") {
|
|
|
|
|
|
let data1 = data / 12
|
|
|
|
|
|
let data2 = Number(data1 - Math.floor(data1)) * 12
|
|
|
|
|
|
that.height2 = data
|
|
|
|
|
|
that.height = Math.floor(data1) + "'" + data2.toFixed(1)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
that.height2 = data
|
|
|
|
|
|
that.height = data
|
|
|
|
|
|
}
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.text = that.$t("linkBluetooth.heightText") + that.height + that.unit
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.isHeight = true
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
2025-02-18 15:52:22 +08:00
|
|
|
|
console.log("G02", value, unit, data, that.height, that.height2)
|
2024-11-12 15:38:28 +08:00
|
|
|
|
})
|
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
|
2025-02-18 15:52:22 +08:00
|
|
|
|
let height = 0
|
2024-06-13 18:03:50 +08:00
|
|
|
|
if (!that.weight) {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.$tools.msg(that.$t("tips.verifyWeight"))
|
2024-06-13 18:03:50 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2025-02-18 15:52:22 +08:00
|
|
|
|
if (that.unit == 'ft') {
|
2025-03-19 15:03:31 +08:00
|
|
|
|
height = Number(that.height2 * 2.54).toFixed(2)
|
2025-02-18 15:52:22 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
height = that.height2
|
|
|
|
|
|
}
|
|
|
|
|
|
console.log("提交身高", height)
|
2024-06-13 18:03:50 +08:00
|
|
|
|
that.$model.getmeasurefunit({
|
2024-07-08 10:50:07 +08:00
|
|
|
|
adc: 0,
|
2024-06-13 18:03:50 +08:00
|
|
|
|
weight: that.weight,
|
2025-02-18 15:52:22 +08:00
|
|
|
|
height: height,
|
2024-12-09 09:57:51 +08:00
|
|
|
|
aud_id: that.userInfo.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
|
|
|
|
})
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.$tools.msg(that.$t("tips.msgSuccess"))
|
2024-06-13 18:03:50 +08:00
|
|
|
|
} else {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.$tools.msg(that.$t("tips.msgFail"))
|
2024-06-13 18:03:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
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.height = ""
|
2024-06-13 18:03:50 +08:00
|
|
|
|
that.text = ""
|
2025-03-19 15:03:31 +08:00
|
|
|
|
that.isHeight = false
|
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({
|
2025-03-19 15:03:31 +08:00
|
|
|
|
// deviceId: that.deviceId,
|
|
|
|
|
|
// serviceId: that.serviceId,
|
|
|
|
|
|
// characteristicId: that.write,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
// value: buf.buffer,
|
|
|
|
|
|
// success: res => {
|
2025-03-19 15:03:31 +08:00
|
|
|
|
|
2024-11-12 15:38:28 +08:00
|
|
|
|
// 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({
|
2024-12-09 09:57:51 +08:00
|
|
|
|
deviceId: that.deviceId,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
success: res => {
|
|
|
|
|
|
console.log('断开蓝牙连接成功');
|
2024-11-14 14:07:14 +08:00
|
|
|
|
that.$store.commit("changeConnected", false);
|
2024-11-12 15:38:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2024-06-13 18:03:50 +08:00
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.image3 {
|
|
|
|
|
|
width: 200px !important;
|
|
|
|
|
|
height: 340px !important;
|
|
|
|
|
|
}
|
2024-12-09 09:57:51 +08:00
|
|
|
|
|
|
|
|
|
|
.status {
|
2025-04-29 17:29:44 +08:00
|
|
|
|
width: auto;
|
2024-12-09 09:57:51 +08:00
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
height: 35px;
|
|
|
|
|
|
line-height: 35px;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
border-radius: 15px;
|
|
|
|
|
|
margin: 15px auto;
|
2025-04-29 17:29:44 +08:00
|
|
|
|
padding: 0 15px;
|
2024-12-09 09:57:51 +08:00
|
|
|
|
background-color: #ffdda6;
|
|
|
|
|
|
}
|
2024-06-13 18:03:50 +08:00
|
|
|
|
</style>
|