Plugin

Plugin 基类。

  • 类型
1class Plugin<T = any> {
2  constructor(
3    protected options: T,
4    protected app: Application,
5  ) {
6    this.options = options;
7    this.app = app;
8  }
9
10  get pluginManager() {
11    return this.app.pluginManager;
12  }
13
14  get router() {
15    return this.app.router;
16  }
17
18  get systemSettingsManager() {
19    return this.app.systemSettingsManager;
20  }
21
22  get schemaInitializerManager() {
23    return this.app.schemaInitializerManager;
24  }
25
26  get schemaSettingsManager() {
27    return this.app.schemaSettingsManager;
28  }
29
30  get dataSourceManager() {
31    return this.app.dataSourceManager;
32  }
33
34  async afterAdd() {}
35
36  async beforeLoad() {}
37
38  async load() {}
39}
  • 详细信息

    • 构造函数
      • options: 插件的添加有两种方式,一种方式从插件列表中远程加载出来,另一种方式是通过 PluginManager 添加
        • 远程加载:options 会被自动注入 { name: 'npm package.name' }
        • PluginManager options 由用户自己传递
      • app:此参数是自动注入的,是应用实例
    • 快捷访问:基类提供了对 app 部分方法和属性的快捷访问
      • pluginManager
      • router
      • systemSettingsManager
      • schemaSettingsManager
      • schemaInitializerManager
    • 声明周期
      • afterAdd:插件被添加后立即执行
      • beforeLoad:执行渲染时执行,在 afterAdd 之后,load 之前
      • load:最后执行
  • 示例

1class MyPlugin extends Plugin {
2
3  async afterAdd() {
4    console.log('afterAdd')
5  }
6
7  async beforeLoad() {
8    console.log('beforeLoad')
9  }
10
11  async load() {
12    console.log('load')
13
14    // 可以访问应用实例
15    console.log(this.app)
16
17    // 访问应用实例内容
18    console.log(this.app.router, this.router);
19  }
20}