commonApi.js 6.02 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
            }
fukai committed
55 56 57 58 59
            this.getRoot().$refs.modelForm.clearValidate();
            const fields = this.getRoot().$refs.modelForm.fields;
            const tab = Utils.positioningErrorMsg(fieldErrors, fields);
            return tab;
        },
潘际乾 committed
60
        loading(text) {
61 62 63 64 65 66 67 68
            const loading = this.$loading({
                lock: true,
                text,
                spinner: 'el-icon-loading',
                background: 'rgba(200, 200, 200, 0.3)'
            });
            return loading
        },
潘际乾 committed
69
        getRoot() {
fukai committed
70 71
            return (this.root || this)
        },
fukai committed
72
        async init(params) {
73
            const loading = this.loading("交易加载中")
潘际乾 committed
74 75 76
            let rtnmsg = await Api.post(this.requestPrefix + "/init", { params })
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
77
            }
78
            loading.close()
fukai committed
79
            return rtnmsg
fukai committed
80
        },
81 82
        async save(params) {
            const loading = this.loading("正在保存交易")
潘际乾 committed
83
            let rtnmsg = await Api.post(this.requestPrefix + "/saveData", this.wrapper(params))
84 85
            loading.close()
            return rtnmsg
fukai committed
86
        },
潘际乾 committed
87
        async executeCheck(rulePath, params) {
88
            const loading = this.loading("校验进行中")
潘际乾 committed
89 90 91
            let rtnmsg = await Api.post(this.requestPrefix + "/executeCheck/" + rulePath, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
92
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
93
            }
94
            loading.close()
fukai committed
95
            return rtnmsg
fukai committed
96
        },
fukai committed
97
        async executeDefault(rulePath, params) {
潘际乾 committed
98 99 100
            let rtnmsg = await Api.post(this.requestPrefix + "/executeDefault/" + rulePath, this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
101
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
102 103
            }
            return rtnmsg
fukai committed
104
        },
潘际乾 committed
105
        async executeRule(rulePath, params, delayCb) {
106
            const loading = this.loading("正在请求数据")
潘际乾 committed
107 108 109
            let rtnmsg = await Api.post(this.requestPrefix + "/executeRule/" + rulePath, this.wrapper(params, delayCb))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
110
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
111
            }
112
            loading.close()
fukai committed
113
            return rtnmsg
fukai committed
114
        },
zhengxiaokui committed
115
        async checkAll(params) {
116
            const loading = this.loading("正在校验数据")
潘际乾 committed
117 118 119
            const rtnmsg = await Api.post(this.requestPrefix + "/checkAll", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
120
            }
121
            loading.close()
fukai committed
122
            return rtnmsg
fukai committed
123
        },
124 125
        async pedding(params) {
            const loading = this.loading("正在暂存数据")
潘际乾 committed
126 127 128
            const rtnmsg = await Api.post(this.requestPrefix + "/pending", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
129 130 131
            }
            loading.close()
            return rtnmsg
fukai committed
132
        },
zhengxiaokui committed
133
        async restoreDisplay() {
fukai committed
134
            let inr = this.$route.query.trn
zhengxiaokui committed
135
            if (!inr)
fukai committed
136
                return
137
            const loading = this.loading("快照数据加载中")
潘际乾 committed
138 139
            let data = await display(inr)
            if (data.data) {
fukai committed
140
                Utils.copyValueFromVO(this.model, JSON.parse(data.data))
潘际乾 committed
141 142
            } else {
                this.$notify.error({ title: '错误', message: '快照文件加载失败!' });
fukai committed
143
            }
144
            loading.close()
145
        },
fukai committed
146
        async executeNotify(params) {
潘际乾 committed
147 148 149
            const rtnmsg = await Api.post(this.requestPrefix + "/executeNotify", this.wrapper(params))
            if (rtnmsg.respCode == SUCCESS) {
                this.updateValueSet(rtnmsg.codeSet)
fukai committed
150 151
            }
            return rtnmsg
152
        },
153 154 155 156 157 158 159 160 161 162 163 164 165
        /**
         * 打开详情页面
         * @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
166
    }
zhengxiaokui committed
167
}