123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import _ from 'lodash'
- import {FunctionRegiste} from "../types";
- import {Scope} from "../Scope";
- export const LibList: FunctionRegiste[] = []
- export function Lib(registe: FunctionRegiste) {
- return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
- LibList.push({
- ...registe,
- name: propertyKey,
- target: target[propertyKey]
- })
- if (registe.type === 'system') {
- _.set(window, 'yvanLib.system.' + propertyKey, target[propertyKey])
- } else if (registe.type === 'format') {
- _.set(window, 'yvanLib.format.' + propertyKey, target[propertyKey])
- }
- return target
- }
- }
- /**
- * 解析事件
- * 'scope.私有方法名'
- * 'system.系统函数名'
- * 'format.格式化名'
- */
- export function lookupFn(scope: Scope, event: string): Function {
- if (window["IS_DESIGN_MODE"]) {
- return Ext.emptyFn
- }
- // 为 eval 准备环境
- const {system, format} = window['yvanLib']
- const func: Function = eval(event)
- if (typeof func !== 'function') {
- console.error('无法识别的事件响应类型', event, func)
- throw new TypeError('无法识别的事件响应类型')
- }
- return func
- }
- /**
- * 从 ext.element 获取 scope 对象
- */
- export function lookupScope(extHandle: any): Scope {
- const vm = extHandle.lookupViewModel()
- return vm.yvanScope
- }
|