no message

This commit is contained in:
kuaifan 2021-06-08 11:51:34 +08:00
parent 0f658c724a
commit 9f4ee54c8f
3 changed files with 24 additions and 28 deletions

View File

@ -14,6 +14,7 @@
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"css-loader": "^0.28.7", "css-loader": "^0.28.7",
"file-loader": "^2.0.0", "file-loader": "^2.0.0",
"internal-ip": "^6.2.0",
"jquery": "^3.5.1", "jquery": "^3.5.1",
"laravel-mix": "^6.0.6", "laravel-mix": "^6.0.6",
"lodash": "^4.17.19", "lodash": "^4.17.19",

View File

@ -79,7 +79,7 @@ export default {
}, },
mounted() { mounted() {
this.parsingRead() this.msgRead()
}, },
computed: { computed: {
@ -94,13 +94,11 @@ export default {
} }
}, },
watch: { methods: {
msgData() { msgRead() {
this.parsingRead() this.$store.commit('wsMsgRead', this.msgData);
}
}, },
methods: {
popperShow() { popperShow() {
$A.apiAjax({ $A.apiAjax({
url: 'dialog/msg/readlist', url: 'dialog/msg/readlist',
@ -115,13 +113,6 @@ export default {
}); });
}, },
parsingRead() {
const {userid, r, id} = this.msgData;
if (userid == this.userId) return;
if ($A.isJson(r) && r.read_at) return;
this.$store.commit('wsMsgRead', id);
},
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

@ -306,12 +306,6 @@ 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;
} }
@ -484,9 +478,6 @@ export default {
if (dialog_id === state.dialogId) { if (dialog_id === state.dialogId) {
let index = state.dialogMsgList.findIndex(({id}) => id === data.id); let index = state.dialogMsgList.findIndex(({id}) => id === data.id);
if (index === -1) { if (index === -1) {
if (state.dialogMsgList.length >= 200) {
state.dialogMsgList.splice(0, 1);
}
state.dialogMsgList.push(data); state.dialogMsgList.push(data);
} else { } else {
state.dialogMsgList.splice(index, 1, data); state.dialogMsgList.splice(index, 1, data);
@ -507,7 +498,7 @@ export default {
if (mode === "add") { if (mode === "add") {
if (dialog) { if (dialog) {
// 新增未读数 // 新增未读数
if (state.dialogId !== dialog_id) dialog.unread++; if (data.userid !== state.userId) dialog.unread++;
// 移动到首位 // 移动到首位
const index = state.dialogList.findIndex(({id}) => id == dialog_id); const index = state.dialogList.findIndex(({id}) => id == dialog_id);
if (index > -1) { if (index > -1) {
@ -517,7 +508,7 @@ export default {
} }
} }
// 新增总未读数 // 新增总未读数
if (state.dialogId !== dialog_id) state.dialogMsgUnread++; if (data.userid !== state.userId) state.dialogMsgUnread++;
} }
})(msgDetail, this); })(msgDetail, this);
} }
@ -559,10 +550,23 @@ export default {
/** /**
* 发送已阅消息 * 发送已阅消息
* @param state * @param state
* @param msgId * @param msgData
*/ */
wsMsgRead(state, msgId) { wsMsgRead(state, msgData) {
state.wsReadWaitList.push(msgId); if (msgData.userid == state.userId) return;
if (typeof msgData.r === "undefined") msgData.r = {};
//
const {id, dialog_id, r} = msgData;
if (!r.read_at) {
r.read_at = $A.formatDate('Y-m-d H:i:s');
let dialog = state.dialogList.find(({id}) => id == dialog_id);
if (dialog && dialog.unread > 0) {
dialog.unread--
state.dialogMsgUnread--;
}
}
//
state.wsReadWaitList.push(id);
clearTimeout(state.wsReadTimeout); clearTimeout(state.wsReadTimeout);
state.wsReadTimeout = setTimeout(() => { state.wsReadTimeout = setTimeout(() => {
this.commit('wsSend', { this.commit('wsSend', {