no message

This commit is contained in:
kuaifan 2021-06-06 20:07:22 +08:00
parent 4a526ecefb
commit 6579a59207
11 changed files with 93 additions and 20 deletions

View File

@ -111,6 +111,17 @@ class DialogController extends AbstractController
return Base::retSuccess('success', $data); return Base::retSuccess('success', $data);
} }
/**
* 未读消息
*/
public function msg__unread()
{
$unread = WebSocketDialogMsgRead::whereUserid(User::token2userid())->whereReadAt(null)->count();
return Base::retSuccess('success', [
'unread' => $unread,
]);
}
/** /**
* 发送消息 * 发送消息
* *

View File

@ -119,6 +119,7 @@ class WebSocketDialogMsg extends AbstractModel
'userid' => $this->userid, 'userid' => $this->userid,
'msg' => [ 'msg' => [
'type' => 'dialog', 'type' => 'dialog',
'mode' => 'up',
'data' => $this->toArray(), 'data' => $this->toArray(),
] ]
]); ]);

View File

@ -64,6 +64,7 @@ class WebSocketDialogMsgTask extends AbstractTask
'userid' => $pushIds, 'userid' => $pushIds,
'msg' => [ 'msg' => [
'type' => 'dialog', 'type' => 'dialog',
'mode' => 'add',
'data' => $this->dialogMsgArray, 'data' => $this->dialogMsgArray,
] ]
]); ]);

View File

@ -17,6 +17,7 @@
<li @click="toggleRoute('messenger')" :class="classNameRoute('messenger')"> <li @click="toggleRoute('messenger')" :class="classNameRoute('messenger')">
<Icon type="ios-chatbubbles-outline" /> <Icon type="ios-chatbubbles-outline" />
<div class="menu-title">{{$L('消息')}}</div> <div class="menu-title">{{$L('消息')}}</div>
<Badge class="menu-badge" :count="dialogMsgUnread"></Badge>
</li> </li>
<li @click="toggleRoute('setting/personal')" :class="classNameRoute('setting')"> <li @click="toggleRoute('setting/personal')" :class="classNameRoute('setting')">
<Icon type="ios-cog-outline" /> <Icon type="ios-cog-outline" />
@ -141,10 +142,15 @@
margin-top: -1px; margin-top: -1px;
} }
.menu-title { .menu-title {
flex: 1;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.menu-badge {
margin-left: 12px;
transform: scale(0.9);
}
&.menu-project { &.menu-project {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -251,20 +257,39 @@ export default {
columns: [], columns: [],
} }
}, },
mounted() { mounted() {
this.$store.commit('getUserInfo'); this.$store.commit('getUserInfo');
}, },
deactivated() { deactivated() {
this.addShow = false; this.addShow = false;
}, },
computed: { computed: {
...mapState(['projectList']), ...mapState(['wsMsg', 'dialogShow', '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: {
initLanguage() { initLanguage() {
this.columns = [{ this.columns = [{

View File

@ -65,6 +65,22 @@ export default {
} }
}, },
mounted() {
this.$store.state.dialogShow = true;
},
destroyed() {
this.$store.state.dialogShow = false;
},
activated() {
this.$store.state.dialogShow = true;
},
deactivated() {
this.$store.state.dialogShow = false;
},
computed: { computed: {
...mapState(['userId', 'dialogId', 'dialogDetail', 'dialogMsgLoad', 'dialogMsgList']), ...mapState(['userId', 'dialogId', 'dialogDetail', 'dialogMsgLoad', 'dialogMsgList']),

View File

@ -108,7 +108,7 @@ export default {
methods: { methods: {
getMsg() { getMsg() {
if (this.projectChatShow && this.projectDetail.dialog_id) { if (this.projectChatShow && this.projectDetail.dialog_id) {
this.$store.commit('getDialogMsg', this.projectDetail.dialog_id); this.$store.commit('getDialogMsgList', this.projectDetail.dialog_id);
} }
} }
} }

View File

@ -74,7 +74,7 @@ export default {
}, },
computed: { computed: {
...mapState(['dialogId', 'wsMsg']), ...mapState(['dialogId', 'dialogShow', 'wsMsg']),
dialogLists() { dialogLists() {
const {dialogKey} = this; const {dialogKey} = this;
@ -99,9 +99,9 @@ export default {
* @param msg * @param msg
*/ */
wsMsg(msg) { wsMsg(msg) {
const {type, data} = msg; const {type, mode, data} = msg;
if (type === "dialog") { if (type === "dialog" && mode === "add") {
if (this.dialogId == data.dialog_id) { if (this.dialogShow && this.dialogId == data.dialog_id) {
return; return;
} }
let dialog = this.dialogList.find(({id}) => id == data.dialog_id); let dialog = this.dialogList.find(({id}) => id == data.dialog_id);
@ -120,7 +120,8 @@ export default {
*/ */
dialogId(dialog_id) { dialogId(dialog_id) {
let dialog = this.dialogList.find(({id}) => id == dialog_id); let dialog = this.dialogList.find(({id}) => id == dialog_id);
if (dialog) { if (dialog && dialog.unread > 0) {
this.$store.state.dialogMsgUnread-= dialog.unread;
this.$set(dialog, 'unread', 0); this.$set(dialog, 'unread', 0);
} }
} }
@ -128,7 +129,7 @@ export default {
methods: { methods: {
openDialog(dialog) { openDialog(dialog) {
this.$store.commit('getDialogMsg', dialog.id); this.$store.commit('getDialogMsgList', dialog.id);
}, },
getDialogLists() { getDialogLists() {

View File

@ -2,7 +2,7 @@
<div class="project"> <div class="project">
<PageTitle>{{ $L('项目面板') }}</PageTitle> <PageTitle>{{ $L('项目面板') }}</PageTitle>
<ProjectList/> <ProjectList/>
<ProjectDialog v-show="$store.state.projectChatShow"/> <ProjectDialog v-if="$store.state.projectChatShow"/>
</div> </div>
</template> </template>

View File

@ -64,6 +64,7 @@ export default {
state.userToken = userInfo.token; state.userToken = userInfo.token;
state.userIsAdmin = state.method.inArray('admin', userInfo.identity); state.userIsAdmin = state.method.inArray('admin', userInfo.identity);
state.method.setStorage('userInfo', state.userInfo); state.method.setStorage('userInfo', state.userInfo);
this.commit('getDialogMsgUnread');
this.commit('getProjectList'); this.commit('getProjectList');
this.commit('wsConnection'); this.commit('wsConnection');
}, },
@ -215,7 +216,7 @@ export default {
* @param state * @param state
* @param dialog_id * @param dialog_id
*/ */
getDialogMsg(state, dialog_id) { getDialogMsgList(state, dialog_id) {
if (state.method.runNum(dialog_id) === 0) { if (state.method.runNum(dialog_id) === 0) {
return; return;
} }
@ -273,6 +274,28 @@ export default {
}); });
}, },
/**
* 获取未读信息
* @param state
*/
getDialogMsgUnread(state) {
const unread = state.dialogMsgUnread;
$A.apiAjax({
url: 'dialog/msg/unread',
success: ({ret, data, msg}) => {
if (ret === 1) {
if (unread === state.dialogMsgUnread) {
state.dialogMsgUnread = data.unread;
} else {
setTimeout(() => {
this.commit('getDialogMsgUnread');
}, 200);
}
}
}
});
},
/** /**
* 根据消息ID 删除 替换 对话数据 * 根据消息ID 删除 替换 对话数据
* @param state * @param state

View File

@ -144,9 +144,7 @@ const method = {
}; };
// 方法类 // 方法类
const state = { const state = { method };
method
};
// Boolean变量 // Boolean变量
[ [
@ -188,9 +186,11 @@ state.projectMsgUnread = 0;
// 会话消息 // 会话消息
state.dialogId = 0; state.dialogId = 0;
state.dialogShow = false;
state.dialogDetail = {}; state.dialogDetail = {};
state.dialogMsgLoad = 0; state.dialogMsgLoad = 0;
state.dialogMsgList = []; state.dialogMsgList = [];
state.dialogMsgUnread = 0;
// 任务优先级 // 任务优先级
state.taskPriority = []; state.taskPriority = [];

View File

@ -1122,12 +1122,7 @@ body {
top: 10px; top: 10px;
left: 42px; left: 42px;
font-size: 12px; font-size: 12px;
.ivu-badge-count { transform: scale(0.8);
height: 18px;
min-width: 18px;
line-height: 16px;
padding: 0 4px;
}
} }
} }
} }