diff --git a/saiadmin-artd/src/composables/useChannelDeptScope.ts b/saiadmin-artd/src/composables/useChannelDeptScope.ts index 80092f0..1d77edd 100644 --- a/saiadmin-artd/src/composables/useChannelDeptScope.ts +++ b/saiadmin-artd/src/composables/useChannelDeptScope.ts @@ -27,12 +27,35 @@ export interface ChannelDeptScopeContext { export const CHANNEL_DEPT_SCOPE_KEY: InjectionKey = Symbol('channelDeptScope') +/** + * 当前应用中处于激活态的超管渠道上下文。 + * 仅有一个 SuperAdminChannelShell 实例,所以可以在模块作用域内缓存其 ctx, + * 供 setInterval / 异步回调 / 事件处理器等"setup 外"路径取用—— + * 这些路径上 Vue 的 inject() 会失效(getCurrentInstance() 为 null)。 + */ +let activeChannelCtx: ChannelDeptScopeContext | null = null + export function provideChannelDeptScope(ctx: ChannelDeptScopeContext) { provide(CHANNEL_DEPT_SCOPE_KEY, ctx) + activeChannelCtx = ctx + onScopeDispose(() => { + if (activeChannelCtx === ctx) { + activeChannelCtx = null + } + }) } export function useInjectedChannelDept(): ChannelDeptScopeContext | null { - return inject(CHANNEL_DEPT_SCOPE_KEY, null) + // 仅在组件 setup 同步路径下调用 inject() 才可靠; + // 否则(异步回调、setInterval、事件处理器等)退化为读取模块级激活上下文, + // 避免渠道切换后 getCurrentPool/withChannelDeptParams 等仍按超管自身部门发请求。 + if (getCurrentInstance()) { + const ctx = inject(CHANNEL_DEPT_SCOPE_KEY, null) + if (ctx) { + return ctx + } + } + return activeChannelCtx } /** 超管全局渠道栏:创建并 provide 渠道上下文 */ diff --git a/saiadmin-artd/src/views/plugin/dice/lottery_pool_config/index/modules/current-pool-dialog.vue b/saiadmin-artd/src/views/plugin/dice/lottery_pool_config/index/modules/current-pool-dialog.vue index 64ad0d5..7fc6a83 100644 --- a/saiadmin-artd/src/views/plugin/dice/lottery_pool_config/index/modules/current-pool-dialog.vue +++ b/saiadmin-artd/src/views/plugin/dice/lottery_pool_config/index/modules/current-pool-dialog.vue @@ -239,6 +239,8 @@ () => props.modelValue, (open) => { if (open) { + // 切换渠道后再打开弹窗时,先清掉旧池数据,避免视觉残留 + pool.value = null loadPool().then(() => startPolling()) } else { stopPolling()