no message

This commit is contained in:
kuaifan 2021-06-06 20:41:10 +08:00
parent 6579a59207
commit 2222914005
4 changed files with 106 additions and 101 deletions

View File

@ -267,27 +267,13 @@ export default {
}, },
computed: { computed: {
...mapState(['wsMsg', 'dialogShow', 'dialogMsgUnread', 'projectList']), ...mapState(['dialogMsgUnread', 'projectList']),
}, },
watch: { watch: {
'$route' (route) { '$route' (route) {
this.curPath = route.path; this.curPath = route.path;
}, },
/**
* 收到新消息
* @param msg
*/
wsMsg(msg) {
const {type, mode} = msg;
if (type === "dialog" && mode === "add") {
if (this.dialogShow) {
return;
}
this.$store.state.dialogMsgUnread++;
}
},
}, },
methods: { methods: {
@ -297,7 +283,7 @@ export default {
value: [], value: [],
}, { }, {
label: this.$L('软件开发'), label: this.$L('软件开发'),
value: [this.$L('产品规划'),this.$L('前端开发'),this.$L('后端开发'),this.$L('测试'),this.$L('发布'),this.$L('其它')], value: [this.$L('产品规划'), this.$L('前端开发'), this.$L('后端开发'), this.$L('测试'), this.$L('发布'), this.$L('其它')],
}, { }, {
label: this.$L('产品开发'), label: this.$L('产品开发'),
value: [this.$L('产品计划'), this.$L('正在设计'), this.$L('正在研发'), this.$L('测试'), this.$L('准备发布'), this.$L('发布成功')], value: [this.$L('产品计划'), this.$L('正在设计'), this.$L('正在研发'), this.$L('测试'), this.$L('准备发布'), this.$L('发布成功')],

View File

@ -63,18 +63,20 @@ export default {
components: {DialogWrapper}, components: {DialogWrapper},
data() { data() {
return { return {
dialogLoad: 0,
dialogKey: '', dialogKey: '',
dialogList: [], dialogLoad: 0,
} }
}, },
mounted() { mounted() {
this.getDialogLists(); this.dialogLoad++;
this.$store.commit("getDialogList", () => {
this.dialogLoad--;
})
}, },
computed: { computed: {
...mapState(['dialogId', 'dialogShow', 'wsMsg']), ...mapState(['dialogId', 'dialogList']),
dialogLists() { dialogLists() {
const {dialogKey} = this; const {dialogKey} = this;
@ -93,79 +95,11 @@ export default {
}, },
}, },
watch: {
/**
* 收到新消息
* @param msg
*/
wsMsg(msg) {
const {type, mode, data} = msg;
if (type === "dialog" && mode === "add") {
if (this.dialogShow && this.dialogId == data.dialog_id) {
return;
}
let dialog = this.dialogList.find(({id}) => id == data.dialog_id);
if (dialog) {
this.$set(dialog, 'unread', dialog.unread + 1);
this.$set(dialog, 'last_msg', data);
} else {
this.getDialogOne(data.dialog_id)
}
}
},
/**
* 打开对话标记已读
* @param dialog_id
*/
dialogId(dialog_id) {
let dialog = this.dialogList.find(({id}) => id == dialog_id);
if (dialog && dialog.unread > 0) {
this.$store.state.dialogMsgUnread-= dialog.unread;
this.$set(dialog, 'unread', 0);
}
}
},
methods: { methods: {
openDialog(dialog) { openDialog(dialog) {
this.$store.commit('getDialogMsgList', dialog.id); this.$store.commit('getDialogMsgList', dialog.id);
}, },
getDialogLists() {
this.dialogLoad++;
$A.apiAjax({
url: 'dialog/lists',
complete: () => {
this.dialogLoad--;
},
success: ({ret, data, msg}) => {
if (ret === 1) {
this.dialogList = data.data;
}
}
});
},
getDialogOne(dialog_id) {
$A.apiAjax({
url: 'dialog/one',
data: {
dialog_id,
},
success: ({ret, data, msg}) => {
if (ret === 1) {
let index = this.dialogList.findIndex(({id}) => id == data.id);
if (index > -1) {
this.dialogList.splice(index, 1, data);
} else {
this.dialogList.unshift(data)
}
}
}
});
},
formatTime(date) { formatTime(date) {
let time = Math.round(new Date(date).getTime() / 1000), let time = Math.round(new Date(date).getTime() / 1000),
string = ''; string = '';

View File

@ -1,5 +1,3 @@
import state from "./state";
export default { export default {
/** /**
* 切换Boolean变量 * 切换Boolean变量
@ -211,6 +209,61 @@ export default {
}); });
}, },
/**
* 获取对话列表
* @param state
* @param completeCallback
*/
getDialogList(state, completeCallback) {
$A.apiAjax({
url: 'dialog/lists',
complete: () => {
typeof completeCallback === "function" && completeCallback();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
state.dialogList = data.data;
}
}
});
},
/**
* 获取单个对话
* @param state
* @param dialog_id
*/
getDialogOne(state, dialog_id) {
$A.apiAjax({
url: 'dialog/one',
data: {
dialog_id,
},
success: ({ret, data, msg}) => {
if (ret === 1) {
let index = state.dialogList.findIndex(({id}) => id == data.id);
if (index > -1) {
state.dialogList.splice(index, 1, data);
} else {
state.dialogList.unshift(data)
}
}
}
});
$A.apiAjax({
url: 'dialog/lists',
complete: () => {
typeof completeCallback === "function" && completeCallback();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
state.dialogList = data.data;
}
}
});
},
/** /**
* 获取对话消息 * 获取对话消息
* @param state * @param state
@ -237,6 +290,12 @@ export default {
} }
state.dialogId = dialog_id; state.dialogId = dialog_id;
// //
let dialog = state.dialogList.find(({id}) => id == dialog_id);
if (dialog && dialog.unread > 0) {
state.dialogMsgUnread-= dialog.unread;
dialog.unread = 0;
}
//
if (state.cacheDialog[dialog_id + "::load"]) { if (state.cacheDialog[dialog_id + "::load"]) {
return; return;
} }
@ -395,19 +454,44 @@ export default {
} }
}); });
if (type === "dialog") { if (type === "dialog") {
const msgData = msgDetail.data; // 更新消息
const dialog_id = msgData.dialog_id; (function (msg) {
const {data} = msg;
const {dialog_id} = data;
if (dialog_id === state.dialogId) { if (dialog_id === state.dialogId) {
let index = state.dialogMsgList.findIndex(({id}) => id === msgData.id); let index = state.dialogMsgList.findIndex(({id}) => id === data.id);
if (index === -1) { if (index === -1) {
if (state.dialogMsgList.length >= 200) { if (state.dialogMsgList.length >= 200) {
state.dialogMsgList.splice(0, 1); state.dialogMsgList.splice(0, 1);
} }
state.dialogMsgList.push(msgData); state.dialogMsgList.push(data);
} else { } else {
state.dialogMsgList.splice(index, 1, msgData); state.dialogMsgList.splice(index, 1, data);
} }
} }
})(msgDetail);
// 更新对话
(function (msg, that) {
const {mode, data} = msg;
const {dialog_id} = data;
if (mode === "add") {
let dialog = state.dialogList.find(({id}) => id == dialog_id);
if (dialog) {
dialog.last_msg = data;
if (state.dialogId !== dialog_id) dialog.unread++;
// 移动到首位
const index = state.dialogList.findIndex(({id}) => id == dialog_id);
if (index > -1) {
const tmp = state.dialogList[index];
state.dialogList.splice(index, 1);
state.dialogList.unshift(tmp);
}
} else {
that.commit('getDialogOne', dialog_id);
}
if (!state.dialogShow || state.dialogId !== dialog_id) state.dialogMsgUnread++;
}
})(msgDetail, this);
} }
break break
} }

View File

@ -187,6 +187,7 @@ state.projectMsgUnread = 0;
// 会话消息 // 会话消息
state.dialogId = 0; state.dialogId = 0;
state.dialogShow = false; state.dialogShow = false;
state.dialogList = [];
state.dialogDetail = {}; state.dialogDetail = {};
state.dialogMsgLoad = 0; state.dialogMsgLoad = 0;
state.dialogMsgList = []; state.dialogMsgList = [];