Skip to content

Commit 90f2691

Browse files
authored
Merge pull request #42 from kkroid/sort_by_id
将已连接的设备排在最前面,剩下的按照id排序
2 parents b1b4036 + 3979d36 commit 90f2691

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/store/modules/device.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,20 @@ export const deviceStore = defineStore("device", {
180180
}
181181
}
182182
}
183+
// 将已连接的设备排在前面
184+
this.records.sort((a, b) => {
185+
if (a.status === EnumDeviceStatus.CONNECTED) {
186+
return -1
187+
}
188+
if (b.status === EnumDeviceStatus.CONNECTED) {
189+
return 1
190+
}
191+
// 剩下的按照id排序
192+
if (a.id && b.id && a.id < b.id) {
193+
return -1
194+
}
195+
return 0
196+
})
183197
// 更新并保存
184198
if (changed) {
185199
await this.sync()

0 commit comments

Comments
 (0)