第一版
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
const app = getApp();
|
||||
|
||||
Page({
|
||||
data: {
|
||||
getDeviceSetting: false,
|
||||
|
||||
initText: "",
|
||||
devicesList: []
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.initBluetooth();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (this.data.getDeviceSetting) {
|
||||
this.getDeviceSettingList();
|
||||
}
|
||||
},
|
||||
|
||||
// 初始化蓝牙
|
||||
initBluetooth() {
|
||||
this.setData({
|
||||
initText: "正在初始化蓝牙..."
|
||||
})
|
||||
wx.openBluetoothAdapter({
|
||||
success: () => {
|
||||
this.setData({
|
||||
initText: "蓝牙初始化成功"
|
||||
})
|
||||
this.getDeviceSettingList();
|
||||
},
|
||||
fail: (err) => {
|
||||
this.setData({
|
||||
initText: "蓝牙初始化失败"
|
||||
})
|
||||
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() {
|
||||
this.setData({
|
||||
initText: "获取设备配置中..."
|
||||
})
|
||||
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) {
|
||||
this.setData({
|
||||
initText: "设备搜索中..."
|
||||
});
|
||||
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_) => {
|
||||
console.log("searchDevice ===> devicesList", res_);
|
||||
this.setData({
|
||||
getDeviceSetting: false,
|
||||
initText: "设备搜索完成"
|
||||
});
|
||||
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
|
||||
app.globalData.ppScale.device.list = res_;
|
||||
app.globalData.ppScale.device.connection = res_[0];
|
||||
wx.navigateTo({
|
||||
url: "/pages/connectedDevice/connectedDevice"
|
||||
})
|
||||
});
|
||||
} else if (res.data.code == 401 || res.data.code == 4008) {
|
||||
// 401 token过期 / 4008 token为空
|
||||
// 重新请求token解析数据
|
||||
this.refreshToken(() => {
|
||||
this.getDeviceSettingList();
|
||||
}, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {},
|
||||
"navigationBarTitleText": "搜索设备",
|
||||
"disableScroll": true
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<view class="icon">
|
||||
<view>
|
||||
<image src="/images/searchDevice/icon.png" />
|
||||
</view>
|
||||
<view></view>
|
||||
<view style="animation-delay: 1s;"></view>
|
||||
</view>
|
||||
|
||||
<view class="description">
|
||||
<view>{{initText}}</view>
|
||||
<view>请轻轻踩秤,保证屏幕亮起</view>
|
||||
</view>
|
||||
@@ -0,0 +1,78 @@
|
||||
page {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding-top: 120rpx;
|
||||
box-sizing: border-box;
|
||||
background-color: #FFFFFF;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 556rpx;
|
||||
height: 556rpx;
|
||||
position: relative;
|
||||
margin: 0 auto 120rpx;
|
||||
}
|
||||
|
||||
.icon>view:nth-of-type(1) {
|
||||
position: absolute;
|
||||
z-index: 3;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
margin: auto;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.icon>view:nth-of-type(2),
|
||||
.icon>view:nth-of-type(3) {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
margin: auto;
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
border-radius: 50%;
|
||||
animation: expand 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes expand {
|
||||
0% {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
background-color: #3194FB;
|
||||
}
|
||||
100% {
|
||||
width: 556rpx;
|
||||
height: 556rpx;
|
||||
background-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.description>view:nth-of-type(1) {
|
||||
color: #252535;
|
||||
width: 100%;
|
||||
height: 36rpx;
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
line-height: 36rpx;
|
||||
text-align: center;
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
.description>view:nth-of-type(2) {
|
||||
color: #808080;
|
||||
width: 100%;
|
||||
height: 30rpx;
|
||||
font-size: 30rpx;
|
||||
line-height: 30rpx;
|
||||
text-align: center;
|
||||
}
|
||||
Reference in New Issue
Block a user