兼容 CF568_G
This commit is contained in:
@@ -5,13 +5,13 @@ App({
|
|||||||
|
|
||||||
globalData: {
|
globalData: {
|
||||||
// wx.request 请求的服务地址
|
// wx.request 请求的服务地址
|
||||||
wxRequestUrl: "http://device.shuziweidao.com:8889/",
|
wxRequestUrl: "https://device.shuziweidao.com/gateway/",
|
||||||
|
|
||||||
// 秤的所有信息
|
// 秤的所有信息
|
||||||
ppScale: {
|
ppScale: {
|
||||||
plugin: null,
|
plugin: null,
|
||||||
activeProtocol: null,
|
activeProtocol: null,
|
||||||
domain: "http://device.shuziweidao.com:8889", // http://192.168.10.173:8889
|
domain: "https://device.shuziweidao.com/gateway", // http://192.168.10.173:8889
|
||||||
wifi: {
|
wifi: {
|
||||||
ssid: "",
|
ssid: "",
|
||||||
password: ""
|
password: ""
|
||||||
|
|||||||
@@ -42,11 +42,6 @@
|
|||||||
"provider": "wx0ffb48417ce6345c"
|
"provider": "wx0ffb48417ce6345c"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"permission": {
|
|
||||||
"scope.userLocation": {
|
|
||||||
"desc": "获取 WiFi 列表需要使用您的位置信息"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sitemapLocation": "sitemap.json",
|
"sitemapLocation": "sitemap.json",
|
||||||
"lazyCodeLoading": "requiredComponents"
|
"lazyCodeLoading": "requiredComponents"
|
||||||
}
|
}
|
||||||
@@ -44,69 +44,157 @@ Page({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async refreshToken(fn, flag) {
|
// async refreshToken(fn, flag) {
|
||||||
let bodyToken = wx.getStorageSync('bodyToken');
|
// let bodyToken = wx.getStorageSync('bodyToken');
|
||||||
let bodyTokenTime = wx.getStorageSync('bodyTokenTime');
|
// let bodyTokenTime = wx.getStorageSync('bodyTokenTime');
|
||||||
if (!bodyToken || bodyTokenTime * 1000 < +new Date() || flag) {
|
// if (!bodyToken || bodyTokenTime * 1000 < +new Date() || flag) {
|
||||||
let res = await app.globalData.ppScale.plugin.refreshToken({
|
// let res = await app.globalData.ppScale.plugin.refreshToken({
|
||||||
url: "https://uniquehealth.lefuenergy.com",
|
// url: "https://uniquehealth.lefuenergy.com",
|
||||||
data: {
|
// data: {
|
||||||
"appKey": app.globalData.ppScale.options.key,
|
// "appKey": app.globalData.ppScale.options.key,
|
||||||
"appSecret": app.globalData.ppScale.options.secret
|
// "appSecret": app.globalData.ppScale.options.secret
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
if (res.data.code == 200) {
|
// if (res.data.code == 200) {
|
||||||
wx.setStorageSync('bodyToken', res.data.data.token);
|
// wx.setStorageSync('bodyToken', res.data.data.token);
|
||||||
wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
|
// wx.setStorageSync('bodyTokenTime', res.data.data.expireTime);
|
||||||
fn();
|
// fn();
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
fn();
|
// 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) {
|
||||||
|
// this.refreshToken(() => {
|
||||||
|
// this.getDeviceSettingList();
|
||||||
|
// }, true);
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// },
|
||||||
|
|
||||||
getDeviceSettingList() {
|
getDeviceSettingList() {
|
||||||
this.setData({
|
this.setData({
|
||||||
initText: "获取设备配置中..."
|
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);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
let seviceList = [{
|
||||||
|
advLength: 999,
|
||||||
|
calorieStatus: 0,
|
||||||
|
createBy: null,
|
||||||
|
deviceAccuracyType: 2,
|
||||||
|
deviceCalcuteType: 4,
|
||||||
|
deviceConnectType: 2,
|
||||||
|
deviceFuncType: 223,
|
||||||
|
deviceName: "CF577",
|
||||||
|
devicePowerType: 3,
|
||||||
|
deviceProtocolType: 3,
|
||||||
|
deviceType: 1,
|
||||||
|
deviceUnitType: "0,1,11",
|
||||||
|
id: 51,
|
||||||
|
imgUrl: null,
|
||||||
|
macAddressStart: 6,
|
||||||
|
remark: null,
|
||||||
|
sign: "FF",
|
||||||
|
status: 0,
|
||||||
|
uhStatus: 1,
|
||||||
|
updateBy: null
|
||||||
|
}, {
|
||||||
|
"advLength": 999,
|
||||||
|
"calorieStatus": 0,
|
||||||
|
"createBy": null,
|
||||||
|
"deviceAccuracyType": 2,
|
||||||
|
"deviceCalcuteType": 3,
|
||||||
|
"deviceConnectType": 2,
|
||||||
|
"deviceFuncType": 223,
|
||||||
|
"deviceName": "CF568_G",
|
||||||
|
"devicePowerType": 3,
|
||||||
|
"deviceProtocolType": 3,
|
||||||
|
"deviceType": 1,
|
||||||
|
"deviceUnitType": "0,1,11",
|
||||||
|
"id": 65,
|
||||||
|
"imgUrl": null,
|
||||||
|
"macAddressStart": 6,
|
||||||
|
"remark": null,
|
||||||
|
"sign": "FF",
|
||||||
|
"status": 0,
|
||||||
|
"uhStatus": 1,
|
||||||
|
"updateBy": null
|
||||||
|
}];
|
||||||
|
app.globalData.ppScale.plugin.Blue.setDeviceSetting(seviceList);
|
||||||
|
app.globalData.ppScale.device.setting = seviceList;
|
||||||
|
let deviceNames = seviceList.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({
|
||||||
|
devicesList: res
|
||||||
|
});
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
this.setData({
|
||||||
|
getDeviceSetting: false,
|
||||||
|
initText: "设备搜索完成"
|
||||||
|
});
|
||||||
|
app.globalData.ppScale.plugin.Blue.stopBluetoothDevicesDiscovery();
|
||||||
|
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({
|
||||||
|
url: "/pages/connectedDevice/connectedDevice"
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let itemLists = this.data.devicesList.map(item => item.name);
|
||||||
|
wx.showActionSheet({
|
||||||
|
itemList: itemLists,
|
||||||
|
alertText: "请选择你要使用的设备",
|
||||||
|
success: (res) => {
|
||||||
|
app.globalData.ppScale.device.connection = this.data.devicesList[res.tapIndex];
|
||||||
|
wx.navigateTo({
|
||||||
|
url: "/pages/connectedDevice/connectedDevice"
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail: () => {
|
||||||
|
wx.navigateBack({
|
||||||
|
delta: 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, 3000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -9,4 +9,8 @@
|
|||||||
<view class="description">
|
<view class="description">
|
||||||
<view>{{initText}}</view>
|
<view>{{initText}}</view>
|
||||||
<view>请轻轻踩秤,保证屏幕亮起</view>
|
<view>请轻轻踩秤,保证屏幕亮起</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<block wx:for="{{devicesList}}" wx:key="index">
|
||||||
|
<view>{{item.name}}</view>
|
||||||
|
</block>
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
|
||||||
"projectname": "weightScaleMini",
|
"projectname": "bodyWeight",
|
||||||
"setting": {
|
"setting": {
|
||||||
"compileHotReLoad": true,
|
"compileHotReLoad": true,
|
||||||
"urlCheck": false,
|
"urlCheck": false,
|
||||||
"bigPackageSizeSupport": true
|
"bigPackageSizeSupport": true
|
||||||
},
|
},
|
||||||
"libVersion": "3.7.10"
|
"libVersion": "3.7.11"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user