no message
This commit is contained in:
parent
6579a59207
commit
2222914005
@ -267,27 +267,13 @@ export default {
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['wsMsg', 'dialogShow', 'dialogMsgUnread', 'projectList']),
|
||||
...mapState(['dialogMsgUnread', 'projectList']),
|
||||
},
|
||||
|
||||
watch: {
|
||||
'$route' (route) {
|
||||
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: {
|
||||
@ -297,7 +283,7 @@ export default {
|
||||
value: [],
|
||||
}, {
|
||||
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('产品开发'),
|
||||
value: [this.$L('产品计划'), this.$L('正在设计'), this.$L('正在研发'), this.$L('测试'), this.$L('准备发布'), this.$L('发布成功')],
|
||||
|
@ -63,18 +63,20 @@ export default {
|
||||
components: {DialogWrapper},
|
||||
data() {
|
||||
return {
|
||||
dialogLoad: 0,
|
||||
dialogKey: '',
|
||||
dialogList: [],
|
||||
dialogLoad: 0,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.getDialogLists();
|
||||
this.dialogLoad++;
|
||||
this.$store.commit("getDialogList", () => {
|
||||
this.dialogLoad--;
|
||||
})
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapState(['dialogId', 'dialogShow', 'wsMsg']),
|
||||
...mapState(['dialogId', 'dialogList']),
|
||||
|
||||
dialogLists() {
|
||||
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: {
|
||||
openDialog(dialog) {
|
||||
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) {
|
||||
let time = Math.round(new Date(date).getTime() / 1000),
|
||||
string = '';
|
||||
|
110
resources/assets/js/store/mutations.js
vendored
110
resources/assets/js/store/mutations.js
vendored
@ -1,5 +1,3 @@
|
||||
import state from "./state";
|
||||
|
||||
export default {
|
||||
/**
|
||||
* 切换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
|
||||
@ -237,6 +290,12 @@ export default {
|
||||
}
|
||||
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"]) {
|
||||
return;
|
||||
}
|
||||
@ -395,19 +454,44 @@ export default {
|
||||
}
|
||||
});
|
||||
if (type === "dialog") {
|
||||
const msgData = msgDetail.data;
|
||||
const dialog_id = msgData.dialog_id;
|
||||
if (dialog_id === state.dialogId) {
|
||||
let index = state.dialogMsgList.findIndex(({id}) => id === msgData.id);
|
||||
if (index === -1) {
|
||||
if (state.dialogMsgList.length >= 200) {
|
||||
state.dialogMsgList.splice(0, 1);
|
||||
// 更新消息
|
||||
(function (msg) {
|
||||
const {data} = msg;
|
||||
const {dialog_id} = data;
|
||||
if (dialog_id === state.dialogId) {
|
||||
let index = state.dialogMsgList.findIndex(({id}) => id === data.id);
|
||||
if (index === -1) {
|
||||
if (state.dialogMsgList.length >= 200) {
|
||||
state.dialogMsgList.splice(0, 1);
|
||||
}
|
||||
state.dialogMsgList.push(data);
|
||||
} else {
|
||||
state.dialogMsgList.splice(index, 1, data);
|
||||
}
|
||||
state.dialogMsgList.push(msgData);
|
||||
} else {
|
||||
state.dialogMsgList.splice(index, 1, msgData);
|
||||
}
|
||||
}
|
||||
})(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
|
||||
}
|
||||
|
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -187,6 +187,7 @@ state.projectMsgUnread = 0;
|
||||
// 会话消息
|
||||
state.dialogId = 0;
|
||||
state.dialogShow = false;
|
||||
state.dialogList = [];
|
||||
state.dialogDetail = {};
|
||||
state.dialogMsgLoad = 0;
|
||||
state.dialogMsgList = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user