import { Notification } from 'element-ui'; import router from '@/router'; export default { // 获取应用权限 checkAuth (appname,auth) { try { // 获取应用数据 let apps = JSON.parse(sessionStorage.getItem('active_modules')) let module_list = apps.apps // 获取当前应用数据 let active_modules = module_list.filter(item => { return item.name === appname }) // 获取当前应用权限 let auth_list = active_modules[0].meta.auth // 判断是否拥有权限 let _haveAuth = auth_list.some(item=>item.option === auth) return _haveAuth } catch (error) { router.replace('/home') } }, // 获取应用表格 tabelCol (appname) { // 获取应用数据 let apps = JSON.parse(sessionStorage.getItem('active_modules')) let module_list = apps.apps // 获取当前应用数据 let active_modules = module_list.filter(item => { return item.name === appname }) // 获取当前应用表格数据 let tablecols = active_modules[0].meta.tables return tablecols }, // 操作响应提示 showMessage (res,success) { if (res.code === 0) return Notification({ title: '失败', message: res.msg, type: 'error' }); Notification({ title: '成功', message: '操作成功', type: 'success' }); success?success():'' }, // 处理省市县数据结构 createMenu (node) { var that = this let obj = Object.keys(node).map((key,index,item)=>{ var elNode = { label: key, value: key, item:node[key], } return elNode; }) obj.forEach(e=>{ if ((e.item) instanceof Array) { e.children = [] e.item.forEach(c=>{ e.children.push({ label:c, value:c }) }) } else { if (Object.keys(e.item).length !== 0) { e.children = that.createMenu(e.item) } } }) return obj }, // 导出excel exportExcel(a,b,c,d) { let formatJson = function(filterVal, jsonData) { return jsonData.map(v => filterVal.map(j => v[j])) } require.ensure([], () => { const { export_json_to_excel } = require('./excel/Export2Excel'); const tHeader = a; // 设置Excel的表格第一行的标题 const filterVal = b; // index、nickName、name是tableData里对象的属性 const list = c; //把data里的tableData存到list const data = formatJson(filterVal, list); export_json_to_excel(tHeader, data, d); //导出Excel 文件名 }) }, // 数组去重 unique(arr, uniId){ const res = new Map(); return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1)); }, // 金额格式化 formatAmount(amount, decimalDigits = 0) { const amountStr = String(Number(amount).toFixed(decimalDigits)) const reg = /\B(?=(?:\d{3})+$)/g // 是否是小数 const isDecimal = amountStr.indexOf('.') > -1 if (isDecimal) { // 整数部分 const integerPart = amountStr.substring(0, amountStr.indexOf('.')) // 小数部分 const decimalPart = amountStr.substring(amountStr.length, amountStr.indexOf('.')) return `${integerPart.replace(reg, ',')}${decimalPart}` } else { return amountStr.replace(reg, ',') } } }