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() {
this.$store.state.dialogShow = false;
},
activated() {
this.$store.state.dialogShow = true;
this.$store.state.dialogId = 0;
},
deactivated() {
this.$store.state.dialogShow = false;
this.$store.state.dialogId = 0;
},
computed: {
@ -132,10 +124,7 @@ export default {
content: msg
});
}
this.$store.commit('spliceDialogMsg', {
id: tempId,
data: ret === 1 ? data : null
});
this.$store.commit('spliceDialogMsg', {id: tempId, data: ret === 1 ? data : null});
}
});
//

View File

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

View File

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

View File

@ -72,7 +72,12 @@ export default {
this.dialogLoad++;
this.$store.commit("getDialogList", () => {
this.dialogLoad--;
})
this.openDialogStorage();
});
},
activated() {
this.openDialogStorage();
},
computed: {
@ -97,9 +102,18 @@ export default {
methods: {
openDialog(dialog) {
this.$store.state.method.setStorage('messengerDialogId', 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) {
let time = Math.round(new Date(date).getTime() / 1000),
string = '';

View File

@ -82,18 +82,18 @@ export default {
/**
* 获取项目列表
* @param state
* @param completeCallback
* @param afterCallback
*/
getProjectList(state, completeCallback) {
getProjectList(state, afterCallback) {
if (state.userId === 0) {
state.projectList = [];
typeof completeCallback === "function" && completeCallback();
typeof afterCallback === "function" && afterCallback();
return;
}
$A.apiAjax({
url: 'project/lists',
complete: () => {
typeof completeCallback === "function" && completeCallback();
after: () => {
typeof afterCallback === "function" && afterCallback();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
@ -212,13 +212,13 @@ export default {
/**
* 获取对话列表
* @param state
* @param completeCallback
* @param afterCallback
*/
getDialogList(state, completeCallback) {
getDialogList(state, afterCallback) {
$A.apiAjax({
url: 'dialog/lists',
complete: () => {
typeof completeCallback === "function" && completeCallback();
after: () => {
typeof afterCallback === "function" && afterCallback();
},
success: ({ret, data, msg}) => {
if (ret === 1) {
@ -241,6 +241,7 @@ export default {
},
success: ({ret, data, msg}) => {
if (ret === 1) {
if (state.dialogId === data.id) data.unread = 0;
let index = state.dialogList.findIndex(({id}) => id == data.id);
if (index > -1) {
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 (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 {
state.dialogMsgList.splice(index, 1);
}
@ -489,7 +484,7 @@ export default {
} else {
that.commit('getDialogOne', dialog_id);
}
if (!state.dialogShow || state.dialogId !== dialog_id) state.dialogMsgUnread++;
if (state.dialogId !== dialog_id) state.dialogMsgUnread++;
}
})(msgDetail, this);
}

View File

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