session-notice.ts 985 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * 全站级会话提示:角色/主体变化后跨页面告知一次。
  3. *
  4. * 场景:主账号转交会把转出方降为 `opsSub`,`NavAllowed` 随即把当前页换成落地页;
  5. * 点内提示随组件卸载而丢失,因此提示挂在 `AppShell` 上(路由切换不丢)。
  6. * ⛔ 当业务结果提示用:普通保存成功仍走各页 `useSaveNotice`。
  7. */
  8. let message: string | null = null;
  9. const listeners = new Set<() => void>();
  10. function emit() {
  11. for (const listener of listeners) listener();
  12. }
  13. export function notifySessionNotice(text: string) {
  14. const next = text.trim();
  15. if (!next) return;
  16. message = next;
  17. emit();
  18. }
  19. export function dismissSessionNotice() {
  20. if (message === null) return;
  21. message = null;
  22. emit();
  23. }
  24. export function subscribeSessionNotice(listener: () => void) {
  25. listeners.add(listener);
  26. return () => {
  27. listeners.delete(listener);
  28. };
  29. }
  30. export function getSessionNotice(): string | null {
  31. return message;
  32. }