Parcourir la source

baseConfigProcess

luoyifan il y a 4 ans
Parent
commit
08df0ebdf2
6 fichiers modifiés avec 46 ajouts et 31 suppressions
  1. 8 4
      src/controls/component.js
  2. 2 1
      src/init.ts
  3. 7 17
      src/lib/config.ts
  4. 25 0
      src/lib/fix.js
  5. 1 6
      src/lib/lib.ts
  6. 3 3
      src/types.ts

+ 8 - 4
src/controls/component.js

@@ -1,13 +1,17 @@
 import _ from 'lodash'
-import {componentConfigProcess} from "../lib/config";
+import {baseConfigProcessList} from "../lib/config";
 
 export default function () {
     const ct = Ext.Component.prototype.constructor
     Ext.Component.override({
         constructor: function (config) {
-            const newConfig = _.cloneDeep(config)
-            componentConfigProcess(this, newConfig)
-            ct.call(this, newConfig)
+            const me = this
+            // 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
+            _.each(baseConfigProcessList, process => {
+                process.call(me, me, config)
+            })
+
+            ct.call(this, config)
         }
     });
 }

+ 2 - 1
src/init.ts

@@ -16,6 +16,7 @@ import initButton from './controls/button'
 import initStores from './controls/stores'
 import {lookupFn, lookupScope} from "./lib/lib"
 import * as SystemLib from './lib/systemLib'
+import './lib/fix'
 
 export function init() {
     // 引入 filters 过滤插件
@@ -92,7 +93,7 @@ export function init() {
     if (!window['system']) {
         window['system'] = {}
     }
-    _.extend(window, SystemLib)
+    _.extend(window['system'], SystemLib)
 
     initComponent()
     initPanel()

+ 7 - 17
src/lib/config.ts

@@ -1,4 +1,4 @@
-import {VJsonProcess} from "../types";
+import {ConfigProcess} from "../types";
 import {ApiFunction} from "./ajax";
 import _ from 'lodash'
 
@@ -49,14 +49,15 @@ export const ajax: {
  */
 let pinyinFunc: Function
 
-export const vjsonProcessChain: VJsonProcess[] = []
+export const baseConfigProcessList: ConfigProcess[] = []
 
 /**
- * 添加一个 VJson 的处理过程
- * @param func VJson 处理函数
+ * 在基类添加 Config 的处理方法
  */
-export function pushVJsonProcess(func: VJsonProcess) {
-    vjsonProcessChain.push(func)
+export function baseConfigProcess(option?: any) {
+    return (target, propertyKey) => {
+        baseConfigProcessList.push(target[propertyKey])
+    }
 }
 
 let designMode: boolean = false
@@ -107,14 +108,3 @@ export function extend(option: Partial<ConfigOption>) {
         setDesignMode(option.designMode)
     }
 }
-
-/**
- * 任意组件 Ext.Component 构造时调用的方法, 可以用来在渲染之前加工处理 VJSON
- * @param me
- * @param config
- */
-export function componentConfigProcess(me, config) {
-    _.each(vjsonProcessChain, process => {
-        process(me, config)
-    })
-}

+ 25 - 0
src/lib/fix.js

@@ -0,0 +1,25 @@
+import _ from 'lodash'
+import {baseConfigProcess} from "./config";
+import {lookupFn, lookupScope} from "./lib";
+
+class FixClass {
+
+    @baseConfigProcess()
+    fix(me, config) {
+        const {fix} = config
+        if (!fix) {
+            return
+        }
+
+        const scope = lookupScope(me)
+        const fixFnArray = []
+        if (_.isArray(fix)) {
+            fixFnArray.push(_.map(fix, (f) => lookupFn(scope, f)))
+        } else if (_.isString(fix)) {
+            fixFnArray.push(lookupFn(scope, fix))
+        }
+
+        console.log(fixFnArray)
+        debugger
+    }
+}

+ 1 - 6
src/lib/lib.ts

@@ -1,7 +1,6 @@
 import _ from 'lodash'
-import {FunctionRegiste, VJsonProcess} from "../types"
+import {FunctionRegiste} from "../types"
 import {Scope} from "../Scope"
-import {pushVJsonProcess} from '../lib/config'
 
 export const LibList: FunctionRegiste[] = []
 
@@ -19,10 +18,6 @@ export function Lib(registe: FunctionRegiste) {
         } else if (registe.type === 'format') {
             _.set(window, 'yvanLib.format.' + propertyKey, target[propertyKey])
 
-        } else if (registe.type === 'mixins') {
-            // 混入方法,在每个组件初始化的时候,都会调用 mixins 混入方法
-            // 混入方法可以对 vjson 进行修改
-            pushVJsonProcess(registe.target as VJsonProcess)
         }
 
         return target

+ 3 - 3
src/types.ts

@@ -12,7 +12,7 @@ export interface VJson {
  * @param vjson 是待处理的 VJson 对象
  * @result 返回处理 VJson 的 Promise 异步结果
  */
-export type VJsonProcess = (me, config) => boolean
+export type ConfigProcess = (me, config) => any
 
 /**
  * 注册函数中的参数
@@ -84,9 +84,9 @@ export interface FunctionRegiste {
      * system: 系统方法
      * format: 格式化作用
      * ajaxMethod: AjaxMethod
-     * meta: 元数据
+     * fix: 修正 vjson
      */
-    type: 'system' | 'format' | 'mixins' | 'ajaxMethod' | 'meta'
+    type: 'system' | 'format' | 'fix'
 
     /**
      * 分类名称