commonApi.js 6.86 KB
Newer Older
fukai committed
1
import Vue from "vue"
fukai committed
2
import Api from "~/service/Api"
潘际乾 committed
3
import { display } from "~/service/business/file"
4
import { getTrnNameByInr } from "~/service/business/common"
fukai committed
5
import Utils from "../utils"
zhengxiaokui committed
6

fukai committed
7
export default {
zhengxiaokui committed
8
    data() {
fukai committed
9
    },
潘际乾 committed
10 11
    created() {
        if (this.root) {
fukai committed
12 13 14
            //非顶级vue实例,不需要执行
            return;
        }
潘际乾 committed
15 16
        if (this.codes) {
            Vue.set(this.codes, "codeSet", {})
fukai committed
17
        }
fukai committed
18
    },
zhengxiaokui committed
19
    mounted() {
fukai committed
20
        //this.restoreDisplay()
fukai committed
21
    },
zhengxiaokui committed
22
    methods: {
潘际乾 committed
23 24
        updateValueSet(values) {
            if (!values) {
fukai committed
25 26
                return
            }
fukai committed
27
            //顶级实例,进入设置
潘际乾 committed
28 29 30
            if (!this.root) {
                for (let key in values) {
                    Vue.set(this.codes.codeSet, key, values[key])
fukai committed
31 32
                }
            }
潘际乾 committed
33 34
            else {
                this.root.updateValueSet(values)
fukai committed
35 36
            }
        },
37
        //获取后台setValues、setCodeValues传来的动态码,并自动转为码表值
潘际乾 committed
38
        getValues(key) {
fukai committed
39
            let arr = this.codes.codeSet[key]
潘际乾 committed
40
            if (!arr)
41
                return undefined
潘际乾 committed
42 43 44 45
            return arr.map(item => {
                let itemArr = item.split("\t")
                if (itemArr.length > 1)
                    return { label: item, value: itemArr[0] }
46
                else
潘际乾 committed
47
                    return { label: itemArr[0], value: itemArr[0] }
48 49
            })
        },
潘际乾 committed
50
        showBackendErrors(fieldErrors) {
fukai committed
51
            // 清除之前的校验状态
潘际乾 committed
52
            if (!this.getRoot().$refs.modelForm) {
fukai committed
53 54
                return
            }
55 56 57 58 59 60
            if (!this.isChecking) {
                this.getRoot().$refs.modelForm.clearValidate();
            } else {
                // 当 checkAll 操作时,由面板切换所触发的 executeRule 请求时,不清空 checkAll 的错误信息
                this.isChecking = false;
            }
fukai committed
61 62 63 64
            const fields = this.getRoot().$refs.modelForm.fields;
            const tab = Utils.positioningErrorMsg(fieldErrors, fields);
            return tab;
        },
潘际乾 committed
65
        loading(text) {
66 67 68 69 70 71 72 73
            const loading = this.$loading({
                lock: true,
                text,
                spinner: 'el-icon-loading',
                background: 'rgba(200, 200, 200, 0.3)'
            });
            return loading
        },
潘际乾 committed
74
        getRoot() {
fukai committed
75 76
            return (this.root || this)
        },
fukai committed
77
        async init(params) {
78
            const loading = this.loading("交易加载中")
潘际乾 committed
79 80 81
            let rtnmsg = await Api.post(this.requestPrefix + "/init", { params })
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
82
            }
83
            loading.close()
fukai committed
84
            return rtnmsg
fukai committed
85
        },
86 87
        async save(params) {
            const loading = this.loading("正在保存交易")
潘际乾 committed
88
            let rtnmsg = await Api.post(this.requestPrefix + "/saveData", this.wrapper(params))
89 90
            loading.close()
            return rtnmsg
fukai committed
91
        },
潘际乾 committed
92
        async executeCheck(rulePath, params) {
93
            const loading = this.loading("校验进行中")
潘际乾 committed
94 95 96
            let rtnmsg = await Api.post(this.requestPrefix + "/executeCheck/" + rulePath, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
97
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
98
            }
99
            loading.close()
fukai committed
100
            return rtnmsg
fukai committed
101
        },
fukai committed
102
        async executeDefault(rulePath, params) {
潘际乾 committed
103 104 105
            let rtnmsg = await Api.post(this.requestPrefix + "/executeDefault/" + rulePath, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
106
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
107 108
            }
            return rtnmsg
fukai committed
109
        },
潘际乾 committed
110
        async executeRule(rulePath, params, delayCb) {
111
            const loading = this.loading("正在请求数据")
潘际乾 committed
112 113 114
            let rtnmsg = await Api.post(this.requestPrefix + "/executeRule/" + rulePath, this.wrapper(params, delayCb))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
115
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
116
            }
117
            loading.close()
fukai committed
118
            return rtnmsg
fukai committed
119
        },
liuxin committed
120 121 122 123 124 125 126 127 128 129 130 131 132
        async executeCustomRule(rulePath, params, delayCb) {
            const loading = this.loading("正在请求数据")
            //copy
            Utils.copyCustomFromModel(this.customModel, this.model)
            console.log(this.customModel)
            let rtnmsg = await Api.post(this.requestPrefix + "/executeRule/" + rulePath, this.wrapperCustom(params, delayCb))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
                this.showBackendErrors(rtnmsg.fieldErrors)
            }
            loading.close()
            return rtnmsg
        },
zhengxiaokui committed
133
        async checkAll(params) {
134
            const loading = this.loading("正在校验数据")
潘际乾 committed
135 136 137
            const rtnmsg = await Api.post(this.requestPrefix + "/checkAll", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
138
            }
139
            loading.close()
fukai committed
140
            return rtnmsg
fukai committed
141
        },
142 143
        async pedding(params) {
            const loading = this.loading("正在暂存数据")
潘际乾 committed
144 145 146
            const rtnmsg = await Api.post(this.requestPrefix + "/pending", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
147 148 149
            }
            loading.close()
            return rtnmsg
fukai committed
150
        },
zhengxiaokui committed
151
        async restoreDisplay() {
fukai committed
152
            let inr = this.$route.query.trn
zhengxiaokui committed
153
            if (!inr)
fukai committed
154
                return
155
            const loading = this.loading("快照数据加载中")
潘际乾 committed
156 157
            let data = await display(inr)
            if (data.data) {
fukai committed
158
                Utils.copyValueFromVO(this.model, JSON.parse(data.data))
潘际乾 committed
159 160
            } else {
                this.$notify.error({ title: '错误', message: '快照文件加载失败!' });
fukai committed
161
            }
162
            loading.close()
163
        },
fukai committed
164
        async executeNotify(params) {
潘际乾 committed
165 166 167
            const rtnmsg = await Api.post(this.requestPrefix + "/executeNotify", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
168 169
            }
            return rtnmsg
170
        },
171 172 173 174 175 176 177 178 179 180 181 182 183
        /**
         * 打开详情页面
         * @param {string} inr 
         */
        display(inr) {
            getTrnNameByInr({ inr }).then((res) => {
                if (res.respCode == SUCCESS) {
                    const trnName = res.data.toLowerCase();
                    let viewurl = "/#/display/" + trnName + "?trn=" + inr
                    window.open(viewurl, 'newwindow', 'height=1500,width=1200,top=100,left=100,toolbar=no,resizable=no,menubar=no,location=no, status=no');
                }
            });
        }
fukai committed
184
    }
zhengxiaokui committed
185
}