增加昵称和部门的匹配

This commit is contained in:
砂糖
2025-07-14 17:02:56 +08:00
parent 66169c3620
commit 4c0df26d3d
7 changed files with 168 additions and 8 deletions

View File

@@ -16,7 +16,7 @@
<view id="scroll_wrap">
<u-loadmore nomoreText="" :status="loadMoreStatus" />
<view
v-for="item in storeHistoryMessageList"
v-for="item in messageListWithDept"
:key="item.clientMsgID"
>
<message-item-render
@@ -36,6 +36,7 @@
<script>
import { mapGetters, mapActions } from "vuex";
import MessageItemRender from "./MessageItem/index.vue";
import { withDeptName } from '@/util/withDeptName';
export default {
name: "",
@@ -58,6 +59,7 @@ export default {
messageLoadState: {
loading: false,
},
messageListWithDept: [],
};
},
computed: {
@@ -75,11 +77,39 @@ export default {
return this.messageLoadState.loading ? "loading" : "loadmore";
},
},
watch: {
storeHistoryMessageList: {
handler: 'updateMessageListWithDept',
immediate: true,
deep: true
}
},
mounted() {
this.loadMessageList();
},
methods: {
...mapActions("message", ["getHistoryMesageList"]),
async updateMessageListWithDept() {
// 取所有发送者昵称
const allSenders = this.storeHistoryMessageList.map(item => ({ showName: item.senderNickname }));
// 获取部门信息
const deptInfoArr = await withDeptName(allSenders);
// 构建映射
const deptMap = {};
deptInfoArr.forEach((obj, idx) => {
if (obj.deptName) {
deptMap[this.storeHistoryMessageList[idx].sendID] = {
deptName: obj.deptName,
color: obj.color
};
}
});
// 合并到消息
this.messageListWithDept = this.storeHistoryMessageList.map(msg => {
const dept = deptMap[msg.sendID];
return dept ? { ...msg, deptName: dept.deptName, color: dept.color } : { ...msg };
});
},
messageItemRender(clientMsgID) {
if (
this.initFlag &&