123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- import { Message } from 'element-ui';
- import store from "../store/index";
- import router from '@/router';
- import api from '@/api/api';
- import { set } from 'nprogress';
- let timer = null,
- _uids = [];
- export default {
- // 获取应用权限
- checkAuth (appname,auth) {
- // await this.sleep(3000)
- let _haveAuth = false
- let app = JSON.parse(sessionStorage.getItem('activeApp'))
- // 获取当前应用权限
- let auth_list = app.meta.auth
- // 判断是否拥有权限
- _haveAuth = auth_list.some(item=>item.option === auth)
- return _haveAuth
- },
- // 获取应用表格
- tabelCol (appname) {
- 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 tablecols = active_modules[0].meta.tables
- return tablecols
- } catch (error) {
- console.log(error,'tool')
- }
- },
- // 操作响应提示
- showMessage (res,success) {
- let message = '操作成功'
- try {
- message = res.msg || '操作成功'
- } catch (error) {
- }
- try {
- message = store.state._this.$t(message)
- } catch (error) {
- }
- if (res.code === 0) return Message({
- message,
- type: 'error',
- duration:3000,
- showClose:true
- });
- Message({
- message,
- type: 'success',
- duration:3000,
- showClose:true
- });
- success?success():''
- },
- /* 获取基本地址 */
- getBaseUrl () {
- // if (process.env.NODE_ENV == 'development') return 'https://oms.idcgroup.com.cn:8079'
- // if (process.env.NODE_ENV == 'development') return '/apis'
- let href = window.location.href
- let index = href.indexOf('/')
- let num = 0
- while (index != -1) {
- num++
- index = href.indexOf('/',index+1)
- if (num++ == 3) {
- return href.slice(0,index)
- }
- }
- },
- // 处理省市县数据结构
- 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));
- },
- //国际化金融单位转换 10000 转换为 1000 100000000 转化为 100000000
- unitConversion(amount, dividend) {
- let lang = localStorage.getItem('lang') || 'ZH';
- if (lang != 'ZH') {
- if (dividend == 10000) {
- dividend = 1000
- } else if (dividend == 100000000) {
- dividend = 1000000000
- }
- }
- return amount / dividend
- },
- //非中文环境下,返回空
- onlyZh(value) {
- let lang = localStorage.getItem('lang') || 'ZH';
- return lang == 'ZH' ? value : ''
- },
- // 金额格式化
- formatAmount(amount, decimalDigits, unit='') {
- // const amountStr = String(Number(amount).toFixed(decimalDigits))
- let a = new Intl.NumberFormat(undefined, { minimumFractionDigits: decimalDigits, maximumFractionDigits: decimalDigits }).format(amount)
- const amountStr = String(a)
- 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 unit + `${integerPart.replace(reg, ',')}${decimalPart}`
- } else {
- return unit + amountStr.replace(reg, ',')
- }
- },
- /* 给指定组件触发$emit事件 */
- dispatchFun(componentName, eventName, vm) {
- var parent = vm.$parent || vm.$root;
- var name = parent.$options.componentName;
- while (parent && (!name || name !== componentName)) {
- parent = parent.$parent;
- if (parent) {
- name = parent.$options.componentName;
- }
- }
- if (parent) {
- parent.$emit.apply(parent, [eventName]);
- }
- },
- // 数组深度拷贝
- deepClone(obj) {
- let res = null;
- const reference = [Date, RegExp, Set, WeakSet, Map, WeakMap, Error];
- if (reference.includes(obj?.constructor)) {
- res = new obj.constructor(obj);
- } else if (Array.isArray(obj)) {
- res = [];
- obj.forEach((e, i) => {
- res[i] = this.deepClone(e);
- });
- } else if (typeof obj === "object" && obj !== null) {
- res = {};
- for (const key in obj) {
- if (Object.hasOwnProperty.call(obj, key)) {
- res[key] = this.deepClone(obj[key]);
- }
- }
- } else {
- res = obj;
- }
- return res;
- },
- // 数组排序
- sortArr (data,str) {
- let cache = {} // cache存储的键是eid,值是这个eid在indices数组中的下标
- let indices = [] // 数组中的每一个值是一个数组,数组中的每一个元素是原数组中相同eid的下标
- data.forEach((item, i) => {
- let eid = item[str]
- let index = cache[eid]
- if (index !== undefined) {
- indices[index].push(i)
- } else {
- cache[eid] = indices.length
- indices.push([i])
- }
- })
- let result = []
- indices.forEach(item => {
- item.forEach(index => {
- result.push(data[index]) // 依次把index对应的元素data[index]添加进去即可
- })
- })
- return result
- },
- calculatedColumnWidth(dom, layout) {
- if (!dom || _uids.includes(dom._uid)) return;
- _uids.push(dom._uid)
- let lang = localStorage.getItem('lang') || 'ZH';
- if (lang!='ZH') setTimeout(() => {
- try {
- const ths = dom.$el.querySelector('.el-table__header-wrapper').querySelectorAll('table thead tr:first-child th'),
- nodes = [];
- for (var key of ths.keys()) {
- const node = ths[key].querySelector('.cell')
- if (node && layout.some(v => v.title == node.innerText)) nodes.push(node);
- }
- layout.forEach((v,i) => {
- v.width = v.width > nodes[i].offsetWidth ? v.width : nodes[i].offsetWidth
- })
- _uids = _uids.filter(v => v != _uids)
- } catch (error) {}
- });
- return true
- },
- getStatusColor(status,isDetail = false){
- const colors = store.state.statusColorList;
- // console.log("colors", colors)
- if (isDetail){
- return colors[status] || "#999";
- }else{
- return colors[status] ? `color:${colors[status]}` : "#999";
- }
- },
- /*日期转化*/
- getDataChange(data){
- const newData = new Date(data)
- const year = newData.getFullYear()
- const month = String(newData.getMonth() + 1).padStart(2,'0')
- const date = String(newData.getDate()).padStart(2,'0')
- return year + '-' + month +'-' + date
- },
- /*查重项目格式化*/
- getCheckFontProject(data){
- data.map(item => {
- item.chars = item.chars.reduce((acc,ite) => ({
- ...acc,
- ...ite
- }),{})
- item.projectname = item.projectname.split('').map(text => {
- let projectname = item.chars.projectname.join("") || ''
- return projectname.includes(text) ? {
- text,
- color: 'red'
- } : {
- text,
- color: '#666'
- }
- })
- return item
- })
- },
- /*查重客户格式化*/
- getCheckFontEnterprisename(data){
- data.map(item => {
- item.chars = item.chars.reduce((acc,ite) => ({
- ...acc,
- ...ite
- }),{})
- item.enterprisename = item.enterprisename.split('').map(text => {
- let enterprisename = item.chars.enterprisename.join("") || ''
- return enterprisename.includes(text) ? {
- text,
- color: 'red'
- } : {
- text,
- color: '#666'
- }
- })
- return item
- })
- },
- /*公称压力格式化*/
- nominalPressureSet(val){
- let newPressure = ""
- if (val){
- val.forEach((item,index)=>{
- if (index == 0){
- newPressure = item
- }else {
- newPressure = newPressure + '/' + item
- // let str1 = item.substring(0,2)
- // let str2 = val[index -1].substring(0,2)
- // let str3 = item.substring(2)
- // if (str1 == str2){
- // if (newPressure == val[index -1]){
- // newPressure = val[index -1] + '/' + str3
- // }else {
- // newPressure = newPressure + '/' + str3
- // }
- // }else {
- //
- // }
- }
- })
- }else {
- newPressure = val
- }
- return newPressure && newPressure.length > 0 && newPressure != null?newPressure:'--'
- },
- /*数组数据展示*/
- ArrDataShow(data){
- let newArr = ''
- data.forEach((item,index)=>{
- if (index == data.length -1 || index == 0){
- newArr = newArr + item
- }else {
- newArr = newArr + ',' + item
- }
- })
- return newArr
- }
- }
|