no message

This commit is contained in:
kuaifan 2021-06-06 21:39:32 +08:00
parent 2222914005
commit 449af9c720
6 changed files with 60 additions and 43 deletions

View File

@ -65,20 +65,12 @@ export default {
} }
}, },
mounted() {
this.$store.state.dialogShow = true;
},
destroyed() { destroyed() {
this.$store.state.dialogShow = false; this.$store.state.dialogId = 0;
},
activated() {
this.$store.state.dialogShow = true;
}, },
deactivated() { deactivated() {
this.$store.state.dialogShow = false; this.$store.state.dialogId = 0;
}, },
computed: { computed: {
@ -132,10 +124,7 @@ export default {
content: msg content: msg
}); });
} }
this.$store.commit('spliceDialogMsg', { this.$store.commit('spliceDialogMsg', {id: tempId, data: ret === 1 ? data : null});
id: tempId,
data: ret === 1 ? data : null
});
} }
}); });
// //

View File

@ -92,6 +92,10 @@ export default {
} }
}, },
mounted() {
this.getMsg();
},
computed: { computed: {
...mapState(['projectDetail', 'projectChatShow']), ...mapState(['projectDetail', 'projectChatShow']),
}, },

View File

@ -26,7 +26,7 @@
</li> </li>
<li :class="['project-icon', projectChatShow ? 'active' : '']" @click="toggleBoolean('projectChatShow')"> <li :class="['project-icon', projectChatShow ? 'active' : '']" @click="toggleBoolean('projectChatShow')">
<Icon type="ios-chatbubbles" /> <Icon type="ios-chatbubbles" />
<Badge :count="projectMsgUnread"></Badge> <Badge :count="msgUnread"></Badge>
</li> </li>
<li class="project-icon"> <li class="project-icon">
<Dropdown @on-click="projectDropdown" transfer> <Dropdown @on-click="projectDropdown" transfer>
@ -836,6 +836,8 @@ export default {
data() { data() {
return { return {
nowTime: Math.round(new Date().getTime() / 1000), nowTime: Math.round(new Date().getTime() / 1000),
nowInterval: null,
searchText: '', searchText: '',
addShow: false, addShow: false,
@ -863,17 +865,25 @@ export default {
transferLoad: 0, transferLoad: 0,
} }
}, },
mounted() { mounted() {
setInterval(() => { this.nowInterval = setInterval(() => {
this.nowTime = Math.round(new Date().getTime() / 1000); this.nowTime = Math.round(new Date().getTime() / 1000);
}, 1000) }, 1000)
}, },
destroyed() {
clearInterval(this.nowInterval)
},
computed: { computed: {
...mapState([ ...mapState([
'userId', 'userId',
'dialogList',
'projectDetail', 'projectDetail',
'projectLoad', 'projectLoad',
'projectMsgUnread',
'projectChatShow', 'projectChatShow',
'projectListPanel', 'projectListPanel',
'taskMyShow', 'taskMyShow',
@ -881,6 +891,12 @@ export default {
'taskCompletedShow' 'taskCompletedShow'
]), ]),
msgUnread() {
const {dialogList, projectDetail} = this;
const dialog = dialogList.find(({id}) => id === projectDetail.dialog_id);
return dialog ? dialog.unread : 0;
},
panelTask() { panelTask() {
const {searchText} = this; const {searchText} = this;
return function (project_task) { return function (project_task) {
@ -963,6 +979,7 @@ export default {
} }
}, },
}, },
methods: { methods: {
addOpen(column_id) { addOpen(column_id) {
this.$set(this.addData, 'owner', this.userId); this.$set(this.addData, 'owner', this.userId);

View File

@ -72,7 +72,12 @@ export default {
this.dialogLoad++; this.dialogLoad++;
this.$store.commit("getDialogList", () => { this.$store.commit("getDialogList", () => {
this.dialogLoad--; this.dialogLoad--;
}) this.openDialogStorage();
});
},
activated() {
this.openDialogStorage();
}, },
computed: { computed: {
@ -97,9 +102,18 @@ export default {
methods: { methods: {
openDialog(dialog) { openDialog(dialog) {
this.$store.state.method.setStorage('messengerDialogId', dialog.id)
this.$store.commit('getDialogMsgList', dialog.id); this.$store.commit('getDialogMsgList', dialog.id);
}, },
openDialogStorage() {
let tmpId = this.$store.state.method.getStorageInt('messengerDialogId')
if (tmpId > 0) {
const dialog = this.dialogList.find(({id}) => id === tmpId);
dialog && this.openDialog(dialog);
}
},
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

@ -82,18 +82,18 @@ export default {
/** /**
* 获取项目列表 * 获取项目列表
* @param state * @param state
* @param completeCallback * @param afterCallback
*/ */
getProjectList(state, completeCallback) { getProjectList(state, afterCallback) {
if (state.userId === 0) { if (state.userId === 0) {
state.projectList = []; state.projectList = [];
typeof completeCallback === "function" && completeCallback(); typeof afterCallback === "function" && afterCallback();
return; return;
} }
$A.apiAjax({ $A.apiAjax({
url: 'project/lists', url: 'project/lists',
complete: () => { after: () => {
typeof completeCallback === "function" && completeCallback(); typeof afterCallback === "function" && afterCallback();
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
@ -212,13 +212,13 @@ export default {
/** /**
* 获取对话列表 * 获取对话列表
* @param state * @param state
* @param completeCallback * @param afterCallback
*/ */
getDialogList(state, completeCallback) { getDialogList(state, afterCallback) {
$A.apiAjax({ $A.apiAjax({
url: 'dialog/lists', url: 'dialog/lists',
complete: () => { after: () => {
typeof completeCallback === "function" && completeCallback(); typeof afterCallback === "function" && afterCallback();
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
@ -241,6 +241,7 @@ export default {
}, },
success: ({ret, data, msg}) => { success: ({ret, data, msg}) => {
if (ret === 1) { if (ret === 1) {
if (state.dialogId === data.id) data.unread = 0;
let index = state.dialogList.findIndex(({id}) => id == data.id); let index = state.dialogList.findIndex(({id}) => id == data.id);
if (index > -1) { if (index > -1) {
state.dialogList.splice(index, 1, data); state.dialogList.splice(index, 1, data);
@ -250,18 +251,6 @@ export default {
} }
} }
}); });
$A.apiAjax({
url: 'dialog/lists',
complete: () => {
typeof completeCallback === "function" && completeCallback();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
state.dialogList = data.data;
}
}
});
}, },
/** /**
@ -374,6 +363,12 @@ export default {
if (index > -1) { if (index > -1) {
if (data) { if (data) {
state.dialogMsgList.splice(index, 1, state.method.cloneJSON(data)); state.dialogMsgList.splice(index, 1, state.method.cloneJSON(data));
// 是最后一条消息时更新对话 last_msg
console.log(data);
if (state.dialogMsgList.length - 1 == index) {
const dialog = state.dialogList.find(({id}) => id == data.dialog_id);
if (dialog) dialog.last_msg = data;
}
} else { } else {
state.dialogMsgList.splice(index, 1); state.dialogMsgList.splice(index, 1);
} }
@ -489,7 +484,7 @@ export default {
} else { } else {
that.commit('getDialogOne', dialog_id); that.commit('getDialogOne', dialog_id);
} }
if (!state.dialogShow || state.dialogId !== dialog_id) state.dialogMsgUnread++; if (state.dialogId !== dialog_id) state.dialogMsgUnread++;
} }
})(msgDetail, this); })(msgDetail, this);
} }

View File

@ -13,7 +13,7 @@ const method = {
return typeof value === "string" || typeof value === "number" ? value : def; return typeof value === "string" || typeof value === "number" ? value : def;
}, },
getStorageNumber(key, def = 0) { getStorageInt(key, def = 0) {
let value = this.storage(key); let value = this.storage(key);
return typeof value === "number" ? value : def; return typeof value === "number" ? value : def;
}, },
@ -182,11 +182,9 @@ state.projectDetail = {
project_column: [], project_column: [],
project_user: [] project_user: []
}; };
state.projectMsgUnread = 0;
// 会话消息 // 会话消息
state.dialogId = 0; state.dialogId = 0;
state.dialogShow = false;
state.dialogList = []; state.dialogList = [];
state.dialogDetail = {}; state.dialogDetail = {};
state.dialogMsgLoad = 0; state.dialogMsgLoad = 0;