ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
 * 全局复用的变量、组件、配置,各个模块之间共享
 * 通过单例模式实现,单例必须注意不受请求影响,例如用户信息这些需要根据请求获取的。后续如果有ssr需求,也不会影响
 */
 
interface ComponentsState {
  [key: string]: any;
}
interface commonState {
  [key: string]: any;
}
interface MessageState {
  copyPreferencesSuccess?: (title: string, content?: string) => void;
  createMessage?: any;
}
 
export interface IGlobalSharedState {
  api: commonState;
  components: ComponentsState;
  message: MessageState;
  stores: commonState;
}
 
class GlobalShareState {
  #api: commonState = {};
  #components: ComponentsState = {};
  #message: MessageState = {};
  #stores: commonState = {};
 
  /**
   * 定义框架内部各个场景的消息提示
   */
  public defineMessage({
    copyPreferencesSuccess,
    createMessage,
  }: MessageState) {
    this.#message = {
      copyPreferencesSuccess,
      createMessage,
    };
  }
 
  public getApi(): commonState {
    return this.#api;
  }
  public getComponents(): ComponentsState {
    return this.#components;
  }
  public getMessage(): MessageState {
    return this.#message;
  }
  public getStores(): commonState {
    return this.#stores;
  }
 
  public setApi(value: commonState) {
    this.#api = value;
  }
  public setComponents(value: ComponentsState) {
    this.#components = value;
  }
  public setStores(value: commonState) {
    this.#stores = value;
  }
}
 
export const globalShareState = new GlobalShareState();