|
@@ -1,5 +1,5 @@
|
|
|
export const isValue = (val: any) => {
|
|
|
- if (val === null || val === undefined || val === '') {
|
|
|
+ if (val === null || val === undefined || (typeof val === 'string' && val.trim() === '') || (typeof val === 'object' && val?.length === 0)) {
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
@@ -57,7 +57,7 @@ export const findInListData = (data: Array<any>, current:any, key = "id", childr
|
|
|
|
|
|
if(!!item[children] && Array.isArray(item[children]) && item[children].length > 0){
|
|
|
|
|
|
- const findChildData = findInListData(item[children], current, key, children)
|
|
|
+ const findChildData: any = findInListData(item[children], current, key, children)
|
|
|
|
|
|
if(findChildData) return findChildData
|
|
|
|
|
@@ -68,7 +68,7 @@ export const findInListData = (data: Array<any>, current:any, key = "id", childr
|
|
|
return null
|
|
|
}
|
|
|
|
|
|
-export const formatGetParam = (params: Object) => {
|
|
|
+export const formatGetParam = (params: any) => {
|
|
|
let paramUrl = ''
|
|
|
Object.keys(params).forEach((v, i) => {
|
|
|
paramUrl += i === 0 ? `${v}=${encodeURIComponent(params[v])}` : `&${v}=${encodeURIComponent(params[v])}`
|
|
@@ -76,7 +76,7 @@ export const formatGetParam = (params: Object) => {
|
|
|
return paramUrl
|
|
|
}
|
|
|
|
|
|
-export const formatTableHeadFilters = (arr, text = 'dictLabel', value = 'dictValue') => {
|
|
|
+export const formatTableHeadFilters = (arr: Array<any>, text = 'dictLabel', value = 'dictValue') => {
|
|
|
return arr.map(v => {
|
|
|
v.value = v[value]
|
|
|
v.text = v[text]
|
|
@@ -84,60 +84,93 @@ export const formatTableHeadFilters = (arr, text = 'dictLabel', value = 'dictVal
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-export const YMDHms = (date) => {
|
|
|
+export const YMDHms = (date: any) => {
|
|
|
const _date = new Date(date)
|
|
|
const Y = `${_date.getFullYear()}`;
|
|
|
const M = `${_date.getMonth() + 1 < 10 ? `0${_date.getMonth() + 1}` : _date.getMonth() + 1}`;
|
|
|
- const D = `${_date.getDate() + 1 < 10 ? `0${_date.getDate()}` : _date.getDate()}`;
|
|
|
+ const D = `${_date.getDate() < 10 ? `0${_date.getDate()}` : _date.getDate()}`;
|
|
|
const H = `${_date.getHours() < 10 ? `0${_date.getHours()}` : _date.getHours()}`;
|
|
|
const m = `${_date.getMinutes() < 10 ? `0${_date.getMinutes()}` : _date.getMinutes()}`;
|
|
|
const s = _date.getSeconds() < 10 ? `0${_date.getSeconds()}` : _date.getSeconds();
|
|
|
return `${Y}-${M}-${D} ${H}:${m}:${s}`;
|
|
|
}
|
|
|
|
|
|
-export const YMD = (date) => {
|
|
|
+export const YMD = (date: any, format = false) => {
|
|
|
const _date = new Date(date)
|
|
|
const Y = `${_date.getFullYear()}`;
|
|
|
const M = `${_date.getMonth() + 1 < 10 ? `0${_date.getMonth() + 1}` : _date.getMonth() + 1}`;
|
|
|
- const D = `${_date.getDate() + 1 < 10 ? `0${_date.getDate()}` : _date.getDate()}`;
|
|
|
- return `${Y}-${M}-${D}`;
|
|
|
+ const D = `${_date.getDate() < 10 ? `0${_date.getDate()}` : _date.getDate()}`;
|
|
|
+ return format ? `${Y}年${M}月${D}日` : `${Y}-${M}-${D}`;
|
|
|
+}
|
|
|
+
|
|
|
+export const Hms = (date: any, format = false) => {
|
|
|
+ const _date = new Date(date)
|
|
|
+ const H = `${_date.getHours() < 10 ? `0${_date.getHours()}` : _date.getHours()}`;
|
|
|
+ const m = `${_date.getMinutes() < 10 ? `0${_date.getMinutes()}` : _date.getMinutes()}`;
|
|
|
+ const s = _date.getSeconds() < 10 ? `0${_date.getSeconds()}` : _date.getSeconds();
|
|
|
+ return format ? `${H}时${m}分${s}秒` : `${H}:${m}:${s}`;
|
|
|
}
|
|
|
|
|
|
//防抖
|
|
|
-export const debounce = function (cb, ms = 0) {
|
|
|
- let timer = null
|
|
|
+export const debounce = function (cb: any, ms = 0) {
|
|
|
+ let timer: any = null
|
|
|
return function () {
|
|
|
if (timer) clearTimeout(timer)
|
|
|
timer = setTimeout(() => {
|
|
|
+ // @ts-ignore
|
|
|
cb.apply(this, arguments)
|
|
|
timer = null
|
|
|
}, ms)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export const comTime = (time) => {
|
|
|
+export const comTime = (time: any, format = false) => {
|
|
|
const sAll = time
|
|
|
const d = Math.floor(sAll / (1000 * 60 * 60 * 24))
|
|
|
const h = Math.floor((sAll - d * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
|
|
|
const m = Math.floor((sAll - d * (1000 * 60 * 60 * 24) - h * (1000 * 60 * 60)) / (1000 * 60))
|
|
|
const s = Math.floor((sAll - d * (1000 * 60 * 60 * 24) - h * (1000 * 60 * 60) - m * (1000 * 60)) / 1000)
|
|
|
- return{
|
|
|
- d, h, m ,s
|
|
|
+ let result: any = {d, h, m ,s}
|
|
|
+ if (format) {
|
|
|
+ result = ''
|
|
|
+ if (d > 0) {
|
|
|
+ result += d + '天'
|
|
|
+ }
|
|
|
+ if (d > 0 || h > 0) {
|
|
|
+ result += h + '时'
|
|
|
+ }
|
|
|
+ if (d > 0 || h > 0 || m > 0) {
|
|
|
+ result += m + '分'
|
|
|
+ }
|
|
|
+ result += s + '秒'
|
|
|
}
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
-export const comTimeByArea = (start, end) => {
|
|
|
+export const comTimeByArea = (start: any, end: any, format = false) => {
|
|
|
const sAll = new Date(end).getTime() - new Date(start).getTime()
|
|
|
const d = Math.floor(sAll / (1000 * 60 * 60 * 24))
|
|
|
const h = Math.floor((sAll - d * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
|
|
|
const m = Math.floor((sAll - d * (1000 * 60 * 60 * 24) - h * (1000 * 60 * 60)) / (1000 * 60))
|
|
|
const s = Math.floor((sAll - d * (1000 * 60 * 60 * 24) - h * (1000 * 60 * 60) - m * (1000 * 60)) / 1000)
|
|
|
- return{
|
|
|
- d, h, m ,s
|
|
|
+ let result: any = {d, h, m ,s}
|
|
|
+ if (format) {
|
|
|
+ result = ''
|
|
|
+ if (d > 0) {
|
|
|
+ result += d + '天'
|
|
|
+ }
|
|
|
+ if (d > 0 || h > 0) {
|
|
|
+ result += h + '时'
|
|
|
+ }
|
|
|
+ if (d > 0 || h > 0 || m > 0) {
|
|
|
+ result += m + '分'
|
|
|
+ }
|
|
|
+ result += s + '秒'
|
|
|
}
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
-export const deepAssign = (...obj) => {
|
|
|
+export const deepAssign = (...obj: any) => {
|
|
|
const result = Object.assign({}, ...obj)
|
|
|
for (let item of obj) {
|
|
|
for (let [idx, val] of Object.entries(item)) {
|
|
@@ -151,7 +184,7 @@ export const deepAssign = (...obj) => {
|
|
|
return result
|
|
|
}
|
|
|
|
|
|
-export const copy = (value) => {
|
|
|
+export const copy = (value: any) => {
|
|
|
const str = document.createElement('input')
|
|
|
str.setAttribute('value', value)
|
|
|
document.body.appendChild(str)
|
|
@@ -179,9 +212,9 @@ export const copy = (value) => {
|
|
|
* [20.7, '#eeeeee']
|
|
|
* ])
|
|
|
*/
|
|
|
-export const getGradientColorArray = (precision, colorArr) => {
|
|
|
+export const getGradientColorArray = (precision: any, colorArr: any) => {
|
|
|
// 将hex表示方式转换为rgb表示方式(这里返回rgb数组模式)
|
|
|
- const colorRgb = (sColor) => {
|
|
|
+ const colorRgb = (sColor: any) => {
|
|
|
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
|
|
let _sColor = sColor.toLowerCase();
|
|
|
if (_sColor && reg.test(_sColor)) {
|
|
@@ -195,6 +228,7 @@ export const getGradientColorArray = (precision, colorArr) => {
|
|
|
//处理六位的颜色值
|
|
|
const sColorChange = [];
|
|
|
for (let i = 1; i < 7; i += 2) {
|
|
|
+ // @ts-ignore
|
|
|
sColorChange.push(parseInt("0x" + _sColor.slice(i, i + 2)));
|
|
|
}
|
|
|
return sColorChange;
|
|
@@ -203,7 +237,7 @@ export const getGradientColorArray = (precision, colorArr) => {
|
|
|
}
|
|
|
};
|
|
|
// 将rgb表示方式转换为hex表示方式
|
|
|
- const colorHex = (rgb) => {
|
|
|
+ const colorHex = (rgb: any) => {
|
|
|
const _this = rgb;
|
|
|
const reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
|
|
|
if (/^(rgb|RGB)/.test(_this)) {
|
|
@@ -211,7 +245,7 @@ export const getGradientColorArray = (precision, colorArr) => {
|
|
|
let strHex = "#";
|
|
|
for (let i = 0; i < aColor.length; i++) {
|
|
|
let hex = Number(aColor[i]).toString(16);
|
|
|
- hex = hex < 10 ? 0 + '' + hex : hex;// 保证每个rgb的值为2位
|
|
|
+ hex = Number(hex) < 10 ? 0 + '' + hex : hex;// 保证每个rgb的值为2位
|
|
|
if (hex === "0") {
|
|
|
hex += hex;
|
|
|
}
|
|
@@ -236,17 +270,17 @@ export const getGradientColorArray = (precision, colorArr) => {
|
|
|
return _this;
|
|
|
}
|
|
|
}
|
|
|
- const rgb2hex = (sRGB) => {
|
|
|
+ const rgb2hex = (sRGB: any) => {
|
|
|
const reg = /^(RGB|rgb)\((\d+),\s*(\d+),\s*(\d+)\)$/
|
|
|
if (!reg.test(sRGB)) return sRGB
|
|
|
const rgbArr = sRGB.match(/\d+/g)
|
|
|
- const resultRgbArr = rgbArr.map(v => {
|
|
|
+ const resultRgbArr = rgbArr.map((v: any) => {
|
|
|
if (+v > 16) return (+v).toString(16)
|
|
|
return '0' + (+v).toString(16)
|
|
|
})
|
|
|
return '#' + resultRgbArr.join('')
|
|
|
}
|
|
|
- const gradientColor = (startColor, endColor, step) => {
|
|
|
+ const gradientColor = (startColor: any, endColor: any, step: any) => {
|
|
|
const startRGB = colorRgb(startColor);//转换为rgb数组模式
|
|
|
const startR = startRGB[0];
|
|
|
const startG = startRGB[1];
|
|
@@ -262,12 +296,13 @@ export const getGradientColorArray = (precision, colorArr) => {
|
|
|
for (let i = 0; i <= step; i++) {
|
|
|
//计算每一步的hex值
|
|
|
const hex = colorHex('rgb(' + parseInt((sR * i + startR)) + ',' + parseInt((sG * i + startG)) + ',' + parseInt((sB * i + startB)) + ')');
|
|
|
+ // @ts-ignore
|
|
|
colorArr.push(rgb2hex(hex));
|
|
|
}
|
|
|
return colorArr;
|
|
|
}
|
|
|
const colorMap = new Map()
|
|
|
- colorArr.forEach((v, i) => {
|
|
|
+ colorArr.forEach((v: any, i: number) => {
|
|
|
if (i < colorArr.length - 1) {
|
|
|
const _arr = gradientColor(v[1], colorArr[i + 1][1], (Number(colorArr[i + 1][0]) - Number(v[0])) / precision)
|
|
|
_arr.forEach((cV, cI) => {
|
|
@@ -279,3 +314,128 @@ export const getGradientColorArray = (precision, colorArr) => {
|
|
|
})
|
|
|
return colorMap
|
|
|
}
|
|
|
+// 根据部门名称 寻找上级所有父节点名称
|
|
|
+//data:要遍历的数据, target:查找目标, result用于装查找结果的数组
|
|
|
+export const findParent = (data: any, target: any, result: any) => {
|
|
|
+ for (let item of data) {
|
|
|
+ if (item.deptName === target) {
|
|
|
+ //将查找到的目标数据加入结果数组中
|
|
|
+ //可根据需求unshift(item.id)或unshift(item)
|
|
|
+ result.unshift(item.deptName);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (item.children && item.children.length > 0) {
|
|
|
+ let isFind = findParent(item.children, target, result);
|
|
|
+ if (isFind) {
|
|
|
+ result.unshift(item.deptName);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+};
|
|
|
+
|
|
|
+// 涉及到跨域问题,需要配nginx代理的url地址处理
|
|
|
+export const proxyNginxUrl = (url: string) => {
|
|
|
+ if (url) {
|
|
|
+ // @ts-ignore
|
|
|
+ const apiMapper = window.cusConfig?.nginxApiMapper || new Map()
|
|
|
+ let newUrl = url
|
|
|
+ apiMapper.forEach((v: any, k: any) => {
|
|
|
+ if (url.includes(k)) {
|
|
|
+ newUrl = v + url.substring(url.indexOf(k) + k.length, url.length)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return newUrl
|
|
|
+ }
|
|
|
+ return url
|
|
|
+};
|
|
|
+
|
|
|
+// 后端接口拦截 < > 内的文本,正反向格式化为 /《/ /》/ res = true 为接收返回值进行格式化
|
|
|
+export const formatInputHtmlInterceptor = (html: string, res = true) => {
|
|
|
+ if (html) {
|
|
|
+ const map = new Map()
|
|
|
+ map.set('<', '_《_')
|
|
|
+ map.set('>', '_》_')
|
|
|
+ let nHtml = html.toString()
|
|
|
+ map.forEach((v, k) => {
|
|
|
+ if (res) {
|
|
|
+ nHtml = nHtml.replace(eval(`/${v}/g`), k)
|
|
|
+ } else {
|
|
|
+ nHtml = nHtml.replace(eval(`/${k}/g`), v)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return nHtml
|
|
|
+ }
|
|
|
+ return html
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//生成从minNum到maxNum的随机数
|
|
|
+// export const randomNum = (minNum: number,maxNum: number) => {
|
|
|
+// return parseInt(String(Math.random() * (maxNum - minNum + 1) + minNum),10);
|
|
|
+// }
|
|
|
+
|
|
|
+export const randomNum = (min = 0, max = 0, decimal=0) => {
|
|
|
+ // 获取数值的小数部分
|
|
|
+ const getDecimalNum = (data: number) => {
|
|
|
+ return Number(data.toString().split('.')[1]);
|
|
|
+ }
|
|
|
+ let min_z = Math.trunc(min); // 最小值的整数部分
|
|
|
+ let max_z = Math.trunc(max); // 最大值的整数部分
|
|
|
+ // 判断是否存在小数部分,不存在的话为0
|
|
|
+ let min_x = isNaN(getDecimalNum(min)) ? 0 : getDecimalNum(min); // 最小值的小数部分
|
|
|
+ let max_x = isNaN(getDecimalNum(max)) ? 0 : getDecimalNum(max); // 最大值的小数部分
|
|
|
+
|
|
|
+ // 区分有小数和没小数的情况
|
|
|
+ if (min_x > 0 || max_x > 0 || decimal > 0) {
|
|
|
+ // 整数部分随机数
|
|
|
+ let z = parseInt(String(Math.random() * (max_z - min_z + 1) + min_z), 10);
|
|
|
+ // 小数部分随机数
|
|
|
+ let x = 0;
|
|
|
+ // 小数部分随机数最大位数
|
|
|
+ let max_decimal = min_x.toString().length > max_x.toString().length ? min_x.toString().length : max_x.toString().length;
|
|
|
+ max_decimal = decimal > max_decimal ? decimal : max_decimal;
|
|
|
+ // 判断随机出的整数部分,是否等于最小值或者最大值
|
|
|
+ if(z == min_z || z == max_z){
|
|
|
+ if(z == min_z){
|
|
|
+ // 整数部分随机数等于最小值,那么应该从最小值的小数部分开始,到小数位数的最大值随机就可以
|
|
|
+ x = parseInt(String(Math.random() * (Math.pow(10, max_decimal) - min_x) + min_x), 10);
|
|
|
+ }else{
|
|
|
+ // 整数部分随机数等于最大值,那么应该从0开始,到最大值小数部分
|
|
|
+ x = parseInt(String(Math.random() * (max_x + 1)), 10);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 整数部分在最大最小值区间的,就从0到小数位数的最大值随机就可以
|
|
|
+ x = parseInt(String(Math.random() * (Math.pow(10, max_decimal))), 10);
|
|
|
+ }
|
|
|
+ return Number(`${z}.${x}`);
|
|
|
+ } else {
|
|
|
+ return parseInt(String(Math.random() * (max_z - min_z + 1) + min_z), 10);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @param val 处理的数值
|
|
|
+ * @param unit 单位,默认空字符
|
|
|
+ * @param digits 小数,默认1
|
|
|
+ */
|
|
|
+export const formatNumberUnit = (val, unit = '', digits = 1) => {
|
|
|
+ let num = ''
|
|
|
+ let str = ''
|
|
|
+ if (String(val).length < 5) {
|
|
|
+ num = val
|
|
|
+ str = unit
|
|
|
+ } else if (String(val).length < 9) {
|
|
|
+ num = Number((Number(val) / 10000).toFixed(digits)) / 1 + ''
|
|
|
+ str = '万' + unit
|
|
|
+ } else if (String(val).length < 13) {
|
|
|
+ num = Number((Number(val) / 10000 / 10000).toFixed(digits)) / 1 + ''
|
|
|
+ str = '亿' + unit
|
|
|
+ }
|
|
|
+ return {
|
|
|
+ num: num, unit: str
|
|
|
+ }
|
|
|
+}
|