第一版
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
const app = getApp();
|
||||
import $ from "../../utils/request";
|
||||
|
||||
Page({
|
||||
data: {
|
||||
deviceConnect: false,
|
||||
|
||||
deviceInfo: null
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.getDevice();
|
||||
this.initBluetooth();
|
||||
|
||||
app.globalData.ppScale.plugin.bus.subscribe("deviceConnect", (res) => {
|
||||
console.log('deviceInfo ===》deviceConnect', res);
|
||||
|
||||
app.globalData.ppScale.plugin.ScaleAction.startDataProgress();
|
||||
app.globalData.ppScale.activeProtocol = app.globalData.ppScale.plugin.ScaleAction.getActiveProtocol();
|
||||
|
||||
app.globalData.ppScale.activeProtocol.codeUpdateMTU((res) => {
|
||||
console.log("deviceInfo ===》codeUpdateMTU", res);
|
||||
|
||||
$.ajax("weighingScale/list/device", {}, "GET", false).then((res) => {
|
||||
if(res.result && res.result.length) {
|
||||
let deviceConnect = res.result.some(item => item.macAddress === app.globalData.ppScale.device.mac);
|
||||
if(deviceConnect) {
|
||||
this.setData({
|
||||
deviceConnect: true
|
||||
})
|
||||
} else {
|
||||
app.globalData.ppScale.plugin.Blue.disconnect();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 初始化蓝牙
|
||||
initBluetooth() {
|
||||
wx.openBluetoothAdapter({
|
||||
success: () => {
|
||||
this.getDeviceSettingList();
|
||||
},
|
||||
fail: (err) => {
|
||||
if (err.errCode === 10001) {
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: "请打开手机蓝牙",
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
async refreshToken(fn, flag) {
|
||||
let bodyToken = wx.getStorageSync('bodyToken');
|
||||
let bodyTokenTime = wx.getStorageSync('bodyTokenTime');
|
||||
if (!bodyToken || bodyTokenTime * 1000 < +new Date() || flag) {
|
||||
let res = await app.globalData.ppScale.plugin.refreshToken({
|
||||
url: "https://uniquehealth.lefuenergy.com",
|
||||
data: {
|
||||
"appKey": app.globalData.ppScale.options.key,
|
||||
"appSecret": app.globalData.ppScale.options.secret
|
||||
}
|
||||
});
|
||||
if (res.data.code == 200) {
|
||||
wx.setStorageSync('bodyToken', res.data.data.token);
|
||||
wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
|
||||
fn();
|
||||
}
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
},
|
||||
getDeviceSettingList() {
|
||||
let bodyToken = wx.getStorageSync("bodyToken");
|
||||
app.globalData.ppScale.plugin.getDeviceSettingList({
|
||||
url: "https://uniquehealth.lefuenergy.com",
|
||||
data: {
|
||||
appKey: app.globalData.ppScale.options.key
|
||||
},
|
||||
header: {
|
||||
"token": bodyToken,
|
||||
"Accept-Language": wx.getStorageSync("lang") || 'zh'
|
||||
}
|
||||
}).then((res) => {
|
||||
if (res.data.code == 200) {
|
||||
app.globalData.ppScale.plugin.Blue.setDeviceSetting(res.data.data);
|
||||
app.globalData.ppScale.device.setting = res.data.data;
|
||||
let deviceNames = res.data.data.map(item => item.deviceName);
|
||||
app.globalData.ppScale.plugin.Blue.start(deviceNames, false);
|
||||
app.globalData.ppScale.plugin.bus.subscribe("devicesList", (res_) => {
|
||||
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
|
||||
app.globalData.ppScale.plugin.Blue.createBLEConnection(res_[0]);
|
||||
});
|
||||
} else if (res.data.code == 401 || res.data.code == 4008) {
|
||||
// 401 token过期 / 4008 token为空
|
||||
// 重新请求token解析数据
|
||||
this.refreshToken(() => {
|
||||
this.getDeviceSettingList();
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 获取已经绑定的设备列表
|
||||
getDevice() {
|
||||
let params = {};
|
||||
$.ajax("weighingScale/list/device", params, "GET", false).then((res) => {
|
||||
this.setData({
|
||||
deviceInfo: res.result[0]
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
delDevice() {
|
||||
if(this.data.deviceConnect) {
|
||||
app.globalData.ppScale.activeProtocol.codeClearDeviceData("00", (res) => {
|
||||
console.log("deviceInfo === codeClearDeviceData", res);
|
||||
|
||||
let scaleDeviceId = app.globalData.ppScale.device.mac.replace(/:/g, '');
|
||||
let params = {
|
||||
equipmentCode: scaleDeviceId,
|
||||
};
|
||||
$.ajax("weighingScale/del/device", params, "POST", true, "正在解绑设备...").then(res_ => {
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: res_.message,
|
||||
})
|
||||
setTimeout(() => {
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
}, 1500);
|
||||
});
|
||||
})
|
||||
} else {
|
||||
wx.showToast({
|
||||
icon: "none",
|
||||
title: "删除失败,请靠近设备并点亮后再试"
|
||||
})
|
||||
this.initBluetooth();
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
app.globalData.ppScale.plugin.Blue.stop();
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "设备详情",
|
||||
"disableScroll": true
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<view class="device">
|
||||
<view>
|
||||
<image src="/images/deviceInfo/device.png" />
|
||||
</view>
|
||||
<view>
|
||||
<view>{{deviceInfo.equipmentName}}</view>
|
||||
<view>型号:{{deviceInfo.type}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="info">
|
||||
<view>
|
||||
<view>设备名称</view>
|
||||
<view>{{deviceInfo.equipmentName}}</view>
|
||||
</view>
|
||||
<view>
|
||||
<view>设备SN</view>
|
||||
<view>{{deviceInfo.equipmentCode}}</view>
|
||||
</view>
|
||||
<view>
|
||||
<view>配置Wi-Fi</view>
|
||||
<view class="arrowAfter" style="padding-right: 30rpx;">{{deviceInfo.wifiName}}</view>
|
||||
</view>
|
||||
<view>
|
||||
<view>成员</view>
|
||||
<view>{{deviceInfo.subUserNum}}人</view>
|
||||
</view>
|
||||
<view>
|
||||
<view>MAC地址</view>
|
||||
<view>{{deviceInfo.macAddress}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="btn" bind:tap="delDevice">删除设备</view>
|
||||
@@ -0,0 +1,94 @@
|
||||
page {
|
||||
padding: 30rpx 30rpx 0;
|
||||
}
|
||||
|
||||
.device {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
padding: 30rpx;
|
||||
box-sizing: border-box;
|
||||
border-radius: 24rpx;
|
||||
margin-bottom: 24rpx;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.device>view:first-of-type {
|
||||
width: 180rpx;
|
||||
height: 180rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.device>view:last-of-type {
|
||||
flex: 1;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.device>view:last-of-type>view:first-of-type {
|
||||
color: #252535;
|
||||
width: 100%;
|
||||
height: 40rpx;
|
||||
font-weight: bold;
|
||||
font-size: 40rpx;
|
||||
line-height: 40rpx;
|
||||
margin-bottom: 22rpx;
|
||||
}
|
||||
|
||||
.device>view:last-of-type>view:last-of-type {
|
||||
color: #808080;
|
||||
width: 100%;
|
||||
height: 26rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 26rpx;
|
||||
}
|
||||
|
||||
.info {
|
||||
width: 100%;
|
||||
border-radius: 24rpx;
|
||||
margin-bottom: 88rpx;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.info>view {
|
||||
width: 100%;
|
||||
height: 120rpx;
|
||||
padding: 0 30rpx;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1rpx solid #EAECF1;
|
||||
}
|
||||
|
||||
.info>view:last-of-type {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.info>view>view {
|
||||
height: 120rpx;
|
||||
font-size: 30rpx;
|
||||
line-height: 120rpx;
|
||||
}
|
||||
|
||||
.info>view>view:first-of-type {
|
||||
color: #252535;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.info>view>view:last-of-type {
|
||||
color: #808080;
|
||||
}
|
||||
|
||||
.btn {
|
||||
color: #FFFFFF;
|
||||
width: 580rpx;
|
||||
height: 88rpx;
|
||||
margin: 0 auto;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
line-height: 88rpx;
|
||||
text-align: center;
|
||||
border-radius: 44rpx;
|
||||
background-color: #1385FA;
|
||||
}
|
||||
Reference in New Issue
Block a user