123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- /*
- * @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(`<p class="text_normal bold">${msg}</p>`, 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();
- };
|