/*
|
* @Description:
|
* @Version: 2.0
|
* @Autor: wuyun
|
* @Date: 2022-08-05 15:17:36
|
* @LastEditors: wuyun
|
* @LastEditTime: 2023-02-27 10:16:24
|
*/
|
// 公用方法
|
import { Menu } from '@element-plus/icons-vue'
|
import _ from 'lodash'
|
// import { useUserInfo } from '@/stores/userInfo'
|
|
// // 获取用户token
|
// export function getAdminToken() {
|
// const info = useUserInfo()
|
// return info.token
|
// }
|
// // 删除用户token
|
// export function removeAdminToken() {
|
// const info = useUserInfo()
|
// info.removeToken()
|
// }
|
|
// /**
|
// * @param {string} path
|
// * @returns {Boolean}
|
// */
|
export function isExternal(path: string) {
|
const isExternal = /^(https?:|http?:|mailto:|tel:)/.test(path)
|
return isExternal
|
}
|
/**
|
* 获取本地静态图片
|
* @param name // 文件名 如 404.svg
|
* @returns {*|string}
|
*/
|
export function getAssetsImages(name: string) {
|
return new URL(`/src/assets/images/${name}`, import.meta.url).href
|
}
|
|
/**
|
* 防抖
|
* @param fn 执行函数
|
* @param ms 间隔毫秒数
|
*/
|
// export const debounce = (fn: Function, ms: number) => {
|
// return (...args: any[]) => {
|
// if (window.lazy) {
|
// clearTimeout(window.lazy)
|
// }
|
// window.lazy = setTimeout(() => {
|
// fn(...args)
|
// }, ms)
|
// }
|
// }
|
|
/**
|
* 格式化接口返回的路由配置json或者树形菜单json
|
* @param treeList {Object[]} 接口返回的元原始数组
|
* @param ancestorVal {string} 最大一级菜单对应的parentId或者说是祖先节点的父节点标识
|
* @param parentId {string} 父级id对应的字段名称
|
* @return {Array} 整合后的树形结构
|
* 返回值示例 [ {id:'',name: '', children: []} ...] 具体字段名称根据接口实际返回值
|
*/
|
export function formatTree(
|
treeList: Menu[] = [],
|
ancestorVal: string = 'null',
|
parentId: string = 'parentId',
|
selfCode: string = 'id'
|
) {
|
treeList.map((element: any) => {
|
// 由于后端接口中存在null为祖父级,''为祖父级的混乱现象所以需要统一处理为null
|
if (element[parentId] == '') {
|
element[parentId] = null
|
}
|
return element
|
})
|
let treeObj = _.groupBy(treeList, parentId)
|
Object.keys(treeObj).forEach((key: any) => {
|
treeList.forEach((element: any) => {
|
if (element[selfCode] == key) {
|
element.children = _.orderBy(treeObj[key], ['sort'], ['asc'])
|
}
|
})
|
})
|
|
let result: Menu[] = []
|
if (treeObj[ancestorVal]) {
|
result = treeObj[ancestorVal]
|
} else {
|
result = treeList
|
}
|
|
return result
|
}
|
// 数组对象 通过键名进行分组生成map
|
export function getGroupByKey(arr: [], key: string) {
|
let result = []
|
result = arr.reduce((r, a) => {
|
r[a[key]] = r[a[key]] || []
|
r[a[key]].push(a)
|
return r
|
}, Object.create(null))
|
return result
|
}
|
|
// 产品页面根据dataSource的值跳转不同的查询和修改 新增 1 是旧 的其他的是新的
|
export function returnProductDetailPath(dataSource: string,type:string) {
|
let pathStr=''
|
if(dataSource!='1'){
|
//新路由
|
pathStr='/safety/performance/meritRatingNewDetail'
|
}else{
|
// 旧路由
|
if(type=='edit'){
|
pathStr='/safety/performance/meritRatingDetail'
|
}
|
else if(type=='view'){
|
pathStr='/safety/performance/meritRatingView'
|
}
|
}
|
return pathStr
|
}
|
|
export function numberToUpperCase(textIndex:number){
|
let newString = '';
|
let newTextIndex:any = (textIndex + 1) + '';
|
function sum(value:number, index:number) {
|
var newValue = '';
|
if ((textIndex === 9)) {
|
return !index ? '十' : '';
|
}
|
let isSeat = (~~textIndex > 9 && ~~textIndex < 19);
|
switch (~~value) {
|
case 1:
|
newValue = !index ? (isSeat ? '' : '一') : '十一';
|
break;
|
case 2:
|
newValue = !index ? (isSeat ? '' : '二') : '十二';
|
break;
|
case 3:
|
newValue = !index ? (isSeat ? '' : '三') : '十三';
|
break;
|
case 4:
|
newValue = !index ? (isSeat ? '' : '四') : '十四';
|
break;
|
case 5:
|
newValue = !index ? (isSeat ? '' : '五') : '十五';
|
break;
|
case 6:
|
newValue = !index ? (isSeat ? '' : '六') : '十六';
|
break;
|
case 7:
|
newValue = !index ? (isSeat ? '' : '七') : '十七';
|
break;
|
case 8:
|
newValue = !index ? (isSeat ? '' : '八') : '十八';
|
break;
|
case 9:
|
newValue = !index ? (isSeat ? '' : '九') : '十九';
|
break;
|
case 0:
|
newValue = '十';
|
break;
|
default:
|
break;
|
}
|
return newValue;
|
}
|
|
for (let i = 0; i < newTextIndex.length; i++) {
|
newString += sum(newTextIndex.substring(i, i + 1), i);
|
}
|
return newString;
|
}
|