|
|
@@ -12,8 +12,8 @@
|
|
|
<!-- 设备卡片 -->
|
|
|
<view class="device-card" v-for="(item, index) in list" :key="index" @click="goDeviceInfo(item)">
|
|
|
<image class="device-icon" src="/static/device/device1.png" mode="heightFix"></image>
|
|
|
- <text class="device-name">{{item.deviceName}}</text>
|
|
|
-
|
|
|
+ <text class="device-name">{{item.deviceName || item.name}}</text>
|
|
|
+
|
|
|
</view>
|
|
|
<!-- 添加设备卡片 -->
|
|
|
<view class="device-card add-card" @click="goAddDevice">
|
|
|
@@ -33,7 +33,7 @@
|
|
|
<script>
|
|
|
import ayToast from '@/components/ay-toast/ay-toast.nvue'
|
|
|
import { useBleStore } from '@/stores/ble'
|
|
|
-import { getDeviceList } from '@/utils/api/device.js'
|
|
|
+import { getDeviceList } from '@/utils/api/device'
|
|
|
|
|
|
export default {
|
|
|
components: {
|
|
|
@@ -56,18 +56,21 @@ export default {
|
|
|
this.init()
|
|
|
},
|
|
|
methods: {
|
|
|
- /** 从后端获取设备列表 */
|
|
|
async init() {
|
|
|
try {
|
|
|
- const data = await getDeviceList()
|
|
|
- if (data && data.length > 0) {
|
|
|
- this.list = data
|
|
|
- } else {
|
|
|
- this.list = []
|
|
|
+ const deviceList= await getDeviceList()
|
|
|
+ console.log("后台返回列表list",deviceList)
|
|
|
+ if(deviceList&&deviceList.length>0){
|
|
|
+ for (var index = 0; index < deviceList.length; index++) {
|
|
|
+ deviceList[index].deviceId=deviceList[index].deviceCode;
|
|
|
+ }
|
|
|
+ console.log("后台返回列表list有值")
|
|
|
+ this.list = deviceList
|
|
|
}
|
|
|
+ // 同步到本地缓存,供其他页面使用
|
|
|
+ uni.setStorageSync('deviceList', this.list)
|
|
|
} catch (e) {
|
|
|
- console.error('获取设备列表失败', e)
|
|
|
- this.list = []
|
|
|
+ console.log('获取设备列表失败:', e)
|
|
|
}
|
|
|
},
|
|
|
goAddDevice() {
|
|
|
@@ -77,7 +80,7 @@ export default {
|
|
|
},
|
|
|
goDeviceInfo(item) {
|
|
|
uni.navigateTo({
|
|
|
- url: '/pages/device/deviceInfo/deviceInfo?name=' + encodeURIComponent(item.deviceName || '') + '&deviceId=' + encodeURIComponent(item.deviceCode || '') + '&rssi='
|
|
|
+ url: '/pages/device/deviceInfo/deviceInfo?name=' + encodeURIComponent(item.deviceName || item.name || '') + '&deviceId=' + encodeURIComponent(item.deviceId || '') + '&deviceCode=' + encodeURIComponent(item.deviceCode || '') + '&rssi=' + encodeURIComponent(item.RSSI || '')
|
|
|
})
|
|
|
},
|
|
|
/** 如果设备已连接,实时获取RSSI并更新缓存 */
|
|
|
@@ -89,6 +92,15 @@ export default {
|
|
|
deviceId: connectedDeviceId,
|
|
|
success: (res) => {
|
|
|
console.log('实时RSSI更新:', res.RSSI)
|
|
|
+ // 更新列表中对应设备的RSSI
|
|
|
+ const idx = this.list.findIndex(item => item.deviceId === connectedDeviceId)
|
|
|
+ if (idx !== -1) {
|
|
|
+ this.list[idx].RSSI = res.RSSI
|
|
|
+ // 同步更新到本地缓存
|
|
|
+ try {
|
|
|
+ uni.setStorageSync('deviceList', this.list)
|
|
|
+ } catch (e) {}
|
|
|
+ }
|
|
|
},
|
|
|
fail: (err) => {
|
|
|
console.log('获取RSSI失败:', err)
|