commonApi.js 5.5 KB
Newer Older
fukai committed
1
import Vue from "vue"
fukai committed
2 3
import Api from "~/service/Api"
import Utils from "../utils"
zhengxiaokui committed
4

fukai committed
5
export default {
zhengxiaokui committed
6
    data() {
fukai committed
7 8 9 10 11 12 13 14 15
       
    },
    created(){
        if(this.root){
            //非顶级vue实例,不需要执行
            return;
        }
        if(this.codes){
            Vue.set(this.codes,"codeSet",{})
fukai committed
16
        }
fukai committed
17
    },
zhengxiaokui committed
18
    mounted() {
fukai committed
19
        //this.restoreDisplay()
fukai committed
20
    },
zhengxiaokui committed
21
    methods: {
fukai committed
22 23 24 25
        updapteValueSet(values){
            if(!values){
                return
            }
fukai committed
26 27 28 29 30 31 32 33
            //顶级实例,进入设置
            if(!this.root){
                for(let key in values){
                    Vue.set(this.codes.codeSet,key,values[key])
                }
            }
            else{
                this.root.updapteValueSet(values)
fukai committed
34 35
            }
        },
36 37
        //获取后台setValues、setCodeValues传来的动态码,并自动转为码表值
        getValues(key){
fukai committed
38
            let arr = this.codes.codeSet[key]
39 40 41 42 43
            if(!arr)
                return undefined
            return arr.map(item=>{
               let itemArr =  item.split("\t")
               if(itemArr.length > 1)
fukai committed
44
                    return {label:item,value:itemArr[0]}
45
                else
fukai committed
46
                    return {label:itemArr[0],value:itemArr[0]}
47 48
            })
        },
fukai committed
49 50
        showBackendErrors(fieldErrors){
            // 清除之前的校验状态
fukai committed
51 52 53
            if(!this.getRoot().$refs.modelForm){
                return
            }
fukai committed
54 55 56 57 58 59
            this.getRoot().$refs.modelForm.clearValidate();
            const fields = this.getRoot().$refs.modelForm.fields;
            Utils.positioningErrorMsg(fieldErrors, fields);
            const tab = Utils.positioningErrorMsg(fieldErrors, fields);
            return tab;
        },
60 61 62 63 64 65 66 67 68
        loading(text){
            const loading = this.$loading({
                lock: true,
                text,
                spinner: 'el-icon-loading',
                background: 'rgba(200, 200, 200, 0.3)'
            });
            return loading
        },
fukai committed
69 70 71
        getRoot(){
            return (this.root || this)
        },
fukai committed
72
        async init(params) {
73
            const loading = this.loading("交易加载中")
fukai committed
74 75 76 77
            let rtnmsg = await Api.post(this.declareParams.trnName + "/init", { params })
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
            }
78
            loading.close()
fukai committed
79
            return rtnmsg
fukai committed
80
        },
fukai committed
81
        
82 83 84 85 86
        async save(params) {
            const loading = this.loading("正在保存交易")
            let rtnmsg = await Api.post(this.declareParams.trnName + "/saveData", this.wrapper(params))
            loading.close()
            return rtnmsg
fukai committed
87
        },
fukai committed
88
        async executeCheck(rulePath,params){
89
            const loading = this.loading("校验进行中")
fukai committed
90 91 92
            let rtnmsg = await  Api.post(this.declareParams.trnName+"/executeCheck/"+rulePath, this.wrapper(params))
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
fukai committed
93
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
94
            }
95
            loading.close()
fukai committed
96
            return rtnmsg
fukai committed
97
        },
fukai committed
98 99 100 101
        async executeDefault(rulePath, params) {
            let rtnmsg = await  Api.post(this.declareParams.trnName + "/executeDefault/" + rulePath, this.wrapper(params))
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
fukai committed
102
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
103 104
            }
            return rtnmsg
fukai committed
105
        },
fukai committed
106
        async executeRule(rulePath, params,delayCb) {
107
            const loading = this.loading("正在请求数据")
fukai committed
108 109 110
            let rtnmsg = await  Api.post(this.declareParams.trnName + "/executeRule/" + rulePath, this.wrapper(params,delayCb))
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
fukai committed
111
                this.showBackendErrors(rtnmsg.fieldErrors)
fukai committed
112
            }
113
            loading.close()
fukai committed
114
            return rtnmsg
fukai committed
115
        },
zhengxiaokui committed
116
        async checkAll(params) {
117
            const loading = this.loading("正在校验数据")
fukai committed
118 119 120 121
            const rtnmsg = await Api.post(this.declareParams.trnName + "/checkAll", this.wrapper(params))
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
            }
122
            loading.close()
fukai committed
123
            return rtnmsg
fukai committed
124
        },
125 126 127 128 129 130 131 132
        async pedding(params) {
            const loading = this.loading("正在暂存数据")
            const rtnmsg = await  Api.post(this.declareParams.trnName + "/pending", this.wrapper(params))
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
            }
            loading.close()
            return rtnmsg
fukai committed
133
        },
zhengxiaokui committed
134
        async restoreDisplay() {
fukai committed
135
            let inr = this.$route.query.trn
zhengxiaokui committed
136
            if (!inr)
fukai committed
137
                return
138
            const loading = this.loading("快照数据加载中")
zhengxiaokui committed
139
            let data = await Api.post("display/" + inr)
fukai committed
140 141 142 143 144 145
            if(data.data)
            {
                Utils.copyValueFromVO(this.model, JSON.parse(data.data))
            }else{
                this.$notify.error({title: '错误',message: '快照文件加载失败!'});
            }
146
            loading.close()
147
        },
fukai committed
148 149 150 151 152 153
        async executeNotify(params) {
            const rtnmsg = await  Api.post(this.declareParams.trnName + "/executeNotify", this.wrapper(params))
            if(rtnmsg.respCode == SUCCESS){
                this.updapteValueSet(rtnmsg.codeSet)
            }
            return rtnmsg
154
        },
fukai committed
155
    }
zhengxiaokui committed
156
}