This commit is contained in:
fan 2023-05-23 15:50:56 +08:00
commit 88b9ac889c
2 changed files with 77 additions and 69 deletions

View File

@ -94,10 +94,10 @@ export default {
doorList: [], doorList: [],
memberData: {}, memberData: {},
treeData: [{ treeData: [{
labelName: '行调', labelName: 'NCC调度',
children: [] children: []
}, { }, {
labelName: 'NCC调度', labelName: '行调',
children: [] children: []
}, { }, {
labelName: '车站值班员', labelName: '车站值班员',
@ -197,14 +197,14 @@ export default {
val.forEach(item => { val.forEach(item => {
const device = this.$store.getters['map/getDeviceByCode'](item.deviceCode); const device = this.$store.getters['map/getDeviceByCode'](item.deviceCode);
switch (item.type) { switch (item.type) {
case 'DISPATCHER':
this.memberData[item.id].labelName = '行调' + (item.name || '');
dispatcherList.push(this.memberData[item.id]);
break;
case 'NCC_DISPATCHER': case 'NCC_DISPATCHER':
this.memberData[item.id].labelName = 'NCC调度' + (item.name || ''); this.memberData[item.id].labelName = 'NCC调度' + (item.name || '');
nccDispatcherList.push(this.memberData[item.id]); nccDispatcherList.push(this.memberData[item.id]);
break; break;
case 'DISPATCHER':
this.memberData[item.id].labelName = '行调' + (item.name || '');
dispatcherList.push(this.memberData[item.id]);
break;
case 'ELECTRIC_DISPATCHER': case 'ELECTRIC_DISPATCHER':
this.memberData[item.id].labelName = '电力调度' + (item.name || ''); this.memberData[item.id].labelName = '电力调度' + (item.name || '');
electricDispatcherList.push(this.memberData[item.id]); electricDispatcherList.push(this.memberData[item.id]);
@ -277,13 +277,13 @@ export default {
} }
}); });
this.treeData = [{ this.treeData = [{
labelName: '行调',
id: 'dispatcher',
children: dispatcherList
}, {
labelName: 'NCC调度', labelName: 'NCC调度',
id: 'nccDispatcher', id: 'nccDispatcher',
children: nccDispatcherList children: nccDispatcherList
}, {
labelName: '行调',
id: 'dispatcher',
children: dispatcherList
}, { }, {
labelName: '车站值班员', labelName: '车站值班员',
id: 'stationSupervisor', id: 'stationSupervisor',

View File

@ -39,7 +39,7 @@
</div> </div>
</div> </div>
<div class="middleMain"> <div class="middleMain">
<div v-for="(item, index) in chatList" :ref="'dom'+index" :key="index" class="row pointer" :class="{active: item.id === id || (privateChatId && privateChatId == getPrivateChatId(item))}" @click="groupClick(item)" @contextmenu.prevent.stop="showMenu($event,item)"> <div v-for="(item, index) in groupList" :ref="'dom'+index" :key="index" class="row pointer" :class="{active: item.id === id || (privateChatId && privateChatId == getPrivateChatId(item))}" @click="groupClick(item)" @contextmenu.prevent.stop="showMenu($event,item)">
<div v-show="false" class="groupIcon"> <div v-show="false" class="groupIcon">
<img :src="getImgUrl(item.imageUrl)" alt=""> <img :src="getImgUrl(item.imageUrl)" alt="">
</div> </div>
@ -77,7 +77,8 @@ import ChatContent from './chatContent';
import EditGroup from './editGroup'; import EditGroup from './editGroup';
import AddressBook from './addressBook'; import AddressBook from './addressBook';
import PopMenu from '@/components/PopMenu'; import PopMenu from '@/components/PopMenu';
import DialogMember from './dialogMember.vue'; import DialogMember from './dialogMember';
import { objectIsEqual } from '@/utils/date';
export default { export default {
name: 'ChatDialog', name: 'ChatDialog',
components: { components: {
@ -111,8 +112,7 @@ export default {
id: 0, // id id: 0, // id
privateChatId: '', // id privateChatId: '', // id
memberTreeData: [], memberTreeData: [],
menu: [], // menu: [] //
noIdChatList: [] // id
}; };
}, },
computed: { computed: {
@ -136,13 +136,6 @@ export default {
}); });
return n; return n;
}, },
chatList() {
const list = JSON.parse(JSON.stringify(this.groupList));
this.noIdChatList.forEach(item => {
list.splice(item.sortIndex, 0, item);
});
return list;
},
activeMessageList() { activeMessageList() {
let list = []; let list = [];
const find = this.groupList.find(item => { const find = this.groupList.find(item => {
@ -174,11 +167,7 @@ export default {
watch: { watch: {
'$store.state.socket.simulationReset': function (val) { // 仿 '$store.state.socket.simulationReset': function (val) { // 仿
if (val) { if (val) {
this.id = 0; this.initGroupList();
this.privateChatId = '';
this.$store.dispatch('socket/resetConversationGroup');
this.groupList = [];
this.noIdChatList = [];
} }
}, },
'$store.state.socket.conversationGroup.MESSAGE': function(val) { '$store.state.socket.conversationGroup.MESSAGE': function(val) {
@ -200,8 +189,15 @@ export default {
this.$message.success(`${val.messageTips}`); this.$message.success(`${val.messageTips}`);
} }
if (val.id) { if (val.id) {
this.groupList.push({...val, messageList: [], imageUrl: ''}); const findIndex = this.groupList.findIndex(ii => {
this.removeNoIdItem(); return val.id == ii.id || (val.type == 'PRIVATE_CHAT' && ii.type == 'PRIVATE_CHAT' && this.isEqualMember(ii.memberList, val.memberList));
});
const obj = {...val, messageList: [], imageUrl: ''};
if (findIndex > -1) {
this.groupList.splice(findIndex, 1, obj);
} else {
this.groupList.push(obj);
}
} }
}, },
'$store.state.socket.conversationGroup.UPDATE_NAME': function(val) { '$store.state.socket.conversationGroup.UPDATE_NAME': function(val) {
@ -242,8 +238,14 @@ export default {
totalUnread() { totalUnread() {
this.$emit('setTotalUnread', this.totalUnread); this.$emit('setTotalUnread', this.totalUnread);
}, },
myMemberId() { myMemberId: {
this.getGroupList(); handler(val) {
this.initGroupList();
if (val) {
this.getGroupList();
}
},
immediate: true
}, },
memberList () { memberList () {
this.getTreeData(); this.getTreeData();
@ -254,9 +256,9 @@ export default {
created() { created() {
this.getTreeData(); this.getTreeData();
this.getBaseInfo(); this.getBaseInfo();
this.getGroupList();
}, },
beforeDestroy() { beforeDestroy() {
this.initGroupList();
this.handleClose(); this.handleClose();
}, },
methods: { methods: {
@ -364,14 +366,13 @@ export default {
}, },
sendPrivateMsg(item) { sendPrivateMsg(item) {
this.privateChatId = item.id; this.privateChatId = item.id;
const findIndex = this.chatList.findIndex(ii => { const findIndex = this.groupList.findIndex(ii => {
return ii.type == 'PRIVATE_CHAT' && ii.memberList.find(m => { return ii.type == 'PRIVATE_CHAT' && ii.memberList.find(m => {
return m.memberId == item.id; return m.memberId == item.id;
}); });
}); });
let index = findIndex; let index = findIndex;
if (findIndex < 0) { if (findIndex < 0) {
const sortIndex = this.chatList.length;
const obj = { const obj = {
creatorId: this.myMemberId, creatorId: this.myMemberId,
leaderId: this.myMemberId, leaderId: this.myMemberId,
@ -379,33 +380,22 @@ export default {
{memberId: this.myMemberId, connect: false, role: 'Leader'}, {memberId: this.myMemberId, connect: false, role: 'Leader'},
{memberId: item.id, connect: false, role: 'Leader'} {memberId: item.id, connect: false, role: 'Leader'}
], ],
sortIndex: sortIndex,
messageList: [], messageList: [],
name: item.labelName, name: item.labelName,
type: 'PRIVATE_CHAT' type: 'PRIVATE_CHAT'
}; };
this.noIdChatList.push(obj); this.groupList.push(obj);
index = sortIndex; index = this.groupList.length - 1;
} }
this.scrollTop(index); this.scrollTop(index);
this.id = 0; this.id = 0;
this.tabActive = 0; this.tabActive = 0;
}, },
removeNoIdItem() { initGroupList() {
const list = []; this.id = 0;
this.noIdChatList.forEach(item => { this.privateChatId = '';
const find = this.groupList.find(ii => { this.$store.dispatch('socket/resetConversationGroup');
return ii.type == 'PRIVATE_CHAT' && ii.memberList[0].memberId == item.memberList[0].memberId && ii.memberList[1].memberId == item.memberList[1].memberId; this.groupList = [];
});
if (!find) {
list.push(item);
} else {
if (this.privateChatId && this.privateChatId == this.getPrivateChatId(find)) {
this.groupClick(find);
}
}
});
this.noIdChatList = list;
}, },
getTreeData() { getTreeData() {
const val = this.memberList; const val = this.memberList;
@ -431,14 +421,14 @@ export default {
val.forEach(item => { val.forEach(item => {
const device = this.$store.getters['map/getDeviceByCode'](item.deviceCode); const device = this.$store.getters['map/getDeviceByCode'](item.deviceCode);
switch (item.type) { switch (item.type) {
case 'DISPATCHER':
this.memberData[item.id].labelName = '行调' + (item.name || '');
dispatcherList.push(this.memberData[item.id]);
break;
case 'NCC_DISPATCHER': case 'NCC_DISPATCHER':
this.memberData[item.id].labelName = 'NCC调度' + (item.name || ''); this.memberData[item.id].labelName = 'NCC调度' + (item.name || '');
nccDispatcherList.push(this.memberData[item.id]); nccDispatcherList.push(this.memberData[item.id]);
break; break;
case 'DISPATCHER':
this.memberData[item.id].labelName = '行调' + (item.name || '');
dispatcherList.push(this.memberData[item.id]);
break;
case 'ELECTRIC_DISPATCHER': case 'ELECTRIC_DISPATCHER':
this.memberData[item.id].labelName = '电力调度' + (item.name || ''); this.memberData[item.id].labelName = '电力调度' + (item.name || '');
electricDispatcherList.push(this.memberData[item.id]); electricDispatcherList.push(this.memberData[item.id]);
@ -509,13 +499,13 @@ export default {
} }
}); });
this.memberTreeData = [{ this.memberTreeData = [{
labelName: '行调',
id: 'dispatcher',
children: dispatcherList
}, {
labelName: 'NCC调度', labelName: 'NCC调度',
id: 'nccDispatcher', id: 'nccDispatcher',
children: nccDispatcherList children: nccDispatcherList
}, {
labelName: '行调',
id: 'dispatcher',
children: dispatcherList
}, { }, {
labelName: '车站值班员', labelName: '车站值班员',
id: 'stationSupervisor', id: 'stationSupervisor',
@ -625,9 +615,9 @@ export default {
let name = ''; let name = '';
if (item.type == 'PRIVATE_CHAT') { if (item.type == 'PRIVATE_CHAT') {
let mId = ''; let mId = '';
if (item.memberList[0].memberId == this.myMemberId) { if (item.memberList[0].memberId == this.myMemberId && item.memberList[1]) {
mId = item.memberList[1].memberId; mId = item.memberList[1].memberId;
} else if (item.memberList[1].memberId == this.myMemberId) { } else {
mId = item.memberList[0].memberId; mId = item.memberList[0].memberId;
} }
const node = this.memberData[mId]; const node = this.memberData[mId];
@ -692,11 +682,19 @@ export default {
}, },
getGroupList() { getGroupList() {
getGroupList(this.groupId).then(res => { getGroupList(this.groupId).then(res => {
this.groupList = res.data; res.data.forEach(item => {
const findIndex = this.groupList.findIndex(ii => {
return item.id == ii.id || (item.type == 'PRIVATE_CHAT' && ii.type == 'PRIVATE_CHAT' && this.isEqualMember(ii.memberList, item.memberList));
});
if (findIndex > -1) {
this.groupList.splice(findIndex, 1, item);
} else {
this.groupList.push(item);
}
});
if (this.groupList && this.groupList[0] && !this.id && !this.privateChatId) { if (this.groupList && this.groupList[0] && !this.id && !this.privateChatId) {
this.id = this.groupList[0].id; this.id = this.groupList[0].id;
} }
this.removeNoIdItem();
}); });
}, },
getImgUrl(url) { getImgUrl(url) {
@ -711,6 +709,17 @@ export default {
filterClick(index) { filterClick(index) {
this.filterActive = index; this.filterActive = index;
}, },
isEqualMember(list1, list2) {
const m1 = {};
const m2 = {};
list1.forEach(item => {
m1[item.memberId] = item.memberId;
});
list2.forEach(item => {
m2[item.memberId] = item.memberId;
});
return objectIsEqual(m1, m2);
},
groupClick(item) { groupClick(item) {
this.id = item.id || 0; this.id = item.id || 0;
if (item.type == 'GROUP_CHAT') { if (item.type == 'GROUP_CHAT') {
@ -722,12 +731,11 @@ export default {
}, },
getPrivateChatId(item) { getPrivateChatId(item) {
let pId = ''; let pId = '';
if (item.type == 'PRIVATE_CHAT' && item.leaderId == this.myMemberId) { if (item.type == 'PRIVATE_CHAT') {
const find = item.memberList.find(ii => { if (item.memberList[0].memberId == this.myMemberId && item.memberList[1]) {
return ii.memberId != this.myMemberId; pId = item.memberList[1].memberId;
}); } else {
if (find) { pId = item.memberList[0].memberId;
pId = find.memberId;
} }
} }
return pId; return pId;