From f6301affbaf066ea13fc13a2a95d52894954eea0 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Tue, 1 Apr 2025 09:54:08 +0800 Subject: [PATCH] list --- pages/connectedDevice/connectedDevice.js | 2 +- pages/searchDevice/searchDevice.js | 64 +++++++++++++----------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/pages/connectedDevice/connectedDevice.js b/pages/connectedDevice/connectedDevice.js index 8587778..d5b0f1b 100644 --- a/pages/connectedDevice/connectedDevice.js +++ b/pages/connectedDevice/connectedDevice.js @@ -53,7 +53,7 @@ Page({ }) setTimeout(() => { wx.navigateBack({ - delta: 1 + delta: 2 }) }, 1500); }); diff --git a/pages/searchDevice/searchDevice.js b/pages/searchDevice/searchDevice.js index 5ccf479..822736b 100644 --- a/pages/searchDevice/searchDevice.js +++ b/pages/searchDevice/searchDevice.js @@ -164,37 +164,45 @@ Page({ this.setData({ devicesList: res }); + this.selectDevice(); }); + }, + + selectDevice() { 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" - }) + if(this.data.devicesList && this.data.devicesList.length) { + 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 + }) + } + }) + } } 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 - }) - } - }) + this.selectDevice(); } - }, 3000) + }, 3000); } }) \ No newline at end of file