/* * @Author:zouwenying * @Date: 2020-10-23 19:29:07 * @LastEditTime: 2020-11-13 18:43:56 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \vue-manage-system-master\src\utils\utils.js */ import Vue from 'vue' import newValidate from './newValidate.js'; import MsgBoxCom from '../components/msgBox'; Vue.prototype.$valid = newValidate; //全局混入 //mix_path为权限前缀 Vue.mixin({ computed: { $add() { return this.$store.getters["hasPermission"](this.mix_path + ":add") }, $del() { return this.$store.getters["hasPermission"](this.mix_path + ":del") }, $edit() { return this.$store.getters["hasPermission"](this.mix_path + ":edit") }, $query() { return this.$store.getters["hasPermission"](this.mix_path + ":query") }, } }) /** * @description: 弹出确认提示框 * @param {String} msg: 主消息 * @param {String} tipMsg: 提示内容 * @param {String} type: 告警类型 ['error', 'warn'] * @param {Object} params: 扩展参数 * @return {type}: null */ Vue.prototype.$msgBox = (msg = '', tipMsg = '删除后将无法恢复,是否继续?', type = 'error', params = {}) => new Promise((resolve, reject) => { const config = { width: '374px', showCancelButton: true, confirmButtonText: '确认', showClose: true, resolve: resolve, reject: reject, } Object.assign(config, params) const MsgBox = Vue.extend(MsgBoxCom) const dom = new MsgBox().$mount() document.getElementById('app').appendChild(dom.$el) dom.config = config dom.msg = msg dom.tipMsg = tipMsg dom.type = type }) /** * @description: 遍历节点是否存在当前值 * @param {Array} dataArr 数组对象 * @param {String|Number} val 比对值 * @param {String} valStr 比对字段 * @return {Boolean} 返回存在或不存在 */ Vue.prototype.__calleArr = function (dataArr, val, valStr) { for (let i in dataArr) { var data = dataArr[i]; if (data[valStr] === val) { return true; } else { if (data.children) { this.__calleArr(data.children, val, valStr) } } } } // 确认提示框 Vue.prototype.__confirm = function (msg = '确认要删除该数据?', title = '提示', settings) { let sets = Object.assign(settings || {}, { cancelButtonClass: 'el-button--medium', confirmButtonClass: 'el-button--medium', dangerouslyUseHTMLString: true, }) return this.$confirm(`

${msg}

`, title, sets); } /* 设置弹出组件 datakey 集合下各字段的值,根据params.data */ Vue.prototype.__setValue = function (datakey) { let obj = this[datakey]; for (let item in obj) { const str = this.params.data[item]; obj[item] = str ? str : _.isNumber(str) ? str : '' } } // Excel表格下载 Vue.prototype.__exportExcel = ( url = "Abnormal/getAllAbnormalExcel", params = {}, token = localStorage.getItem("SC_token") ) => { // eslint-disable-next-line no-param-reassign delete params.pageNum; // eslint-disable-next-line no-param-reassign delete params.pageSize; let link; if (document.getElementById("exportATag")) { link = document.getElementById("exportATag"); } else { link = document.createElement("a"); link.setAttribute("id", "exportATag"); link.style.display = "none"; } const httpReg = /(http|https):\/\/([\w.]+\/?)\S*/; let urlStr = httpReg.test(url) ? `${url}&` : `${url}?`; _.mapKeys(params, (val, key) => { if (!_.isEmpty(String(val)) && val) { urlStr += `${key}=${val}&`; } }); link.href = `${urlStr}access_token=${token}`; document.body.appendChild(link); link.click(); };