优化了一部分代码

This commit is contained in:
17792275749
2025-04-30 15:33:24 +08:00
parent 230490b995
commit 2fc1f423bd
5 changed files with 172 additions and 18 deletions
+2 -2
View File
@@ -143,7 +143,7 @@ Page({
app.globalData.ppScale.device.list = this.data.devicesList;
if(this.data.devicesList.length === 1) {
app.globalData.ppScale.device.connection = this.data.devicesList[0];
wx.navigateTo({
wx.redirectTo({
url: "/pages/connectedDevice/connectedDevice"
})
} else {
@@ -153,7 +153,7 @@ Page({
alertText: "请选择你要使用的设备",
success: (res) => {
app.globalData.ppScale.device.connection = this.data.devicesList[res.tapIndex];
wx.navigateTo({
wx.redirectTo({
url: "/pages/connectedDevice/connectedDevice"
})
},
+93 -8
View File
@@ -8,6 +8,8 @@ Page({
initBluetooth: "0",
customerType: "1",
deviceInfo: null,
seviceList: [],
userInfo: null,
id: "",
realname: "",
@@ -34,6 +36,12 @@ Page({
index: 20,
data: Array.from({ length: 100 - 50 + 1 }, (_, i) => i + 50)
},
connectedDevice: {
code: "",
color: "",
message: ""
}
},
onLoad(options) {
@@ -57,6 +65,7 @@ Page({
if (userInfo && options.initBluetooth === "1") {
let [year, month, day] = userInfo.birthday.split("-");
this.setData({
userInfo: userInfo,
realname: userInfo.realname,
["sex.index"]: this.data.sex.data.findIndex(item => {return item.id === userInfo.sex}),
birthday: {
@@ -70,10 +79,17 @@ Page({
}
}
if(options.initBluetooth === "1") {
this.getDevice();
this.initBluetooth();
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
console.log('userInfo ===》deviceConnect', res);
this.setData({
connectedDevice: {
code: "",
color: "#2AC79F",
message: "等待设备回应"
}
})
app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
@@ -82,7 +98,12 @@ Page({
console.log("userInfo ===》codeUpdateMTU", res);
this.setData({
deviceConnect: true
deviceConnect: true,
connectedDevice: {
code: "",
color: "#2AC79F",
message: "已连接"
}
})
});
});
@@ -91,14 +112,28 @@ Page({
// 获取已经绑定的设备列表
getDevice() {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "获取设备列表"
}
})
let params = {};
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
if(res.result && res.result.length) {
this.setData({
deviceInfo: res.result[0]
})
this.initBluetooth();
this.getDeviceSettingList();
} else {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "未绑定设备"
}
})
wx.showModal({
title: "提示",
content: "当前暂未绑定设备,需要绑定吗?",
@@ -121,12 +156,26 @@ Page({
// 初始化蓝牙
initBluetooth() {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "初始化蓝牙"
}
})
wx.openBluetoothAdapter({
success: () => {
this.getDeviceSettingList();
this.getDevice();
},
fail: (err) => {
if (err.errCode === 10001) {
this.setData({
connectedDevice: {
code: "",
color: "#F24439",
message: "初始化蓝牙失败"
}
})
wx.showModal({
title: "提示",
content: "请打开手机蓝牙",
@@ -137,20 +186,57 @@ Page({
},
getDeviceSettingList() {
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "获取配置信息"
}
})
let seviceList = [];
app.globalData.ppScale.device.setting.map(item => {
if(this.data.deviceInfo.type === item.deviceName) {
seviceList.push(item);
}
})
this.setData({
seviceList: seviceList,
connectedDevice: {
code: "",
color: "#2AC79F",
message: "配置获取成功"
}
})
if(seviceList && seviceList.length) {
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "开始搜索设备"
}
})
app.globalData.ppScale.plugin.Blue.start(seviceList[0].deviceName, false);
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res) => {
console.log("deviceInfo ===> devicesList", res);
let fIndex = res.findIndex(item => item.deviceId === this.data.deviceInfo.deviceId);
this.setData({
connectedDevice: {
code: "",
color: "#808080",
message: "设备搜索中"
}
})
if (fIndex >= 0) {
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
this.setData({
connectedDevice: {
code: "",
color: "#2AC79F",
message: "连接中"
}
})
app.globalData.ppScale.plugin.Blue.createBLEConnection(res[fIndex]);
return;
}
@@ -239,7 +325,7 @@ Page({
icon: "none",
title: "请靠近设备并点亮后再试"
})
this.getDeviceSettingList();
app.globalData.ppScale.plugin.Blue.start(this.data.seviceList[0].deviceName, false);
return false;
}
if(!realname) {
@@ -323,7 +409,7 @@ Page({
gender: res_.result.sex, //
height: res_.result.height, //
isAthleteMode: 0,
currentWeight: res_.result.weight, //
currentWeight: res_.result.weight, //
deviceHeaderIndex: 0,
targetWeight: "",
idealWeight: "",
@@ -418,8 +504,7 @@ Page({
icon: "none",
title: "删除失败,请靠近设备并点亮后再试"
})
app.globalData.ppScale.plugin.Blue.stop();
this.getDeviceSettingList();
app.globalData.ppScale.plugin.Blue.start(this.data.seviceList[0].deviceName, false);
}
},
+17 -2
View File
@@ -1,4 +1,15 @@
<view class="tips">请填写和完善您家人的健康信息,将用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。我们会严格保护您的家庭信息安全。</view>
<block wx:if="{{initBluetooth === '1'}}">
<view class="device">
<view>
<view>{{deviceInfo && deviceInfo.equipmentName ? deviceInfo.equipmentName : '获取中...'}}</view>
<view>型号:{{deviceInfo && deviceInfo.type ? deviceInfo.type : '获取中...'}}</view>
</view>
<view>
<view style="background-color: {{connectedDevice.color}};"></view>
<view style="color: {{connectedDevice.color}};">{{connectedDevice.message}}</view>
</view>
</view>
</block>
<view class="form">
<view>
@@ -61,6 +72,10 @@
<view class="btn" bind:tap="submit">确定</view>
<block wx:if="{{!userInfo && !id}}">
<view class="tips">请填写和完善您家人的健康信息,将用于计算身体数据及运动卡路里消耗等,以便准确的分析数据。我们会严格保护您的家庭信息安全。</view>
</block>
<block wx:if="{{customerType === '0' && id}}">
<view class="delBtn" bind:tap="delUser">删除该档案</view>
</block>
</block>
+55 -6
View File
@@ -2,14 +2,54 @@ page {
padding: 30rpx 30rpx 0;
}
.tips {
color: #77849E;
.device {
width: 100%;
font-size: 26rpx;
line-height: 40rpx;
margin-bottom: 40rpx;
padding: 0 30rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
padding: 35rpx 40rpx;
border-radius: 24rpx;
box-sizing: border-box;
margin-bottom: 24rpx;
background-color: #FFFFFF;
justify-content: space-between;
}
.device>view:nth-of-type(1)>view:nth-of-type(1) {
color: #252535;
height: 32rpx;
font-weight: bold;
font-size: 32rpx;
line-height: 32rpx;
margin-bottom: 22rpx;
}
.device>view:nth-of-type(1)>view:nth-of-type(2) {
color: #808080;
height: 26rpx;
font-size: 26rpx;
line-height: 26rpx;
}
.device>view:nth-of-type(2) {
height: 28rpx;
display: flex;
flex-wrap: nowrap;
align-items: center;
}
.device>view:nth-of-type(2)>view:nth-of-type(1) {
width: 14rpx;
height: 14rpx;
border-radius: 50%;
}
.device>view:nth-of-type(2)>view:nth-of-type(2) {
height: 28rpx;
font-weight: bold;
font-size: 28rpx;
line-height: 28rpx;
padding-left: 8rpx;
}
.form {
@@ -83,6 +123,15 @@ page {
background-color: #1385FA;
}
.tips {
color: #77849E;
width: 100%;
font-size: 26rpx;
line-height: 40rpx;
padding: 0 30rpx;
box-sizing: border-box;
}
.delBtn {
color: #1385FA;
width: 580rpx;