WF_VIEW_CONTENT.tsx.ftl 5.4 KB
Newer Older
yanshaowei's avatar
yanshaowei committed
1 2 3 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
<#--  工作流内容  -->
<#if (view.getPSWorkflow?? && view.getPSWorkflow()??) && (view.isWFIAMode?? && view.isWFIAMode()) && (view.getWFStepValue?? && view.getWFStepValue() == "") && (view.getViewType?? && (view.getViewType() == 'DEWFEDITVIEW3' || view.getViewType() == 'DEWFEDITVIEW'))>
<#assign mounted_block>this.loadWFLinks();</#assign>

    /**
     * 加载权限按钮
     *
     * @memberof ${srfclassname('${view.name}')}
     */
    public loadWFLinks(): void {
        const url = '${app.getPKGCodeName()?lower_case}/${de.getPSSystemModule().codeName?lower_case}/${de.codeName?lower_case}/wflinks';
        const arg: any = {};
        if (this.engine && this.engine.viewdata && this.engine.viewdata.srfkey) {
            Object.assign(arg, { srfkey: this.engine.viewdata.srfkey });
        }
        if (!arg.srfkey || Object.is(arg.srfkey, '')) {
            return;
        }
        const get: Promise<any> = this.$http.get(url, arg, true);
        get.then((response: any) => {
            if (!response.status || response.status !== 200) {
                return;
            }
            const { data: _data } = response;
            this.containerModel.wflinks = _data;
        }).catch((response: any) => {
            console.log(response);
        });
    }

    /**
     * 工作流动态按钮 点击事件
     *
     * @param {*} item
     * @param {*} $event
     * @memberof ${srfclassname('${view.name}')}
     */
    public wflink_click(item: any, $event: any): void {
        if (Object.is(item.type, 'FRONT')) {
            this.wflink_front(item, $event);
        } else if (Object.is(item.type, 'BACKEND')) {
            this.wflink_backend(item, $event);
        }
    }

    /**
     *  前台界面行为
     *
     * @param {*} item
     * @param {*} $event
     * @memberof ${srfclassname('${view.name}')}
     */
    public wflink_front(item: any, $event: any): void {
        if (!item.page || Object.is(item.page, '')) {
            return;
        }

        const page: any = {};
        try {
            Object.assign(page, JSON.parse(item.page));
        } catch (error) {

        }
        if (Object.keys(page).length === 0) {
            return;
        }
        const arg: any = { srfparentdata: {} };
        const _this: any = this;
        if (_this.srfparentdata) {
            Object.assign(arg.srfparentdata, _this.srfparentdata);
        }

        if (this.engine && this.engine.viewdata && this.engine.viewdata.srfkey) {
            Object.assign(arg, { srfkey: this.engine.viewdata.srfkey });
        }
        if (!arg.srfkey || Object.is(arg.srfkey, '')) {
            return;
        }

        const viewname = this.$util.srfFilePath2(page.viewname);
        const view: any = {
            viewname: viewname,
            title: page.title,
            width: page.width,
            height: page.height,
        }
        let container: Subject<any> = this.$appmodal.openModal(view, arg);
        container.subscribe((result: any) => {
            if (!result || !Object.is(result.ret, 'OK')) {
                return;
            }
            const { datas: _datas } = result;
            const [data] = _datas;
            this.wflink_backend(item, $event, data);
        });
    }

    /**
     * 后台界面行为
     *
     * @param {*} item
     * @param {*} $event
     * @param {*} [data]
     * @memberof ${srfclassname('${view.name}')}
     */
    public wflink_backend(item: any, $event: any, data?: any): void {
        const _this: any = this;
        this.wf_Step(item, $event, data).then((response: any) => {
            if (!response.status || response.status !== 200) {
                if (response.errorMessage) {
                    this.$Notice.error({ title: '错误', desc: response.errorMessage });
                }
                return;
            }
            this.$Notice.success({ title: '', desc: item.name + '操作成功' });

            const { data: _data } = response;
            if (_this.viewdata) {
                _this.$emit('viewdataschange', [{ ..._data }]);
                _this.$emit('close');
            } else if (_this.$tabPageExp) {
                _this.$tabPageExp.onClose(_this.$route.fullPath);
            }
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
            this.$Notice.error({ title: '错误', desc: response.errorMessage });
        });
    }

    /**
     * 工作流步骤
     *
     * @private
     * @param {*} item
     * @param {*} $event
     * @param {*} [data]
     * @returns {Promise<any>}
     * @memberof ${srfclassname('${view.name}')}
     */
    private async wf_Step(item: any, $event: any, data?: any): Promise<any> {
        const arg: any = { args: {} };
        if (data) {
            Object.assign(arg, data);
        }
        if (this.engine && this.engine.viewdata && this.engine.viewdata.srfkey) {
            Object.assign(arg, { srfkey: this.engine.viewdata.srfkey });
        }
        if (!arg.srfkey || Object.is(arg.srfkey, '')) {
            return;
        }
        Object.assign(arg, { link: item.id });
        if (!arg.link || Object.is(arg.link, '')) {
            return;
        }

        const url: string = '${app.getPKGCodeName()?lower_case}/${de.getPSSystemModule().codeName?lower_case}/${de.codeName?lower_case}/wflink';
        const post: Promise<any> = this.$http.post(url, arg, true);
        return post;
    }
</#if>