From 824b10feb3c0211820ccbf7ba9eedc5a693680f6 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Tue, 10 Feb 2026 14:30:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E7=A8=8B=E5=AE=9E=E9=AA=8C=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E5=8D=95=E9=80=9A=E7=9F=A5=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApprovalNotificationManager.vue | 75 ++++++++++++++++--- src/store/modules/user.js | 4 + src/views/main.vue | 10 +++ src/views/modules/erf/expApplyList.vue | 2 +- 4 files changed, 81 insertions(+), 10 deletions(-) diff --git a/src/components/ApprovalNotificationManager.vue b/src/components/ApprovalNotificationManager.vue index 35ca0aa..7e104bc 100644 --- a/src/components/ApprovalNotificationManager.vue +++ b/src/components/ApprovalNotificationManager.vue @@ -64,11 +64,25 @@ export default { return this.$store.state.user.site }, + /** + * 工程实验消息通知标志('Y'=启用通知, 'N'=禁用通知) + */ + erfMsgFlag() { + return this.$store.state.user.erfMsgFlag + }, + /** * 是否已登录 */ isLoggedIn() { return this.currentUserId && this.currentUserId !== 0 + }, + + /** + * 是否需要显示通知(已登录且erfMsgFlag='Y') + */ + shouldShowNotification() { + return this.isLoggedIn && this.erfMsgFlag === 'Y' } }, @@ -77,7 +91,7 @@ export default { * 监听用户登录状态变化 */ isLoggedIn(newVal, oldVal) { - console.log(`[审批通知] 登录状态变化: ${oldVal} -> ${newVal}, 已初始化: ${this.isInitialized}`) + console.log(`[审批通知] 登录状态变化: ${oldVal} -> ${newVal}, erfMsgFlag: ${this.erfMsgFlag}, 已初始化: ${this.isInitialized}`) // 只有真正的登录状态变化才处理 if (oldVal === newVal) { @@ -86,28 +100,59 @@ export default { } if (newVal && !this.isInitialized) { - console.log('[审批通知] 用户已登录(watch触发),初始化通知系统') - // 延迟执行,避免与 mounted 冲突 + // 用户已登录且未初始化,但需要检查 erfMsgFlag + if (this.erfMsgFlag === 'Y') { + console.log('[审批通知] 用户已登录且启用通知(watch触发),初始化通知系统') + // 延迟执行,避免与 mounted 冲突 + this.$nextTick(() => { + if (!this.isInitialized && this.shouldShowNotification) { + this.initializeNotificationSystem() + } + }) + } else { + console.log('[审批通知] 用户已登录但未启用通知功能(erfMsgFlag=N),等待erfMsgFlag变化') + } + } else if (!newVal && this.isInitialized) { + console.log('[审批通知] 用户已登出,停止通知系统') + this.stopNotificationSystem() + } + }, + + /** + * 监听 erfMsgFlag 变化 + */ + erfMsgFlag(newVal, oldVal) { + console.log(`[审批通知] erfMsgFlag变化: ${oldVal} -> ${newVal}, 登录状态: ${this.isLoggedIn}, 已初始化: ${this.isInitialized}`) + + if (newVal === 'Y' && this.shouldShowNotification && !this.isInitialized) { + // erfMsgFlag 变为 'Y',且满足显示通知条件但未初始化,则初始化通知系统 + console.log('[审批通知] erfMsgFlag启用且用户已登录,初始化通知系统') this.$nextTick(() => { - if (!this.isInitialized) { + if (!this.isInitialized && this.shouldShowNotification) { this.initializeNotificationSystem() } }) - } else if (!newVal && this.isInitialized) { - console.log('[审批通知] 用户已登出,停止通知系统') + } else if (newVal === 'Y' && !this.isLoggedIn) { + // erfMsgFlag 为 'Y' 但用户未登录 + console.log('[审批通知] erfMsgFlag启用但用户未登录,等待登录') + } else if (newVal === 'N' && this.isInitialized) { + // erfMsgFlag 变为 'N',且已初始化,则停止通知系统 + console.log('[审批通知] erfMsgFlag禁用,停止通知系统') this.stopNotificationSystem() } } }, mounted() { - console.log(`[审批通知] 组件挂载, 登录状态: ${this.isLoggedIn}, 已初始化: ${this.isInitialized}`) - // 组件挂载时,如果已登录且未初始化则初始化 + console.log(`[审批通知] 组件挂载, 登录状态: ${this.isLoggedIn}, erfMsgFlag: ${this.erfMsgFlag}, 已初始化: ${this.isInitialized}`) + // 组件挂载时,如果需要显示通知且未初始化则初始化 // 使用延迟确保只执行一次 this.$nextTick(() => { - if (this.isLoggedIn && !this.isInitialized) { + if (this.shouldShowNotification && !this.isInitialized) { console.log('[审批通知] 组件挂载时初始化通知系统') this.initializeNotificationSystem() + } else if (!this.shouldShowNotification) { + console.log(`[审批通知] 用户未启用通知功能(erfMsgFlag=${this.erfMsgFlag}),不初始化`) } }) }, @@ -123,6 +168,12 @@ export default { * 初始化通知系统 */ initializeNotificationSystem() { + // 检查是否需要显示通知 + if (!this.shouldShowNotification) { + console.log(`[审批通知] 用户未启用通知功能(erfMsgFlag=${this.erfMsgFlag}),跳过初始化`) + return + } + // 双重检查锁 if (this.isInitialized) { console.log('[审批通知] 系统已初始化,跳过重复初始化') @@ -254,6 +305,12 @@ export default { * @param {boolean} isFirstCheck - 是否首次检查 */ checkPendingApprovals(isFirstCheck = false) { + // 检查是否需要显示通知 + if (!this.shouldShowNotification) { + console.log(`[审批通知] 用户未启用通知功能(erfMsgFlag=${this.erfMsgFlag}),跳过检查`) + return + } + if (!this.isLoggedIn) { console.log('[审批通知] 用户未登录,跳过检查') return diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 6fbe3b3..62c987a 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -9,6 +9,7 @@ export default { userDev: false, multiLanguage: '', authControl: '', + erfMsgFlag: 'N', // 工程实验消息通知标志:'Y'=启用通知, 'N'=禁用通知 // favoriteFlag: false, }, mutations: { @@ -32,6 +33,9 @@ export default { }, updateAuthControl (state,authControl){ state.authControl = authControl + }, + updateErfMsgFlag (state, erfMsgFlag) { + state.erfMsgFlag = erfMsgFlag } } } diff --git a/src/views/main.vue b/src/views/main.vue index 4836262..a2718f6 100644 --- a/src/views/main.vue +++ b/src/views/main.vue @@ -96,6 +96,14 @@ this.$store.commit('user/updateUserDisplay', val) } }, + erfMsgFlag: { + get() { + return this.$store.state.user.erfMsgFlag + }, + set(val) { + this.$store.commit('user/updateErfMsgFlag', val) + } + }, }, created() { this.getUserInfo() @@ -126,6 +134,8 @@ this.languageDefault = data.user.languageDefault this.site = data.user.site this.userDisplay = data.user.userDisplay + // 工程实验消息通知标志:'Y'=启用通知, 'N'=禁用通知 + this.erfMsgFlag = data.user.erfMsgFlag || 'N' } }) }, diff --git a/src/views/modules/erf/expApplyList.vue b/src/views/modules/erf/expApplyList.vue index f216d6e..10be19b 100644 --- a/src/views/modules/erf/expApplyList.vue +++ b/src/views/modules/erf/expApplyList.vue @@ -79,7 +79,7 @@ - 新增申请单 + 新增申请单