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