【功能完善】商城: 客服会话排序调整

pull/584/head
puhui999 2024-11-10 13:09:27 +08:00
parent 8b0778ca0c
commit 33a4100ed4
1 changed files with 7 additions and 41 deletions

View File

@ -63,48 +63,14 @@ export const useMallKefuStore = defineStore('mall-kefu', {
}
},
conversationSort() {
// TODO @puhui9991逻辑上先按照置顶、再按照最后消息时间2感觉写的有一丢丢小复杂发给大模型看看有没可能简化哈。
this.conversationList.sort((obj1, obj2) => {
// 如果 obj1.adminPinned 为 trueobj2.adminPinned 为 falseobj1 应该排在前面
if (obj1.adminPinned && !obj2.adminPinned) {
return -1
// 按置顶属性和最后消息时间排序
this.conversationList.sort((a, b) => {
// 按照置顶排序,置顶的会在前面
if (a.adminPinned !== b.adminPinned) {
return a.adminPinned ? -1 : 1
}
// 如果 obj1.adminPinned 为 falseobj2.adminPinned 为 trueobj2 应该排在前面
if (!obj1.adminPinned && obj2.adminPinned) {
return 1
}
// 如果 obj1.adminPinned 和 obj2.adminPinned 都为 true比较 adminUnreadMessageCount 的值
if (obj1.adminPinned && obj2.adminPinned) {
return obj1.adminUnreadMessageCount - obj2.adminUnreadMessageCount
}
// 如果 obj1.adminPinned 和 obj2.adminPinned 都为 false比较 adminUnreadMessageCount 的值
if (!obj1.adminPinned && !obj2.adminPinned) {
return obj1.adminUnreadMessageCount - obj2.adminUnreadMessageCount
}
// 如果 obj1.adminPinned 为 trueobj2.adminPinned 为 true且 b 都大于 0比较 adminUnreadMessageCount 的值
if (
obj1.adminPinned &&
obj2.adminPinned &&
obj1.adminUnreadMessageCount > 0 &&
obj2.adminUnreadMessageCount > 0
) {
return obj1.adminUnreadMessageCount - obj2.adminUnreadMessageCount
}
// 如果 obj1.adminPinned 为 falseobj2.adminPinned 为 false且 b 都大于 0比较 adminUnreadMessageCount 的值
if (
!obj1.adminPinned &&
!obj2.adminPinned &&
obj1.adminUnreadMessageCount > 0 &&
obj2.adminUnreadMessageCount > 0
) {
return obj1.adminUnreadMessageCount - obj2.adminUnreadMessageCount
}
return 0
// 按照最后消息时间排序,最近的会在前面
return (b.lastMessageTime as unknown as number) - (a.lastMessageTime as unknown as number)
})
}
}