2024-11-12 15:38:28 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view class="weightPages">
|
|
|
|
|
|
<view class="content ">
|
2025-04-29 17:29:44 +08:00
|
|
|
|
<view class="title overflow">{{$t("linkBluetooth.linkBluetoothSuccess")}}</view>
|
2024-11-12 15:38:28 +08:00
|
|
|
|
<view class="text">{{text}}</view>
|
|
|
|
|
|
<view class="image">
|
2024-12-14 09:42:21 +08:00
|
|
|
|
<image src="/pageTwo/static/PCL.gif" class="image3"></image>
|
2024-11-12 15:38:28 +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-11-12 15:38:28 +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-11-12 15:38:28 +08:00
|
|
|
|
<view class="Blue-box">
|
2025-04-26 13:35:30 +08:00
|
|
|
|
{{$t("linkBluetooth.nowWeight")}}:<text>{{weight}}{{unit}}</text>
|
2024-11-12 15:38:28 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<view class="Blue-box">
|
2025-04-26 13:35:30 +08:00
|
|
|
|
{{$t("linkBluetooth.lastHeight")}}:
|
|
|
|
|
|
<input v-model="height" type="digit" :placeholder="$t('tips.verifyHeight')" />cm
|
2024-11-12 15:38:28 +08:00
|
|
|
|
</view>
|
2025-04-26 13:35:30 +08:00
|
|
|
|
<view class="Blue-btn Blue-close" @click="handleBack">{{$t("tips.btnSancellation")}}</view>
|
|
|
|
|
|
<view class="Blue-btn" @click="handleGetMeasure">{{$t("linkBluetooth.SaveResult")}}</view>
|
2024-11-12 15:38:28 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import {
|
|
|
|
|
|
mapState
|
|
|
|
|
|
} from "vuex";
|
|
|
|
|
|
let myTime;
|
|
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
text: "",
|
|
|
|
|
|
imp: "",
|
|
|
|
|
|
weight: "",
|
|
|
|
|
|
height: "",
|
|
|
|
|
|
deviceId: "",
|
|
|
|
|
|
unit: "kg",
|
|
|
|
|
|
Unload: false,
|
|
|
|
|
|
isHeight: false,
|
|
|
|
|
|
isConnection: 0,
|
|
|
|
|
|
isdevice: false,
|
|
|
|
|
|
stopblue: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
...mapState(["user"]),
|
|
|
|
|
|
info() {
|
|
|
|
|
|
return this.user
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
onUnload: function() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.Unload) {
|
|
|
|
|
|
clearTimeout(myTime)
|
|
|
|
|
|
that.closeBluetoothAdapter()
|
|
|
|
|
|
that.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
|
|
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
|
|
pages[pages.length - 2].$vm.getBlereload();
|
|
|
|
|
|
console.log("页面返回onUnload", pages, pages[pages.length - 2])
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onLoad(options) {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
that.text = ""
|
|
|
|
|
|
that.stopblue = true
|
|
|
|
|
|
that.deviceId = options.deviceId
|
|
|
|
|
|
that.height = that.user.height
|
|
|
|
|
|
that.onBluetoothDeviceFound()
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
stopblue: function() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.stopblue) {
|
|
|
|
|
|
clearTimeout(myTime);
|
|
|
|
|
|
that.isHeight = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 发现外围设备
|
|
|
|
|
|
*/
|
|
|
|
|
|
onBluetoothDeviceFound() {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
uni.onBluetoothDeviceFound(res => {
|
|
|
|
|
|
res.devices.forEach(device => {
|
|
|
|
|
|
device.advertisData = device.advertisData ? device.advertisData : ''
|
|
|
|
|
|
if (device.name.indexOf("PCL") !== -1 && device.deviceId.indexOf(that.deviceId) !=
|
|
|
|
|
|
-1) {
|
|
|
|
|
|
clearTimeout(myTime);
|
|
|
|
|
|
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") {
|
|
|
|
|
|
if (dw == "10") {
|
|
|
|
|
|
that.unit = "lb"
|
|
|
|
|
|
data = data / 10
|
|
|
|
|
|
} else {
|
|
|
|
|
|
data = data / 100
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.text = that.$t("linkBluetooth.realTimeWeightText") + data + that.unit
|
2024-11-12 15:38:28 +08:00
|
|
|
|
if (type == "1") {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.text = that.$t("linkBluetooth.StableWeightText") + data + that.unit
|
2024-11-12 15:38:28 +08:00
|
|
|
|
that.imp = parseInt(value.substring(8, 12), 16) / 10
|
|
|
|
|
|
that.deviceId = device.deviceId
|
|
|
|
|
|
that.weight = data
|
|
|
|
|
|
that.stopblue = false
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
});
|
|
|
|
|
|
// that.handleMyTime()
|
|
|
|
|
|
},
|
|
|
|
|
|
handleMyTime() {
|
|
|
|
|
|
var that = this;
|
|
|
|
|
|
myTime = setTimeout(function() {
|
|
|
|
|
|
if (!that.macAddr) {
|
|
|
|
|
|
clearTimeout(myTime);
|
|
|
|
|
|
that.text = ""
|
|
|
|
|
|
that.Unload = true
|
|
|
|
|
|
that.isHeight = false
|
|
|
|
|
|
that.startBluetoothDeviceDiscovery()
|
|
|
|
|
|
that.closeBluetoothAdapter()
|
|
|
|
|
|
}
|
|
|
|
|
|
}, 30000);
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 停止搜索蓝牙设备
|
|
|
|
|
|
*/
|
|
|
|
|
|
stopBluetoothDevicesDiscovery() {
|
|
|
|
|
|
uni.stopBluetoothDevicesDiscovery({
|
|
|
|
|
|
success: e => {
|
|
|
|
|
|
console.log("停止搜索蓝牙设备", e)
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
// 保存测量结果
|
|
|
|
|
|
handleGetMeasure() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
if (!that.height) {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
this.$tools.msg(that.$t("tips.verifyHeight"))
|
2024-11-12 15:38:28 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
that.$model.getmeasurefunit({
|
|
|
|
|
|
adc: that.imp,
|
2024-12-14 09:42:21 +08:00
|
|
|
|
weight: that.weight + that.unit,
|
2024-11-12 15:38:28 +08:00
|
|
|
|
height: that.height,
|
|
|
|
|
|
aud_id: that.info.id
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
that.isHeight = false
|
2024-12-14 09:42:21 +08:00
|
|
|
|
console.log("res", res, that.imp)
|
2024-11-12 15:38:28 +08:00
|
|
|
|
if (res.code == 0) {
|
|
|
|
|
|
that.$store.dispatch('getUserInfo', {
|
|
|
|
|
|
aud_id: uni.getStorageSync('userid')
|
|
|
|
|
|
})
|
|
|
|
|
|
that.$store.dispatch("getResult", {
|
|
|
|
|
|
aud_id: uni.getStorageSync('userid')
|
|
|
|
|
|
})
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.$tools.msg(that.$t("tips.msgSuccess"))
|
2024-11-12 15:38:28 +08:00
|
|
|
|
} else {
|
2025-04-26 13:35:30 +08:00
|
|
|
|
that.$tools.msg(that.$t("tips.msgFail"))
|
2024-11-12 15:38:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
that.Unload = true
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
|
that.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
|
|
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
|
|
pages[pages.length - 2].$vm.getBlereload();
|
|
|
|
|
|
uni.switchTab({
|
|
|
|
|
|
url: "/pages/home/home"
|
|
|
|
|
|
})
|
|
|
|
|
|
}, 200)
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
//
|
|
|
|
|
|
handleBack() {
|
|
|
|
|
|
let that = this
|
|
|
|
|
|
that.text = ""
|
|
|
|
|
|
that.Unload = true
|
|
|
|
|
|
that.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
|
|
|
|
|
|
let pages = getCurrentPages();
|
|
|
|
|
|
console.log("页面返回onUnload", pages, pages[pages.length - 2])
|
|
|
|
|
|
pages[pages.length - 2].$vm.getBlereload();
|
|
|
|
|
|
uni.switchTab({
|
|
|
|
|
|
url: "/pages/home/home"
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 断开蓝牙模块
|
|
|
|
|
|
*/
|
|
|
|
|
|
closeBluetoothAdapter() {
|
|
|
|
|
|
let that = this;
|
|
|
|
|
|
uni.closeBluetoothAdapter({
|
|
|
|
|
|
success: res => {
|
|
|
|
|
|
console.log('蓝牙模块关闭成功');
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
.image3 {
|
|
|
|
|
|
width: 200px !important;
|
|
|
|
|
|
height: 340px !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|