From 3979d36285f90b5f3d266bb8817edf991d19a0b0 Mon Sep 17 00:00:00 2001 From: "will.zhang" Date: Wed, 8 Jan 2025 10:26:17 +0800 Subject: [PATCH] sort by id --- src/store/modules/device.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/store/modules/device.ts b/src/store/modules/device.ts index 196d6ba8..0a7b2f88 100644 --- a/src/store/modules/device.ts +++ b/src/store/modules/device.ts @@ -180,6 +180,20 @@ export const deviceStore = defineStore("device", { } } } + // 将已连接的设备排在前面 + this.records.sort((a, b) => { + if (a.status === EnumDeviceStatus.CONNECTED) { + return -1 + } + if (b.status === EnumDeviceStatus.CONNECTED) { + return 1 + } + // 剩下的按照id排序 + if (a.id && b.id && a.id < b.id) { + return -1 + } + return 0 + }) // 更新并保存 if (changed) { await this.sync()