open-yu-que-ui-logic-base.ts 5.3 KB
Newer Older
1
import { UIActionContext } from "@/logic/ui-logic";
2
import { LogicReturnType } from "@/logic/const/logic-return-type";
3
import { UILogicParamType } from "@/logic/const/ui-logic-param-type";
4
import { Util, Verify } from "@/utils";
5 6
import { AppMessageBox } from "@/utils/app-message-box/app-message-box";
import { Subject } from "rxjs";
7 8 9 10 11 12 13 14 15 16 17 18
/**
 * 打开语雀文档
 *
 * @export
 * @class OpenYuQueUILogicBase
 */
export default class OpenYuQueUILogicBase {

    /**
     * Creates an instance of  OpenYuQueBase.
     * 
     * @param {*} [opts={}]
19
     * @memberof OpenYuQueUILogicBase
20 21 22
     */
    constructor(opts: any = {}) { }

23 24 25 26 27 28 29
    /**
     * 逻辑参数
     *
     * @protected
     * @type {any[]}
     * @memberof OpenYuQueUILogicBase
     */
30 31 32 33
    protected logicParams: any[] = [
        {
            name: '传入变量',
            codeName: 'Default',
34 35
            default: true,
            entityParam: true,
36 37 38
        },
    ];

39 40 41 42 43 44 45 46 47 48 49 50 51
    /**
     * 执行前
     *
     * @param {*} args
     * @param {*} [context={}]
     * @param {*} [params={}]
     * @param {*} [$event]
     * @param {*} [xData]
     * @param {*} [actioncontext]
     * @param {string} [srfParentDeName]
     * @return {*} 
     * @memberof OpenYuQueUILogicBase
     */
52 53 54
    public beforeExecute(args: any, context: any = {}, params: any = {},
        $event?: any, xData?: any, actioncontext?: any, srfParentDeName?: string) {
        return new UIActionContext(this.logicParams, args, context, params, $event, xData, actioncontext, srfParentDeName)
55 56 57 58 59 60 61 62 63 64 65 66
    }

    /**
     * 执行
     *
     * @param {any[]} args
     * @param {*} [context={}]
     * @param {*} [params={}]
     * @param {*} [$event]
     * @param {*} [xData]
     * @param {*} [actionContext]
     * @param {string} [srfParentDeName]
67
     * @memberof OpenYuQueUILogicBase
68
     */
69 70 71
    async execute(args: any[], context:any = {} ,params: any = {}, $event?: any, xData?: any, actioncontext?: any, srfParentDeName?: string) {
        try {
            const actionContext = this.beforeExecute(args, context, params, $event, xData, actioncontext, srfParentDeName);
72
            await this.execute_begin_node(actionContext);
73 74
            return actionContext.getResult();
        } catch (error: any) {
75
            throw new Error(`${error && error.message ? error.message : '发生未知错误!'}`);
76 77 78
        }
    }

79 80 81 82 83 84 85 86 87 88 89
    /**
     * 获取条件参数
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
     * @param {string} param 节点参数
     * @param {string} property 参数属性
     * @return {*} 
     * @memberof OpenYuQueUILogicBase
     */
    public getCondParam(actionContext: UIActionContext, param: string, property: string) {
        const resultParam = actionContext.getParam(param).getReal();
90 91 92 93
        //  当不存在参数属性时,返回直接值
        if (property === '') {
            return resultParam;
        }
94 95 96 97 98 99
        if (resultParam && resultParam.hasOwnProperty(property)) {
            return resultParam[property];
        }
        return null;
    }

100 101 102 103
    /**
     * 开始
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
104
     * @memberof OpenYuQueUILogicBase
105 106 107
     */
    protected async execute_begin_node(actionContext: UIActionContext) {
        actionContext.setResult(actionContext.defaultParam.getReal());
108
        console.log('已完成执行 开始 节点');
109 110 111 112 113 114 115
        await this.execute_deuiaction1_node(actionContext);
    }
    
    /**
     * 结束
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
116
     * @memberof OpenYuQueUILogicBase
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
     */
    protected async execute_end1_node(actionContext: UIActionContext) {
        const strReturnType: string = 'NONEVALUE';
        if (Object.is(strReturnType, LogicReturnType.NONEVALUE) || Object.is(strReturnType, LogicReturnType.NULLVALUE)) {
            actionContext.setResult(null);
        } else if (Object.is(strReturnType, LogicReturnType.SRCVALUE)) {
            actionContext.setResult('');
        } else if (Object.is(strReturnType, LogicReturnType.BREAK)) {
            actionContext.setResult(LogicReturnType.BREAK);
        } else if (Object.is(strReturnType, LogicReturnType.LOGICPARAM) || Object.is(strReturnType, LogicReturnType.LOGICPARAMFIELD)) {
            const returnParam = actionContext.getParam('');
            if (Object.is(strReturnType, LogicReturnType.LOGICPARAM)) {
                actionContext.setResult(returnParam.getReal());
            } else {
                actionContext.setResult(returnParam.get(''));
            }
        } else {
            throw new Error(`无法识别的返回值类型${strReturnType}`);
        }
        console.log('已完成执行 结束 节点');
    }
    
    /**
     * 界面行为
     *
     * @param {UIActionContext} actionContext 界面逻辑上下文
143
     * @memberof OpenYuQueUILogicBase
144 145 146 147 148
     */
    protected async execute_deuiaction1_node(actionContext: UIActionContext) {
        const data = actionContext.defaultParam.getReal();
        const { context, viewparams } = actionContext;
        //  TODO 调用实体界面行为节点
149
        console.log('已完成执行 界面行为 节点');
150 151 152
        await this.execute_end1_node(actionContext);
    }
    
153 154

}