办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * 全局复用的变量、组件、配置,各个模块之间共享
 * 通过单例模式实现,单例必须注意不受请求影响,例如用户信息这些需要根据请求获取的。后续如果有ssr需求,也不会影响
 */
 
interface ComponentsState {
  [key: string]: any;
}
 
interface MessageState {
  copyPreferencesSuccess?: (title: string, content?: string) => void;
}
 
export interface IGlobalSharedState {
  components: ComponentsState;
  message: MessageState;
}
 
class GlobalShareState {
  #components: ComponentsState = {};
  #message: MessageState = {};
 
  /**
   * 定义框架内部各个场景的消息提示
   */
  public defineMessage({ copyPreferencesSuccess }: MessageState) {
    this.#message = {
      copyPreferencesSuccess,
    };
  }
 
  public getComponents(): ComponentsState {
    return this.#components;
  }
 
  public getMessage(): MessageState {
    return this.#message;
  }
 
  public setComponents(value: ComponentsState) {
    this.#components = value;
  }
}
 
export const globalShareState = new GlobalShareState();