Ver código fonte

扩展scope的onload方法, 设置统一的显示按钮

yuliang 3 anos atrás
pai
commit
bf8e8cafd4
2 arquivos alterados com 15 adições e 0 exclusões
  1. 4 0
      src/Scope.ts
  2. 11 0
      src/lib/config.ts

+ 4 - 0
src/Scope.ts

@@ -2,6 +2,7 @@ import _ from 'lodash'
 import {invokeMethod} from "./utils"
 import {windows} from './Defaults'
 import {lookupScope} from "./lib/lib";
+import {scopeOnLoad} from './lib/config'
 
 export class Scope {
 
@@ -320,6 +321,9 @@ export class Scope {
      * 模块载入完成之后的回调
      */
     onLoad() {
+        if (scopeOnLoad && typeof scopeOnLoad === 'function') {
+            scopeOnLoad(this)
+        }
     }
 
     /**

+ 11 - 0
src/lib/config.ts

@@ -35,6 +35,11 @@ export interface ConfigOption {
      * 获取拼音首字母的函数
      */
     pinyinFunction: (py: string) => string
+
+    /**
+     * Scope onload 时扩展方法
+     */
+    scopeOnLoad: (scope:any)=> void
 }
 
 /**
@@ -49,6 +54,8 @@ export const ajax: {
  */
 let pinyinFunc: Function = (str) => (str)
 
+export let scopeOnLoad : (scope:any)=>void = null
+
 export const baseConfigProcessList: ConfigProcess[] = []
 
 /**
@@ -104,6 +111,10 @@ export function extend(option: Partial<ConfigOption>) {
         pinyinFunc = option.pinyinFunction
     }
 
+    if (option.scopeOnLoad) {
+        scopeOnLoad = option.scopeOnLoad
+    }
+
     if (typeof option.designMode !== 'undefined') {
         setDesignMode(option.designMode)
     }