|
|
@ -64,11 +64,25 @@ export default { |
|
|
return this.$store.state.user.site |
|
|
return this.$store.state.user.site |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 工程实验消息通知标志('Y'=启用通知, 'N'=禁用通知) |
|
|
|
|
|
*/ |
|
|
|
|
|
erfMsgFlag() { |
|
|
|
|
|
return this.$store.state.user.erfMsgFlag |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 是否已登录 |
|
|
* 是否已登录 |
|
|
*/ |
|
|
*/ |
|
|
isLoggedIn() { |
|
|
isLoggedIn() { |
|
|
return this.currentUserId && this.currentUserId !== 0 |
|
|
return this.currentUserId && this.currentUserId !== 0 |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 是否需要显示通知(已登录且erfMsgFlag='Y') |
|
|
|
|
|
*/ |
|
|
|
|
|
shouldShowNotification() { |
|
|
|
|
|
return this.isLoggedIn && this.erfMsgFlag === 'Y' |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
@ -77,7 +91,7 @@ export default { |
|
|
* 监听用户登录状态变化 |
|
|
* 监听用户登录状态变化 |
|
|
*/ |
|
|
*/ |
|
|
isLoggedIn(newVal, oldVal) { |
|
|
isLoggedIn(newVal, oldVal) { |
|
|
console.log(`[审批通知] 登录状态变化: ${oldVal} -> ${newVal}, 已初始化: ${this.isInitialized}`) |
|
|
|
|
|
|
|
|
console.log(`[审批通知] 登录状态变化: ${oldVal} -> ${newVal}, erfMsgFlag: ${this.erfMsgFlag}, 已初始化: ${this.isInitialized}`) |
|
|
|
|
|
|
|
|
// 只有真正的登录状态变化才处理 |
|
|
// 只有真正的登录状态变化才处理 |
|
|
if (oldVal === newVal) { |
|
|
if (oldVal === newVal) { |
|
|
@ -86,28 +100,59 @@ export default { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (newVal && !this.isInitialized) { |
|
|
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(() => { |
|
|
this.$nextTick(() => { |
|
|
if (!this.isInitialized) { |
|
|
|
|
|
|
|
|
if (!this.isInitialized && this.shouldShowNotification) { |
|
|
this.initializeNotificationSystem() |
|
|
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() |
|
|
this.stopNotificationSystem() |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
mounted() { |
|
|
mounted() { |
|
|
console.log(`[审批通知] 组件挂载, 登录状态: ${this.isLoggedIn}, 已初始化: ${this.isInitialized}`) |
|
|
|
|
|
// 组件挂载时,如果已登录且未初始化则初始化 |
|
|
|
|
|
|
|
|
console.log(`[审批通知] 组件挂载, 登录状态: ${this.isLoggedIn}, erfMsgFlag: ${this.erfMsgFlag}, 已初始化: ${this.isInitialized}`) |
|
|
|
|
|
// 组件挂载时,如果需要显示通知且未初始化则初始化 |
|
|
// 使用延迟确保只执行一次 |
|
|
// 使用延迟确保只执行一次 |
|
|
this.$nextTick(() => { |
|
|
this.$nextTick(() => { |
|
|
if (this.isLoggedIn && !this.isInitialized) { |
|
|
|
|
|
|
|
|
if (this.shouldShowNotification && !this.isInitialized) { |
|
|
console.log('[审批通知] 组件挂载时初始化通知系统') |
|
|
console.log('[审批通知] 组件挂载时初始化通知系统') |
|
|
this.initializeNotificationSystem() |
|
|
this.initializeNotificationSystem() |
|
|
|
|
|
} else if (!this.shouldShowNotification) { |
|
|
|
|
|
console.log(`[审批通知] 用户未启用通知功能(erfMsgFlag=${this.erfMsgFlag}),不初始化`) |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
@ -123,6 +168,12 @@ export default { |
|
|
* 初始化通知系统 |
|
|
* 初始化通知系统 |
|
|
*/ |
|
|
*/ |
|
|
initializeNotificationSystem() { |
|
|
initializeNotificationSystem() { |
|
|
|
|
|
// 检查是否需要显示通知 |
|
|
|
|
|
if (!this.shouldShowNotification) { |
|
|
|
|
|
console.log(`[审批通知] 用户未启用通知功能(erfMsgFlag=${this.erfMsgFlag}),跳过初始化`) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 双重检查锁 |
|
|
// 双重检查锁 |
|
|
if (this.isInitialized) { |
|
|
if (this.isInitialized) { |
|
|
console.log('[审批通知] 系统已初始化,跳过重复初始化') |
|
|
console.log('[审批通知] 系统已初始化,跳过重复初始化') |
|
|
@ -254,6 +305,12 @@ export default { |
|
|
* @param {boolean} isFirstCheck - 是否首次检查 |
|
|
* @param {boolean} isFirstCheck - 是否首次检查 |
|
|
*/ |
|
|
*/ |
|
|
checkPendingApprovals(isFirstCheck = false) { |
|
|
checkPendingApprovals(isFirstCheck = false) { |
|
|
|
|
|
// 检查是否需要显示通知 |
|
|
|
|
|
if (!this.shouldShowNotification) { |
|
|
|
|
|
console.log(`[审批通知] 用户未启用通知功能(erfMsgFlag=${this.erfMsgFlag}),跳过检查`) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (!this.isLoggedIn) { |
|
|
if (!this.isLoggedIn) { |
|
|
console.log('[审批通知] 用户未登录,跳过检查') |
|
|
console.log('[审批通知] 用户未登录,跳过检查') |
|
|
return |
|
|
return |
|
|
|