增加昵称和部门的匹配

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

@@ -12,10 +12,16 @@
</view>
<view class="u-nav-slot" slot="center">
<view class="chating_info" :class="{ chating_info_single: isSingle }">
<view class="conversation_info">
<view class="title">{{ storeCurrentConversation.showName }}</view>
<view v-if="!isSingle && !isNotify" class="sub_title"
>{{ groupMemberCount }}
<view
class="conversation_info"
:style="isSingle ? 'flex-direction: column; align-items: center;' : 'flex-direction: row; align-items: center; justify-content: center;'"
>
<view class="title" :style="isSingle ? 'text-align: center;' : ''">{{ storeCurrentConversation.showName }}</view>
<view v-if="isSingle && storeCurrentConversation.deptName" style="margin-top:6rpx; display: flex; justify-content: center;">
<text :style="{backgroundColor: storeCurrentConversation.color, color: '#fff', padding: '2px 10px', borderRadius: '10px', fontSize: '20rpx', display: 'inline-block', textAlign: 'center'}">{{ storeCurrentConversation.deptName }}</text>
</view>
<view v-if="!isSingle && !isNotify" class="sub_title" style="margin-left: 8rpx;">
{{ groupMemberCount }}
</view>
</view>
</view>

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 &&

View File

@@ -19,7 +19,12 @@
>
<text>{{ formattedMessageTime }}</text>
<text style="margin-left: 2rpx; margin-right: 2rpx">{{ "" }}</text>
<text v-if="!isSingle">{{ source.senderNickname }}</text>
<text v-if="!isSingle">
{{ source.senderNickname }}
</text>
<template v-if="!isSingle && source.deptName">
<text class="dept_name" :style="{backgroundColor: source.color, color: '#fff', padding: '2px 8px', borderRadius: '8px', fontSize: '20rpx', marginLeft: '8rpx'}">{{ source.deptName }}</text>
</template>
</view>
<view class="message_send_state_box">
<view
@@ -384,6 +389,13 @@ export default {
font-size: 0.85rem;
color: #666;
margin-bottom: 6rpx;
align-items: center;
.dept_name {
display: inline-block;
line-height: 1.2;
vertical-align: middle;
margin-left: 8rpx;
}
}
.message_content_wrap {