fix: 独立窗口不更新消息

This commit is contained in:
Pang 2024-04-03 07:00:06 +08:00
parent 9ae278d622
commit 629fe79c61
2 changed files with 30 additions and 0 deletions

View File

@ -799,11 +799,14 @@ export default {
}, },
mounted() { mounted() {
this.subMsgListener()
this.msgSubscribe = Store.subscribe('dialogMsgChange', this.onMsgChange); this.msgSubscribe = Store.subscribe('dialogMsgChange', this.onMsgChange);
document.addEventListener('selectionchange', this.onSelectionchange); document.addEventListener('selectionchange', this.onSelectionchange);
}, },
beforeDestroy() { beforeDestroy() {
this.subMsgListener(true)
//
this.$store.dispatch('forgetInDialog', this._uid) this.$store.dispatch('forgetInDialog', this._uid)
this.$store.dispatch('closeDialog', this.dialogId) this.$store.dispatch('closeDialog', this.dialogId)
// //
@ -1427,6 +1430,29 @@ export default {
}, },
methods: { methods: {
/**
* 订阅消息用于独立窗口
* @param unsubscribe
*/
subMsgListener(unsubscribe = false) {
if (!$A.isSubElectron) {
return
}
if (unsubscribe) {
this.$store.dispatch('websocketMsgListener', 'DialogWrapper')
} else {
this.$store.dispatch('websocketMsgListener', {
name: 'DialogWrapper',
callback: (msgDetail) => {
const {type, mode, data} = msgDetail;
if (type === 'dialog' && mode === 'add') {
this.tempMsgs.push(data)
}
}
})
}
},
/** /**
* 发送消息 * 发送消息
* @param text * @param text

View File

@ -3878,6 +3878,10 @@ export default {
* @param params {name, callback} * @param params {name, callback}
*/ */
websocketMsgListener({state}, params) { websocketMsgListener({state}, params) {
if (typeof params === "string") {
state.wsListener[params] && delete state.wsListener[params];
return;
}
const {name, callback} = params; const {name, callback} = params;
if (typeof callback === "function") { if (typeof callback === "function") {
state.wsListener[name] = callback; state.wsListener[name] = callback;