deuiaction-node.ts 6.2 KB
Newer Older
1
import { IPSDEUIActionLogic, getDstPSAppDEUIAction, IPSDEUILogicParam } from '@ibiz/dynamic-model-api';
2 3
import { AppServiceBase, UIServiceHelp } from 'ibiz-core';
import { UILogicParamType } from '../const/ui-logic-param-type';
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
import { UIActionContext } from '../uiaction-context';
import { AppUILogicNodeBase } from './logic-node-base';
/**
 * 实体界面行为调用节点
 *
 * @export
 * @class AppUILogicDeUIActionNode
 */
export class AppUILogicDeUIActionNode extends AppUILogicNodeBase {

    constructor() {
        super();
    }

    /**
     * 执行节点
     *
     * @param {IPSDEUIActionLogic} logicNode 逻辑节点模型数据
     * @param {UIActionContext} actionContext 界面逻辑上下文
     * @memberof AppUILogicDeUIActionNode
     */
    public async executeNode(logicNode: IPSDEUIActionLogic, actionContext: UIActionContext) {
        try {
            await this.handleDEUIAction(logicNode, actionContext);
            return this.computeNextNodes(logicNode, actionContext)
        } catch (error: any) {
            throw new Error(`逻辑节点 ${logicNode.name}${error?.message ? error?.message : '发生未知错误!'}`);
        }
    }

    /**
     * 处理界面行为 
     *
     * @private
     * @param {IPSDEUIActionLogic} logicNode
     * @param {UIActionContext} actionContext
     * @memberof AppUILogicDeUIActionNode
     */
    private async handleDEUIAction(logicNode: IPSDEUIActionLogic, actionContext: UIActionContext) {
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        const Environment = AppServiceBase.getInstance().getAppEnvironment();
        if (Environment.enableUILogicIssue) {
            return this.executeUIAction(logicNode, actionContext);
        } else {
            return this.executeDefaultUIAction(logicNode, actionContext);
        }
    }

    /**
     * 执行默认界面行为(适配之前的逻辑)
     *
     * @private
     * @param {IPSDEUIActionLogic} logicNode
     * @param {UIActionContext} actionContext
     * @memberof AppUILogicDeUIActionNode
     */
    private async executeDefaultUIAction(logicNode: IPSDEUIActionLogic, actionContext: UIActionContext) {
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        const data = actionContext.defaultParam.getReal();
        const { context, viewparams } = actionContext;
        const additionalParam = actionContext.additionalParam;
        const dstEntity = logicNode.getDstPSAppDataEntity();
        const dstUIAction = await getDstPSAppDEUIAction(logicNode);
        if (dstEntity && dstUIAction) {
            try {
                const targetUIService = await UIServiceHelp.getInstance().getService(dstEntity,{context});
                await targetUIService.loaded();
                const result = await targetUIService.excuteAction(
                    dstUIAction.uIActionTag,
                    [data],
                    context,
                    viewparams,
                    additionalParam?.$event,
75 76
                    actionContext.getParam(actionContext.activeCtrlParamName)?.getReal(),
                    actionContext.getParam(actionContext.activeContainerParamName)?.getReal(),
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
                    additionalParam?.parentDeName,
                );
                const dstParam = actionContext.getParam((logicNode.getDstPSDEUILogicParam() as IPSDEUILogicParam)?.codeName);
                if (result && result.ok && result.result) {
                    dstParam.bind(Array.isArray(result?.result) ? result.result[0] : result.result);
                    actionContext.bindLastReturnParam(Array.isArray(result?.result) ? result.result[0] : result.result);
                }
                return dstParam;
            } catch (error: any) {
                throw new Error(`调用实体行为异常${error?.message ? error.message : ''}`);
            }
        } else {
            throw new Error(`调用界面行为参数不足`);
        }
    }
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 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 143 144

    /**
     * 执行界面行为
     *
     * @private
     * @param {IPSDEUIActionLogic} logicNode
     * @param {UIActionContext} actionContext
     * @return {*} 
     * @memberof AppUILogicDeUIActionNode
     */
    private async executeUIAction(logicNode: IPSDEUIActionLogic, actionContext: UIActionContext) {
        const dstParam = actionContext.getParam((logicNode.getDstPSDEUILogicParam() as IPSDEUILogicParam)?.codeName);
        let data: any[] = [];
        if (Object.is(dstParam.logicParamType, UILogicParamType.entityListParam)) {
            data = dstParam.getReal();
        } else if (Object.is(dstParam.logicParamType, UILogicParamType.entityParam)) {
            data = [dstParam.getReal()];
        } else {
            throw new Error(`界面行为操作参数只能为数据对象变量类型或者数据对象列表类型`);
        }
        const retParam = actionContext.getParam(logicNode.M.getRetPSDEUILogicParam?.id);
        const { context, viewparams } = actionContext;
        const additionalParam = actionContext.additionalParam;
        const dstEntity = logicNode.getDstPSAppDataEntity();
        const dstUIAction = await getDstPSAppDEUIAction(logicNode);
        if (dstEntity && dstUIAction && dstParam) {
            try {
                const targetUIService = await UIServiceHelp.getInstance().getService(dstEntity,{context});
                await targetUIService.loaded();
                const result = await targetUIService.excuteAction(
                    dstUIAction.uIActionTag,
                    [data],
                    context,
                    viewparams,
                    additionalParam?.$event,
                    actionContext.getParam(actionContext.activeCtrlParamName)?.getReal(),
                    actionContext.getParam(actionContext.activeContainerParamName)?.getReal(),
                    additionalParam?.parentDeName,
                );
                if (result && result.ok && result.result) {
                    if (retParam) {
                        retParam.bind(result.result);
                    }
                    actionContext.bindLastReturnParam(result.result);
                }
                return dstParam;
            } catch (error: any) {
                throw new Error(`调用实体行为异常${error?.message ? error.message : ''}`);
            }
        } else {
            throw new Error(`调用界面行为参数不足`);
        }
    }
145
}