Skip to content

Commit

Permalink
Merge pull request #42 from kkroid/sort_by_id
Browse files Browse the repository at this point in the history
将已连接的设备排在最前面,剩下的按照id排序
  • Loading branch information
modstart authored Jan 8, 2025
2 parents b1b4036 + 3979d36 commit 90f2691
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/store/modules/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 90f2691

Please sign in to comment.