App({ onLaunch() { this.initPpScale(); }, globalData: { // wx.request 请求的服务地址 wxRequestUrl: "https://device.shuziweidao.com/gateway/", // wxRequestUrl: "http://192.168.10.173:8889/", // 秤的所有信息 ppScale: { plugin: null, activeProtocol: null, domain: "http://device.shuziweidao.com:80/gateway", // domain: "http://192.168.10.173:8889", wifi: { ssid: "", password: "" }, options: { key: "lefudc91611833e18d94", secret: "eQ50JYimMp0X7uhNLj6D3lTEk4TUUvEG7dvaqKM9t1U=" }, device: { setting: [{ "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 }, { "advLength": 999, "calorieStatus": 0, "createBy": null, "deviceAccuracyType": 2, "deviceCalcuteType": 4, "deviceConnectType": 2, "deviceFuncType": 65759, "deviceName": "CF636_G", "devicePowerType": 3, "deviceProtocolType": 3, "deviceType": 1, "deviceUnitType": "0,1,2", "id": 216, "imgUrl": null, "macAddressStart": 6, "remark": null, "sign": "FF", "status": 0, "uhStatus": 1, "updateBy": null }, { "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 }], // 即将要搜索周边秤的配置 list: [], // 根据配置搜索到秤的列表 mac: null, // 选中的设备mac地址/SN码 name: "", // 设备名称 connection: null, // 默认选中连接的设备 } } }, initPpScale() { this.globalData.ppScale.plugin = requirePlugin('ppScale-plugin'); this.globalData.ppScale.plugin.bus.subscribe("connectState", (res) => { console.log("app.js ===> connectState", res); // 连接失败则重新连接 if (res == this.globalData.ppScale.plugin.BLUE_STATE.CONNECTFAILED) { this.reconnectDevice() } wx.hideLoading(); }); this.globalData.ppScale.plugin.bus.subscribe("deviceWillDisconnect", (res) => { console.log("app.js ===> deviceWillDisconnect", res); this.reconnectDevice(); }) }, reconnectDevice() { this.globalData.ppScale.plugin.Blue.disconnect((disres) => { if (disres.errCode == 0) { this.globalData.ppScale.plugin.Blue.startBluetoothDevicesDiscovery(); } else { this.reconnectDevice(); } }) } })