LOGIC.vue.ftl 17.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<#ibizinclude>
../../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<#--  后台界面行为  -->
<#if backend_block??>
${backend_block}
<#else>
    /**
     * ${item.getCaption()}
     *
     * @param {any[]} args 当前数据
     * @param {any} context 行为附加上下文
     * @param {*} [params] 附加参数
     * @param {*} [$event] 事件源
     * @param {*} [xData]  执行行为所需当前部件
     * @param {*} [actionContext]  执行行为上下文
     * @param {*} [srfParentDeName] 父实体名称
     * @returns {Promise<any>}
Mosher's avatar
Mosher committed
19
    <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()??>
20
     * @memberof ${srfclassname('${item.getPSAppDataEntity().getCodeName()}')}UIService
Mosher's avatar
Mosher committed
21
    </#if>
22
     */
tony001's avatar
tony001 committed
23
    public async ${item.getFullCodeName()}(args: any[],context:any = {}, params:any = {}, $event?: any, xData?: any,actionContext?: any,srfParentDeName?:string){
24 25 26
    <#if item.render??>
        ${item.render.code}
    <#else>
Mosher's avatar
Mosher committed
27
        <#if item.getUILogicAttachMode?? && item.getUILogicAttachMode()?? && item.getUILogicAttachMode() == 'REPLACE' && item.getPSAppDEUILogic?? && item.getPSAppDEUILogic()??>
Mosher's avatar
Mosher committed
28 29
        const _context: any = Object.assign(context, actionContext.context);
        const _params: any = Object.assign(params, actionContext.viewparams);
Mosher's avatar
Mosher committed
30
            <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()?? && item.getPSAppDEUILogic().getPSAppDataEntity?? && item.getPSAppDEUILogic().getPSAppDataEntity()?? && item.getPSAppDataEntity().codeName == item.getPSAppDEUILogic().getPSAppDataEntity().codeName>
Mosher's avatar
Mosher committed
31
        return this.executeUILogic('${item.getPSAppDEUILogic().codeName}', args, _context, _params, $event, xData, actionContext, srfParentDeName);
Mosher's avatar
Mosher committed
32
            <#elseif item.getPSAppDEUILogic().getPSAppDataEntity?? && item.getPSAppDEUILogic().getPSAppDataEntity()??>
Mosher's avatar
Mosher committed
33
        const uiService = await window.uiServiceRegister.getService('${item.getPSAppDEUILogic().getPSAppDataEntity().codeName}');
Mosher's avatar
Mosher committed
34
        return uiService.executeUILogic('${item.getPSAppDEUILogic().codeName}', args, _context, _params, $event, xData, actionContext, srfParentDeName);
Mosher's avatar
Mosher committed
35 36
            </#if>
        <#else>
Mosher's avatar
Mosher committed
37 38
        <#--  BEGIN: 自定义确认  -->
            <#if item.getEnableConfirm?? && item.getEnableConfirm() && item.getConfirmMsg?? && item.getConfirmMsg()??>
39 40 41 42 43 44 45 46 47 48 49
        let confirmResult:boolean = await new Promise((resolve: any, reject: any) => {
          actionContext.$Modal.confirm({
              title: '警告',
              content: '${item.getConfirmMsg()}',
              onOk: () => {resolve(true);},
              onCancel: () => {resolve(false);}
          });
        });
        if(!confirmResult){
            return;
        }
Mosher's avatar
Mosher committed
50 51 52
            </#if>
        <#--  END: 自定义确认  -->
            <#if item.getActionTarget() == 'MULTIDATA'>
53
        actionContext.$Notice.error({ title: '错误', desc: '不支持多项数据' });
Mosher's avatar
Mosher committed
54
            <#else>
55
        let data: any = {};
Mosher's avatar
Mosher committed
56 57 58
        let tempData: any = {};
        let tempContext: any = {};
        let tempViewParam: any = {};
tony001's avatar
tony001 committed
59
        const _this: any = actionContext;
60
        <#-- 是否先保存目标数据start -->
Mosher's avatar
Mosher committed
61
                <#if item.isSaveTargetFirst()>
62
        const result:any = await xData.save(args,false);
Mosher's avatar
Mosher committed
63 64 65
                    <#if item.getActionTarget() == 'SINGLEDATA'>
        Object.assign(args[0], result.data);
                    <#else>
66
        args = [result.data];
Mosher's avatar
Mosher committed
67 68
                    </#if>
                </#if>
69 70 71
         <#-- 是否先保存目标数据end -->
        const _args: any[] = Util.deepCopy(args);
        const actionTarget: string | null = <#if item.getActionTarget()??>'${item.getActionTarget()}'<#else>null</#if>;
Mosher's avatar
Mosher committed
72 73 74 75 76 77 78 79 80 81
                <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()??>
                    <#assign appDataEntity = item.getPSAppDataEntity() />
                    <#if item.getActionTarget() == 'SINGLEKEY' || item.getActionTarget() == 'MULTIKEY'>
                        <#assign valueItem><#if item.getValueItem?? && item.getValueItem() != ''>${item.getValueItem()}<#else>${appDataEntity.getKeyPSAppDEField().getCodeName()?lower_case}</#if></#assign>
                        <#assign paramItem><#if item.getParamItem?? && item.getParamItem() != ''>${item.getParamItem()}<#else>${appDataEntity.getCodeName()?lower_case}</#if></#assign>
                        <#assign textItem><#if item.getTextItem?? && item.getTextItem() != ''>${item.getTextItem()}<#else>${appDataEntity.getMajorPSAppDEField().getCodeName()?lower_case}</#if></#assign>
        if (_args && args[0] && args[0]['${valueItem}']) {
            Object.assign(tempContext, { ${appDataEntity.codeName?lower_case}: '%${valueItem}%' });
        } else {
            Object.assign(tempContext, { ${appDataEntity.codeName?lower_case}: '%${paramItem}%' });
tony001's avatar
tony001 committed
82
        }
Mosher's avatar
Mosher committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        Object.assign(tempViewParam, { ${valueItem}: '%${paramItem}%' });
        Object.assign(tempViewParam, { ${textItem}: '%${textItem}%' });
                    </#if>
                </#if>
                <#if item.getPSNavigateContexts?? && item.getPSNavigateContexts()??>
        Object.assign(tempContext, <@getNavigateContext item />);
                </#if>
                <#if item.getPSNavigateParams?? && item.getPSNavigateParams()??>
        Object.assign(tempViewParam, <@getNavigateParams item />);
                </#if>
        tempContext = UIActionTool.handleContextParam(actionTarget, _args, context, params, tempContext);
                <#if item.getActionTarget() == 'SINGLEDATA'>
        tempData = UIActionTool.handleActionParam(actionTarget, _args, context, params, tempViewParam);
        Object.assign(data, tempData);
                <#else>
Mosher's avatar
Mosher committed
98
        data = UIActionTool.handleActionParam(actionTarget, _args, context, params, tempViewParam);
Mosher's avatar
Mosher committed
99
                </#if>
100
        <#-- 多项数据主键转换数据 start -->
Mosher's avatar
Mosher committed
101
        if (Object.is(actionTarget, "MULTIKEY")) {
102
            let tempDataArray:Array<any> = [];
Mosher's avatar
Mosher committed
103 104 105
            if ((_args.length > 1) && (Object.keys(data).length > 0)) {
                for(let i =0; i < _args.length; i++){
                    let tempObject: any = {};
106
                    Object.keys(data).forEach((key:string) =>{
Mosher's avatar
Mosher committed
107
                        Object.assign(tempObject,{ [key]: data[key].split(',')[i] });
108 109 110
                    })
                    tempDataArray.push(tempObject);
                }
Mosher's avatar
Mosher committed
111
            } else {
112 113 114 115 116
                tempDataArray.push(data);
            }
            data = tempDataArray;
        }
        <#-- 多项数据主键转换数据 end -->
Mosher's avatar
Mosher committed
117
        Object.assign(context, tempContext);
118
        <#-- 构建srfparentdename和srfparentkey start -->
Mosher's avatar
Mosher committed
119 120 121 122
        let parentObj: any = {
            srfparentdename: srfParentDeName ? srfParentDeName : null,
            srfparentkey: srfParentDeName ? context[srfParentDeName.toLowerCase()] : null
        };
123
        <#-- 多项数据主键转换数据 start -->
124
        if(!Object.is(actionTarget,"MULTIKEY")){
Mosher's avatar
Mosher committed
125
            Object.assign(data, parentObj);
126 127
        }
        <#-- 多项数据主键转换数据 end -->
Mosher's avatar
Mosher committed
128
        Object.assign(context, parentObj);
129 130 131
        <#-- 构建srfparentdename和srfparentkey end -->
        // 直接调实体服务需要转换的数据
        if(context && context.srfsessionid){
Mosher's avatar
Mosher committed
132
            context.srfsessionkey = context.srfsessionid;
133 134 135
            delete context.srfsessionid;
        }
        const backend = () => {
Mosher's avatar
Mosher committed
136 137
            if (xData && xData.formValidateStatus instanceof Function) {
                if (!xData.formValidateStatus()) {
Mosher's avatar
Mosher committed
138
                    actionContext.$Notice.error({ title: '错误', desc: actionContext.$t('app.searchform.globalerrortip') as string });
Mosher's avatar
Mosher committed
139 140 141 142 143 144
                    return;
                }
            }
                <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()?? && item.getPSAppDEMethod?? && item.getPSAppDEMethod()??>
            const curService: ${srfclassname('${item.getPSAppDataEntity().getCodeName()}')}Service =  new ${srfclassname('${item.getPSAppDataEntity().getCodeName()}')}Service();
                    <#if item.getActionTarget() == 'MULTIKEY'>
Mosher's avatar
Mosher committed
145
            const promiseArray: any[] = [];
Mosher's avatar
Mosher committed
146 147 148 149
            if (data && data.length > 0) {
                const srfkeys = context['${item.getPSAppDataEntity().codeName?lower_case}'] ? context['${item.getPSAppDataEntity().codeName?lower_case}'].split(',') : [];
                data.forEach((ele: any, index: number) => {
                    const tempContext = Util.deepCopy(context);
Mosher's avatar
Mosher committed
150
                    Object.assign(tempContext, { ${item.getPSAppDataEntity().codeName?lower_case}: srfkeys[index] });
Mosher's avatar
Mosher committed
151 152 153 154 155
                    promiseArray.push(curService['${item.getPSAppDEMethod().getCodeName()}'](tempContext, ele));
                })
            }
            let promise: any = Promise.all(promiseArray);
                    <#else>
Mosher's avatar
Mosher committed
156
            let promise: any = curService['${item.getPSAppDEMethod().getCodeName()}'](context, data);
Mosher's avatar
Mosher committed
157 158 159 160 161 162
                    </#if>
            promise.then(async (response: any) => {
                    <#if item.getActionTarget() == 'SINGLEDATA'>
                Util.clearAdditionalData(tempData, args[0]);
                    </#if>
                if ((!response || response.status !== 200) && !Array.isArray(response)) {
163 164 165
                    actionContext.$Notice.error({ title: '错误', desc: response.message });
                    return;
                }
Mosher's avatar
Mosher committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
                let { data } = response;
                if (Array.isArray(response) && response.length > 0) {
                    data = [];
                    response.forEach((item: any) => {
                        data.push(item.data);
                    })
                }
                    <#--  合并参数  -->
                    <#if item.getPSAppDEMethod().isCustomCode?? && item.getPSAppDEMethod().isCustomCode() && !(item.getPSAppDEMethod().getPSDEServiceAPIMethod?? && item.getPSAppDEMethod().getPSDEServiceAPIMethod()??)>
                if (args && args.length > 0 && Object.prototype.toString.call(data) === '[Object Object]') {
                    Object.assign(args[0], data);
                    actionContext.$forceUpdate();
                }
                    </#if>
                    <#if item.isShowBusyIndicator()>
                        <#if item.getSuccessMsg?? && item.getSuccessMsg()??>
182
                actionContext.$Notice.success({ title: '成功', desc: '${item.getSuccessMsg()}' });
Mosher's avatar
Mosher committed
183
                        <#else>
184
                actionContext.$Notice.success({ title: '成功', desc: '${item.getCaption()}成功!' });
Mosher's avatar
Mosher committed
185 186
                        </#if>
                    </#if>
187
                <#--  是否重新加载数据  -->
Mosher's avatar
Mosher committed
188
                    <#if item.isReloadData?? && item.isReloadData()>
189 190 191
                if (xData && xData.refresh && xData.refresh instanceof Function) {
                    xData.refresh(args);
                }
Mosher's avatar
Mosher committed
192 193 194
                    </#if>
                    <#-- 关闭编辑视图 -->
                    <#if item.isCloseEditView()>
JunZai's avatar
JunZai committed
195
                actionContext.closeView(null);
Mosher's avatar
Mosher committed
196
                    </#if>
Mosher's avatar
Mosher committed
197
                    <#if item.isReloadData?? && item.isReloadData() && item.getRefreshMode?? && item.getRefreshMode()?? && item.getRefreshMode() == 1>
Mosher's avatar
Mosher committed
198
                if (xData && xData.getControlType instanceof Function && xData.getControlType() == 'FORM') {
Mosher's avatar
Mosher committed
199
                    AppCenterService.notifyMessage({ name: "${item.getPSAppDataEntity().getCodeName()}", action: 'appRefresh', data: args });
Mosher's avatar
Mosher committed
200 201 202 203 204 205 206 207 208 209 210
                }
                    </#if>
                    <#--  后续界面行为  -->
                    <#if item.getNextPSUIAction?? && item.getNextPSUIAction()??>
                let { data: result } = response;
                if (response && Array.isArray(response) && response.length > 0) {
                    result = [];
                    response.forEach((item: any) => {
                        result.push(item.data);
                    })
                }
211 212 213 214
                let _args: any[] = [];
                if (Object.is(actionContext.$util.typeOf(result), 'array')) {
                    _args = [...result];
                } else if (Object.is(actionContext.$util.typeOf(result), 'object')) {
Mosher's avatar
Mosher committed
215
                    _args = result && Object.keys(result).length > 0 ? [{ ...result }] : Util.deepCopy(args);
216
                } else {
Mosher's avatar
Mosher committed
217
                    _args = Util.deepCopy(args);
218
                }
Mosher's avatar
Mosher committed
219
                            <#if !(nextPSUIAction.getPSAppDataEntity?? && nextPSUIAction.getPSAppDataEntity()??)>
220
                if (_this.${nextPSUIAction.getFullCodeName()} && _this.${nextPSUIAction.getFullCodeName()} instanceof Function) {
Mosher's avatar
Mosher committed
221
                    _this.${nextPSUIAction.getFullCodeName()}(_args, context, params, $event, xData, actionContext);
222
                }
Mosher's avatar
Mosher committed
223
                            <#else>
224
                if (this.${nextPSUIAction.getFullCodeName()} && this.${nextPSUIAction.getFullCodeName()} instanceof Function) {
Mosher's avatar
Mosher committed
225
                    this.${nextPSUIAction.getFullCodeName()}(_args, context, params, $event, xData, actionContext);
226
                }
Mosher's avatar
Mosher committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                            </#if>
                    <#else>
                        <#if item.getUILogicAttachMode?? && item.getUILogicAttachMode()?? && item.getUILogicAttachMode() == 'AFTER' && item.getPSAppDEUILogic?? && item.getPSAppDEUILogic()??>
                const _context: any = Object.assign(context, actionContext.context);
                const _params: any = Object.assign(params, actionContext.viewparams);
                            <#if item.getPSAppDataEntity?? && item.getPSAppDataEntity()?? && item.getPSAppDEUILogic().getPSAppDataEntity?? && item.getPSAppDEUILogic().getPSAppDataEntity()?? && item.getPSAppDataEntity().codeName == item.getPSAppDEUILogic().getPSAppDataEntity().codeName>
                return this.executeUILogic('${item.getPSAppDEUILogic().codeName}', args, _context, _params, $event, xData, actionContext, srfParentDeName);
                            <#elseif item.getPSAppDEUILogic().getPSAppDataEntity?? && item.getPSAppDEUILogic().getPSAppDataEntity()??>
                const uiService = await window.uiServiceRegister.getService('${item.getPSAppDEUILogic().getPSAppDataEntity().codeName?lower_case}');
                if (uiService) {
                    return uiService.executeUILogic('${item.getPSAppDEUILogic().codeName}', args, _context, _params, $event, xData, actionContext, srfParentDeName);
                }
                            </#if>
                        </#if>
                    </#if>
242
            }).catch((response: any) => {
243 244
                if (response && response.status && response.data) {
                    actionContext.$Notice.error({ title: (actionContext.$t('app.commonWords.wrong') as string), desc: response.data.message });
245 246
                    return;
                }
247 248
                if (!response || !response.status || !response.data) {
                    actionContext.$Notice.error({ title: (actionContext.$t('app.commonWords.wrong') as string), desc: (actionContext.$t('app.commonWords.sysException') as string) });
249 250 251 252
                    return;
                }
                return response;
            });
Mosher's avatar
Mosher committed
253
                <#else>
254
            actionContext.$Notice.error({ title: '错误', desc: '模型异常,应用实体方法不存在' });
Mosher's avatar
Mosher committed
255
                </#if>
256
        };
Mosher's avatar
Mosher committed
257 258 259 260
                <#if item.getFrontPSAppView()??>
                    <#assign frontview = item.getFrontPSAppView()>
                    <#--  抽屉打开  -->
                    <#if frontview.getOpenMode()?index_of('DRAWER') == 0>
261 262 263 264 265 266 267 268 269 270
        const view: any = {
            viewname: '${srffilepath2(frontview.getCodeName())}',
            title: actionContext.<@getViewLanguageTitle frontview />,
            height: ${frontview.getHeight()?c},
            width: ${frontview.getWidth()?c},
            placement: '${frontview.getOpenMode()}'
        };
        const appdrawer = actionContext.$appdrawer.openDrawer(view,context,data);
        appdrawer.subscribe((result: any) => {
            if (result && Object.is(result.ret, 'OK')) {
Mosher's avatar
Mosher committed
271 272 273 274 275 276 277
                if(data && data instanceof Array && data.length > 0){
                    data.forEach((item:any) => {
                        Object.assign(item, { srfactionparam: result.datas });
                    })
                } else {
                    Object.assign(data, { srfactionparam: result.datas });
                }
278 279 280 281
                backend();
            }
        });
        <#--  模态打开  -->
Mosher's avatar
Mosher committed
282
                    <#else>
283 284 285 286 287 288 289 290 291
        const view = { 
            viewname: '${srffilepath2(frontview.getCodeName())}', 
            title: actionContext.<@getViewLanguageTitle frontview />,
            height: ${frontview.getHeight()?c}, 
            width: ${frontview.getWidth()?c}, 
        };
        const appmodal = actionContext.$appmodal.openModal(view,context,data);
        appmodal.subscribe((result:any) => {
            if (result && Object.is(result.ret, 'OK')) {
Mosher's avatar
Mosher committed
292 293 294 295 296 297 298
                if(data && data instanceof Array && data.length > 0){
                    data.forEach((item:any) =>{
                        Object.assign(item, { srfactionparam: result.datas });
                    })
                } else {
                    Object.assign(data, { srfactionparam: result.datas });
                }
299 300 301
                backend();
            }
        });
Mosher's avatar
Mosher committed
302 303
                    </#if>
                <#else>
304
        backend();
Mosher's avatar
Mosher committed
305 306 307 308
                </#if>
            </#if>
        </#if>
    </#if>
309 310
    }
</#if>