commonFunctions.js 5 KB
Newer Older
fukai 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
import Api from "../service/Api";

export default {
    methods: {
        loading(text) {
            return this.$loading({
                lock: true,
                text,
                spinner: 'el-icon-loading',
                background: 'rgba(200, 200, 200, 0.3)',
            });
        },
        //获取公共组件开关
        // async ejectOitWarning(tblnam) {
        //     let stbVo = {tbl: tblnam};
        //     let params = {stbVo: stbVo};
        //     let rtnmsg = await Api.post(`/${this.moduleRouter()}/codetable/configOpen`, params);
        //     if (rtnmsg.respCode === SUCCESS) {
        //         return rtnmsg.data.stbVoList[0].srt;
        //     }
        // },
        //弹出oit的warning
        async ejectOitWarning(objtyp, extkey, path) {
            let params = {objtyp: objtyp, extkey: extkey, path: path};
            let rtnmsg = await Api.post(`/${this.moduleRouter()}/oit/oitcheck`, params);
            if (rtnmsg.respCode === SUCCESS) {
                this.handleShowWarning(rtnmsg);
            }
        },
        handleShowWarning(response) {
            if (response.warnList && response.warnList.length) {
                let curWarnList = [];
                if (this.root) {
                    curWarnList = this.root.model.warnList || []
                }
                curWarnList = this.model.warnList || [];
                response.warnList.map((resItem) => {
                    if (resItem.message) {
                        let hasFlag = curWarnList.some((item) => {
                            return item.key === resItem.key
                        });
                        if (hasFlag) {
                            curWarnList.forEach((item) => {
                                if (item.key === resItem.key) {
                                    if (item.message !== resItem.message) {
                                        Object.assign(item, resItem)
                                    }

                                }
                            })
                        } else {
                            curWarnList.push(resItem)
                        }
                    } else {
                        let ind = curWarnList.findIndex((item) => {
                            return item.key === resItem.key
                        });
                        if (ind > -1) {
                            curWarnList.splice(ind, 1)
                        }
                    }
                });
                if (this.root) {
                    this.$set(this.root.model, 'warnList', curWarnList)
                }
                this.$set(this.model, 'warnList', curWarnList);
                // 判断是否存在未读的warning,不存在则不弹出弹框,存在即弹出
                let isHasNoRead = false;
                if (curWarnList && curWarnList.length > 0) {
                    isHasNoRead = curWarnList.some((item) => {
                        return item.readFlag === 'N'
                    })
                }
                if (isHasNoRead) {
                    this.$store.commit('updateWarningVisible', true)
                }
            }
        },
        getCodeLabel(value, param) {
            let codeTable = [];
            if (Array.isArray(param)) {
                codeTable = [...param];
            } else if (typeof param === 'string') {
                // codeTable = this.codes[param];
                codeTable = this.getObjectProperty(param, this.codes);
            }
            if (!codeTable) {
                return value;// 如果没有找到对应的码表,返回原值
            }
            const item = codeTable.find(item => item.value === value);
            return item ? item.label : value;// 如果找到对应项则返回label,否则返回原值
        },
        getObjectProperty(str, obj) {
            if (typeof str !== 'string' || typeof obj !== 'object' || obj === null) {
                return undefined;// 如果参数类型不正确,返回undefined
            }
            if (str.includes('.')) {
                // 分割字符串以获取属性名
                var properties = str.split('.');
                let currentObj = obj;
                // 遍历属性名并深入对象
                for (let i = 0; i < properties.length; i++) {
                    if (currentObj.hasOwnProperty(properties[i])) {
                        currentObj = currentObj[properties[i]];
                    } else {
                        return undefined;// 如果属性不存在,返回undefined
                    }
                }
                return currentObj;// 返回找到的属性值
            } else {
                // 如果字符串不包含`.`,直接返回对象的属性
                return obj[str];
            }
        }
    },
    computed: {
        isInfo() {
            let trnName = this.root ? this.root.trnName : this.trnName;
            if (trnName && trnName.endsWith("inf")) {
                return true
            }
            return false
        }
    }
};