修复PCL11没显示斤的问题

This commit is contained in:
subing008 2025-08-14 18:30:31 +08:00
parent 2a6d94c422
commit 8d94ac7da7
4 changed files with 1126 additions and 1 deletions

638
BLEPages/child/B68T.vue Normal file
View File

@ -0,0 +1,638 @@
<template>
<view class="content skipping">
<view class="title" v-if="isConnection == 0">连接中请稍后...</view>
<view class="title" v-else-if="isConnection == 1">连接成功请开始测量</view>
<view class="title" style="color: brown;" v-else-if="isConnection == 2" @click="openBluetoothAdapter">连接失败点击重新连接
</view>
<div class="result-wrap">
<view class="result-item">
<view class="result-title">身高</view>
<view class="result-value">{{info.height}}cm</view>
</view>
<view class="result-item">
<view class="result-title">体重</view>
<view class="result-value">{{info.weight}}kg</view>
</view>
<view class="result-item">
<view class="result-title">骨量</view>
<view class="result-value">{{info.boneMass}}kg</view>
</view>
<view class="result-item">
<view class="result-title">阻抗</view>
<view class="result-value">{{info.impedance}}Ω</view>
</view>
<view class="result-item">
<view class="result-title">BMI</view>
<view class="result-value">{{info.bmi}}</view>
</view>
<view class="result-item">
<view class="result-title">内脏脂肪</view>
<view class="result-value">{{info.visceralFat}}%</view>
</view>
<view class="result-item">
<view class="result-title">脂肪率</view>
<view class="result-value">{{info.fatRate}}%</view>
</view>
<view class="result-item">
<view class="result-title">水分率</view>
<view class="result-value">{{info.waterRate}}%</view>
</view>
<view class="result-item">
<view class="result-title">肌肉率</view>
<view class="result-value">{{info.muscleRate}}%</view>
</view>
</div>
<view class="image">
<image mode="aspectFit" src="/BLEPages/static/H08B2.gif"></image>
</view>
<view class="tips">
<view>提示</view>
<view>1.请确定设备是开机状态</view>
<view>2.请确定手机蓝牙位置信息已打开</view>
<view>3.ios系统需打开设置>应用>微信里的蓝牙权限</view>
</view>
<div class="info-dlg" v-if="show_info">
<view class="info-inner">
<view class="info-item">
<text>性别</text>
<text class="man" :class="{'active':cur_sex==1}" @click="cur_sex=1"></text>
<text class="woman" :class="{'active':cur_sex==2}" @click="cur_sex=2"></text>
</view>
<view class="info-item">
<text>年龄</text>
<!-- <input type="text" placeholder="请输入年龄" v-model="cur_age"/>
-->
<picker class="age-select" mode="selector" :value="cur_age" :range="ageRange" @change="onAgeChange">
{{cur_age+1}}
</picker>
</view>
<view class="confirm" @click="setUserInfo">确定</view>
</view>
</div>
</view>
</template>
<script>
import {
mapState
} from "vuex";
export default {
data() {
return {
deviceId: "",
serviceId: "",
write: "",
notify: "",
cur_sex: 1,
cur_age: 27,
show_info: false,
ageRange: [],
ageIndex: 30,
send_err_count: 0,
info: {
bmi: 0,
weight: 0,
fatRate: 0, //
waterRate: 0, //
muscleRate: 0, //,
boneMass: 0, //
impedance: 0, //
height: 0, //
value: 0
},
isConnection: 0,
}
},
computed: {
...mapState(["user", "isConnected", "isBluetoothTyle", "appTheme"]),
},
mounted() {
let that = this
for (let i = 1; i <= 100; i++) {
that.ageRange.push(i);
}
let sex = uni.getStorageSync('sex')
let age = uni.getStorageSync('age')
that.cur_sex = sex ? sex : 1
that.cur_age = age ? age : 27
},
onLoad(options) {
let that = this
if (options && options.deviceId) {
that.deviceId = options.deviceId
that.stopBluetoothDevicesDiscovery()
that.createBLEConnection()
that.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetooth", res.available);
})
} else {
// uni.showToast({
// title: '',
// icon: "error"
// })
// uni.switchTab({
// url: "/pages/index/index"
// })
}
},
onUnload: function() {
let that = this
if (!that.Unload) {
that.handleBack()
uni.switchTab({
url: "/pages/index/index"
})
console.log("返回上一个页面")
}
},
watch: {
isConnected: function() {
let that = this
if (!that.isConnected) {
that.handleBack()
that.isConnection = 2
}
},
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.handleBack()
that.isConnection = 2
}
},
},
methods: {
setUserInfo() {
let that = this
uni.setStorageSync('sex', that.cur_sex)
uni.setStorageSync('age', that.cur_age)
that.show_info = false
that.sendCommand(that.cur_sex, that.cur_age + 1);
},
onAgeChange(e) {
this.cur_age = parseInt(e.detail.value)
},
openBluetoothAdapter() {
let that = this
that.isConnection = 0
uni.openBluetoothAdapter({
success: e => {
console.log("初始化设备")
that.startBluetoothDeviceDiscovery()
},
fail: e => {
that.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")
}
});
},
//
startBluetoothDeviceDiscovery() {
let that = this
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
success: res => {
console.log("开始搜索")
that.onBluetoothDeviceFound();
},
fail: res => {
that.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")
}
});
},
/**
* 发现外围设备
*/
onBluetoothDeviceFound() {
var that = this;
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
if (!device.name && !device.localName) {
return
}
if (device.name.indexOf('JS-B68T') != -1 || (device.localName && device.localName.toLowerCase()
.indexOf('JS-B68T') != -1)) {
this.deviceId = device.deviceId
that.stopBluetoothDevicesDiscovery()
that.createBLEConnection()
}
})
});
},
//
createBLEConnection() {
let that = this;
that.isConnection = 0
uni.createBLEConnection({
deviceId: that.deviceId,
success: res => {
that.getBLEDeviceServices()
},
fail: res => {
console.log("设备连接失败,请重新连接", res);
}
});
},
/**
* 获取设备的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("00001910") != -1) {
that.serviceId = service.uuid;
that.getBLEDeviceCharacteristics();
break;
}
}
},
fail: res => {
console.log('获取设备的UUID失败:', res)
}
});
},
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics() {
let characteristicsList = [];
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
console.log("服务的特征值成功", res)
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('00002B10') != -1) {
that.write = item.uuid
} else if (item.uuid.indexOf('00002B11') != -1) {
that.notify = item.uuid
}
}
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.notify,
state: true,
success: () => {
setTimeout(() => {
that.show_info = true
}, 1000);
uni.onBLECharacteristicValueChange(function(res) {
console.log(res.value)
const raw = new Uint8Array(res.value);
if (raw[0] == 0x55 && raw[1] == 0xAA) {
that.isConnection = 1
that.send_err_count = 0
uni.showToast({
title: '年龄信息发送成功,请开始测量'
})
return
}
if(raw[0] == 0x55 && raw[1] == 0xBB) {
if(that.send_err_count > 2) {
that.isConnection = 2
uni.showToast({
title: '年龄信息发送失败,请重新连接'
})
return
}
that.send_err_count++
that.setUserInfo()
return
}
if(raw[0] == 0x5A) {
// (, 100)
that.info.weight = ((raw[2] << 8) | raw[3]) / 100.0
if (that.info.weight < 1) {
that.info.weight = ((raw[2] << 8) | raw[3])
}
// (, 10)
that.info.fatRate = ((raw[4] << 8) | raw[5]) / 10.0
// (, 10)
that.info.waterRate = ((raw[6] << 8) | raw[7]) / 10.0
// (, 10)
that.info.muscleRate = ((raw[8] << 8) | raw[9]) / 10.0
// (, 10)
that.info.boneMass = ((raw[10] << 8) | raw[11]) / 10.0
// ()
that.info.impedance = (raw[12] << 8) | raw[13]
//BMI
that.info.bmi = ((raw[14] << 8) | raw[16]) / 10.0;
// (, )
that.info.height = raw[15]
if (raw.length == 18 && raw[17] == 0xA5) {
that.handleGetMeasure()
}
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
//
sendCommand(gender, age) {
let that = this;
// 11Buffer ()
const buffer = new ArrayBuffer(10);
const bytes = new Uint8Array(buffer);
//
bytes[0] = 0x02; //
bytes[1] = 0x53; // 1
// ()
bytes[2] = gender === 2 ? 0x31 : 0x30; // 0x31, 0x30
// 4 (0x30)
bytes[3] = 0x30;
bytes[4] = 0x30;
bytes[5] = 0x30;
// ASCII
const ageStr = age.toString().padStart(2, '0');
bytes[6] = ageStr.charCodeAt(0); // ASCII
bytes[7] = ageStr.charCodeAt(1); // ASCII
// (0x02)
let checksum = bytes[0];
for (let i = 1; i <= 7; i++) {
checksum ^= bytes[i];
}
bytes[8] = checksum;
//
bytes[9] = 0x03;
//
uni.writeBLECharacteristicValue({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.write,
value: buffer,
success: () => {
},
fail: (err) => {
uni.showToast({
title: '发送失败'
})
}
});
},
//
handleGetMeasure() {
// let that = this
// if (that.info.active == 3 && that.weight == 0 && that.Ycount != 0) {
// console.log("1", that.weight, that.Ycount)
// that.weight = that.Ycount
// } else if (that.info.active == 3 && that.weight != 0 && that.Ycount != 0) {
// console.log("2", that.weight, that.Ycount)
// that.weight = Number(that.Ycount) - Number(that.weight)
// }
// if (that.info.active == 2) {
// that.time_m = Math.floor((that.time % 3600) / 60)
// that.time_s = that.time % 60
// }
// that.$model.getskipResult({
// aud_id: uni.getStorageSync('userid'),
// kcal: Math.floor(that.kcal),
// num: that.weight,
// time_m: Number(that.time_m),
// time_s: that.time_s,
// type: that.info.active == 1 ? 'free' : that.info.active == 2 ? 'time' : 'num'
// }).then(res => {
// console.log("", that.time, res)
// if (res.code == 0) {
// that.bpm = that.weight / (that.time / 60)
// that.iswrapper = true
// that.$store.dispatch('getUserInfo', {
// aud_id: uni.getStorageSync('userid')
// })
// } else {
// that.$tools.msg(res.msg)
// }
// })
},
onBLEConnectionStateChange() {
let that = this
uni.onBLEConnectionStateChange(function(res) {
console.log("监听蓝牙连接状态", res.connected)
if (!res.connected) {
that.stopBluetoothDevicesDiscovery()
that.closeBLEConnection()
that.closeBluetoothAdapter()
that.isConnection = 2
}
that.$store.commit("changeConnected", res.connected);
})
},
handleBack(ind) {
let that = this
that.stopBluetoothDevicesDiscovery() //
that.closeBLEConnection()
that.closeBluetoothAdapter()
},
/**
* 停止搜索蓝牙设备
*/
stopBluetoothDevicesDiscovery() {
uni.stopBluetoothDevicesDiscovery({
success: e => {
console.log("停止搜索蓝牙设备", e)
},
});
},
/**
* 断开蓝牙模块
*/
closeBluetoothAdapter() {
let that = this;
uni.closeBluetoothAdapter({
success: res => {
console.log('蓝牙模块关闭成功');
}
})
},
/**
* 断开蓝牙连接
*/
closeBLEConnection() {
var that = this;
uni.closeBLEConnection({
deviceId: that.deviceId,
success: res => {
console.log('断开蓝牙连接成功');
}
});
},
}
}
</script>
<style lang="scss" scoped>
.title {
width: 100%;
text-align: center;
font-size: 36rpx;
font-weight: 700;
margin: 20rpx 0;
}
.result-wrap {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 30rpx;
box-sizing: border-box;
.result-item {
display: flex;
justify-content: flex-start;
align-items: center;
width: 48%;
padding: 20rpx;
margin-top: 16rpx;
box-sizing: border-box;
border-radius: 12rpx;
background-color: #fff;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
.result-title {
flex: 150rpx 0 0;
font-size: 32rpx;
font-weight: 600;
color: #4b6cb7;
}
.result-value {
flex: 1;
font-size: 32rpx;
font-weight: 700;
color: #182848;
margin-top: 5rpx;
text-align: right;
}
}
}
.tips {
font-weight: 700;
padding: 0 20rpx;
box-sizing: border-box;
}
.image {
display: flex;
justify-content: center;
margin-top: 20rpx;
}
.info-dlg {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 99;
background-color: rgba(0, 0, 0, 0.8);
.info-inner {
width: 65%;
height: 350rpx;
border-radius: 20rpx;
background-color: #fff;
padding: 80rpx 50rpx;
box-sizing: border-box;
.info-item {
display: flex;
margin-bottom: 30rpx;
text {
font-size: 36rpx;
font-weight: 700;
}
.man,
.woman {
width: 120rpx;
height: 50rpx;
font-size: 28rpx;
line-height: 50rpx;
text-align: center;
border-radius: 8rpx;
border: 1px solid #e1e1e1;
margin-right: 10rpx;
&.active {
color: #fff;
}
}
.man.active {
background-color: #74b9ff;
}
.woman.active {
background-color: #fd79a8;
}
.age-select {
width: 210rpx;
height: 50rpx;
line-height: 50rpx;
border-radius: 8rpx;
padding: 0 20rpx;
border: 1px solid #e1e1e1;
}
}
.confirm {
width: 200rpx;
height: 50rpx;
color: #fff;
font-size: 32rpx;
line-height: 50rpx;
text-align: center;
margin: 0 auto;
background-color: #2ecc71;
}
.info-item:last-child {
margin-top: 50rpx;
}
}
}
</style>

View File

@ -198,6 +198,9 @@
let num = msg.substring(3, 5) //
let unit = msg.substring(1, 3) //
let dw1 = "kg"
if(unit == '01') {
dw1 = 'jin'
}
if (unit == "10") {
dw1 = "lb"
}
@ -213,7 +216,7 @@
}
}
console.log("weight", type, weight, num, unit, dw1)
that.text = "您的体重是:" + weight + dw1
that.text = "您的体重是:" + weight
if (type == '1') {
that.macAddr = device.macAddr
that.deviceId = device.deviceId;

469
BLEPages/child/SG616BT.vue Normal file
View File

@ -0,0 +1,469 @@
<template>
<view>
<view class="content weightPages">
<view class="title" v-if="isConnection == 0">连接中请稍后</view>
<view class="title" v-if="isConnection == 1">连接成功请开始测量</view>
<view class="title" v-if="isConnection == 2" @click="openBluetoothAdapter">连接失败点击重新连接</view>
<view class="text">{{text}}</view>
<view class="text">{{textH}}</view>
<view class="image">
<image src="/BLEPages/static/H01pro.gif"></image>
</view>
<view class="tips">
<text>提示</text>
<text>1.请确定设备是开机状态</text>
<text>2.请确定手机蓝牙位置信息已打开</text>
<text>3.ios系统需打开设置>应用>微信里的蓝牙权限</text>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
var myTime;
export default {
data() {
return {
text: "",
textH: "",
height: "",
weight: "",
imp: 0,
uuid1: "",
uuid2: "",
uuid3: "",
macAddr: "",
deviceId: "",
serviceId: "",
type30: false,
Unload: false,
isConnection: 0, //
}
},
computed: {
...mapState(["user", "isConnected", "isBluetoothTyle", "appTheme"]),
info() {
return this.user
}
},
onUnload: function() {
let that = this
if (!that.Unload) {
that.stopBluetoothDevicesDiscovery() //
clearTimeout(myTime);
that.closeBLEConnection()
that.closeBluetoothAdapter()
uni.switchTab({
url: "/pages/index/index"
})
console.log("返回首页")
}
},
onLoad(options) {
let that = this
//
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: this.appTheme,
})
//
that.text = ""
that.textH = ""
that.imp = 0
if (options && options.deviceId) {
that.deviceId = options.deviceId
that.closeBLEConnection()
that.closeBluetoothAdapter()
that.openBluetoothAdapter()
}
that.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetooth", res.available);
})
},
watch: {
isConnected: function() {
let that = this
if (!that.isConnected) {
that.handleBack()
that.isConnection = 2
}
},
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.handleBack()
that.isConnection = 2
}
},
},
methods: {
//
openBluetoothAdapter() {
let that = this
that.text = ""
that.textH = ""
uni.openBluetoothAdapter({
success: e => {
that.isConnection = 0
that.startBluetoothDeviceDiscovery()
},
fail: e => {
that.isConnection = 2
that.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")
}
});
},
//
startBluetoothDeviceDiscovery() {
let that = this
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: false,
interval: 500, //
services: [
"FFE0",
],
success: res => {
that.isConnection = 0
that.onBluetoothDeviceFound();
},
fail: res => {
that.isConnection = 2
that.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")
}
});
},
/**
* 发现外围设备
*/
onBluetoothDeviceFound() {
var that = this;
that.isConnection = 0
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
if (!device.name && !device.localName) {
return
}
if (device.name.indexOf('AiLink_') != -1 || (device.localName && device.localName
.indexOf('AiLink_') != -1)) {
clearTimeout(myTime);
let buff = device.advertisData.slice(-6)
device.mac = new Uint8Array(buff) // 广maciOSmac
let tempMac = Array.from(device.mac)
tempMac.reverse()
device.macAddr = that.$tools.ab2hex(tempMac, ':').toUpperCase()
if (device.deviceId.indexOf(that.deviceId) != -1 || device.macAddr.indexOf(that
.deviceId) != -1) {
that.stopBluetoothDevicesDiscovery()
that.macAddr = device.macAddr
that.deviceId = device.deviceId;
that.createBLEConnection()
return;
}
}
})
});
that.handleMyTime()
},
handleMyTime() {
var that = this;
myTime = setTimeout(function() {
if (!that.macAddr) {
clearTimeout(myTime);
that.Unload = true
that.isConnection = 2
that.closeBLEConnection()
that.closeBluetoothAdapter()
}
}, 20000);
},
/**
* 停止搜索蓝牙设备
*/
stopBluetoothDevicesDiscovery() {
uni.stopBluetoothDevicesDiscovery({
success: e => {
console.log("停止搜索蓝牙设备", e)
},
});
},
//
onBLEConnectionStateChange() {
let that = this
uni.onBLEConnectionStateChange(function(res) {
console.log("监听蓝牙连接状态", res.connected)
if (!res.connected) {
that.Unload = true
that.isConnection = 2
clearTimeout(myTime);
that.closeBLEConnection()
that.closeBluetoothAdapter()
}
that.$store.commit("changeConnected", res.connected);
})
},
//
createBLEConnection() {
let that = this;
uni.createBLEConnection({
deviceId: that.deviceId,
success: res => {
that.isConnection = 0
that.getBLEDeviceServices();
},
fail: res => {
that.isConnection = 2
console.log("设备连接失败,请重新连接", res);
}
});
},
/**
* 获取设备的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.isConnection = 1
that.serviceId = service.uuid;
that.getBLEDeviceCharacteristics();
console.log("设备的FFE0的serviceId " + that.serviceId);
break;
}
}
},
fail: res => {
console.log('获取设备的UUID失败:', res)
}
});
},
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics() {
let characteristicsList = [];
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: that.deviceId,
serviceId: that.serviceId,
success: res => {
console.log("服务的特征值成功", res)
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFE1') != -1) {
that.uuid1 = item.uuid //
} else if (item.uuid.indexOf('0000FFE2') != -1) {
that.uuid2 = item.uuid //
} else if (item.uuid.indexOf('0000FFE3') != -1) {
that.uuid3 = item.uuid //
}
}
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.uuid2,
state: true,
})
uni.notifyBLECharacteristicValueChange({
deviceId: that.deviceId,
serviceId: that.serviceId,
characteristicId: that.uuid3,
state: true,
})
// that.sendData()
uni.onBLECharacteristicValueChange(function(res) {
let value = that.$tools.ab2hex(res.value, "");
let num = value.substring(18, 19)
let dw = value.substring(19, 20)
let type = value.substring(8, 10)
let typeInfo = value.substring(10, 12)
console.log("单位", value, dw)
if (type == "10") {
let data = parseInt(value.substring(13, 18), 16)
let dw1 = "kg"
let dw2 = "kg"
if (dw == "1") {
dw1 = "斤"
dw2 = "jin"
}
if (dw == "4") {
dw1 = "st:lb"
dw2 = "st"
data = 1 * data + 5
}
if (dw == "6") {
dw1 = "lb"
dw2 = "lb"
}
if (num == "1") {
data = parseInt(value.substring(13, 18), 16) / 10
}
if (num == "2") {
data = parseInt(value.substring(13, 18), 16) / 100
}
if (num == "3") {
data = parseInt(value.substring(13, 18), 16) / 1000
}
if (typeInfo == "01") {
that.text = "您的实时体重是:" + data + dw1
}
if (typeInfo == "02") {
that.text = "您的体重是:" + data + dw1
that.weight = data + dw2
console.log("稳定体重:", value, that.weight)
}
}
if (type == "14") {
that.height = parseInt(value.substring(10, 14), 16) / 10
that.textH = "您的身高是:" + that.height + "cm"
console.log("稳定身高:", that.height)
}
if (type == "11") {
if (typeInfo == "03" || typeInfo == "04") {
that.imp = parseInt(value.substring(17, 22), 16)
}
console.log("阻抗:", typeInfo, parseInt(value.substring(17, 22), 16))
}
if (type == "30") {
console.log("测量完成", that.weight, that.imp, that.height)
if (!that.type30) {
if (that.imp == 0) {
uni.showModal({
title: '提示',
content: "体脂测量失败,是否保存本次测量结果?",
cancelText: "放弃",
confirmText: "保存",
success(res) {
if (res.confirm) {
that.imp = 0
that.handleGetMeasure()
} else {
console.log("放弃保存")
that.Unload = true
that.closeBLEConnection()
that.closeBluetoothAdapter()
uni.switchTab({
url: "/pages/index/index"
})
}
}
})
} else {
that.handleGetMeasure()
}
that.type30 = true
}
}
});
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
//
sendData() {
let that = this
let j = Number(26 + 3 + 6 + 1).toString(16)
let str = "A9002603060100" + j.substr(j.length - 2, 2) + "9A"
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.uuid1,
value: buf.buffer,
success: res => {
console.log('下发指令成功', res.errMsg)
},
fail: res => {
console.log("下发指令失败", res);
},
})
},
//
handleGetMeasure() {
let that = this
that.$model.getmeasure({
weight: that.weight,
imp: that.imp,
ecode: that.macAddr,
height: that.height,
familyid: that.info.familyid,
}).then(res => {
if (res.code == 0) {
that.$store.dispatch("getUserInfo", {
familyid: that.info.familyid,
});
that.$store.dispatch("getResult", {
birthday: that.info.birthday,
familyid: that.info.familyid,
height: that.height,
sex: that.info.sex,
});
that.$tools.msg("测量成功")
} else {
console.log("测量失败", res.message)
that.$tools.msg(res.message)
}
that.Unload = true
setTimeout(function() {
that.closeBLEConnection()
that.closeBluetoothAdapter()
uni.switchTab({
url: "/pages/index/index"
})
}, 200)
})
},
handleBack(ind) {
let that = this
that.text = ""
that.textH = ""
that.Unload = true
that.stopBluetoothDevicesDiscovery() //
that.closeBLEConnection()
that.closeBluetoothAdapter()
},
/**
* 断开蓝牙模块
*/
closeBluetoothAdapter() {
let that = this;
uni.closeBluetoothAdapter({
success: res => {
console.log('蓝牙模块关闭成功');
}
})
},
/**
* 断开蓝牙连接
*/
closeBLEConnection() {
var that = this;
uni.closeBLEConnection({
deviceId: that.deviceId,
success: res => {
console.log('断开蓝牙连接成功');
}
});
},
},
}
</script>
<style scoped lang="scss">
</style>

View File

@ -323,6 +323,21 @@
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#F9FAFC"
}
},
{
"path": "child/SG616BT",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false,
"navigationBarBackgroundColor": "#F9FAFC"
}
},
{
"path" : "child/B68T",
"style" :
{
"navigationBarTitleText" : ""
}
}
]
}],