267 lines
7.0 KiB
JavaScript
267 lines
7.0 KiB
JavaScript
![]() |
// import {
|
||
|
// getAddress
|
||
|
// } from "@/api/getAddress.js";
|
||
|
// import {
|
||
|
// getUserArea
|
||
|
// } from "@/api/base.js";
|
||
|
|
||
|
// 随机颜色 - 把16进制的颜色换成rgba格式
|
||
|
export function choseRbgb(color,opcity) {
|
||
|
if(color){
|
||
|
return 'rgba('+ parseInt('0x'+color.slice(1,3)) + ','+ parseInt('0x'+color.slice(3,5))+','+parseInt('0x'+color.slice(5,7)) + ','+opcity+')'
|
||
|
}else{
|
||
|
let r = Math.floor(Math.random()*256)
|
||
|
let g = Math.floor(Math.random()*256)
|
||
|
let b = Math.floor(Math.random()*256)
|
||
|
let a = opcity ? opcity :1;
|
||
|
return `rgba(${r},${g},${b},${a})`
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 毫秒转时长
|
||
|
export function formatDuring(mss) {
|
||
|
var days = parseInt(mss / (1000 * 60 * 60 * 24));
|
||
|
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
|
||
|
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
|
||
|
var seconds = (mss % (1000 * 60)) / 1000;
|
||
|
if (days) {
|
||
|
return days + "天" + hours + "小时" + minutes + "分钟" + seconds + "秒";
|
||
|
} else if (hours) {
|
||
|
return hours + "小时" + minutes + "分钟" + seconds + "秒";
|
||
|
} else if (minutes) {
|
||
|
return minutes + "分钟" + seconds + "秒";
|
||
|
} else {
|
||
|
return seconds + "秒";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 转换时间格式
|
||
|
export function timeValidate(date, type) {
|
||
|
const time = date ? new Date(date) : new Date()
|
||
|
const yyyy = time.getFullYear()
|
||
|
const MM = (time.getMonth() + 1).toString().padStart(2, 0)
|
||
|
const dd = time.getDate().toString().padStart(2, '0')
|
||
|
const hh = time.getHours().toString().padStart(2, '0')
|
||
|
const mm = time.getMinutes().toString().padStart(2, '0')
|
||
|
const ss = time.getSeconds().toString().padStart(2, '0')
|
||
|
if (type == 'ymd') {
|
||
|
return `${yyyy}-${MM}-${dd}`;
|
||
|
}
|
||
|
if (type == 'md') {
|
||
|
return `${MM}.${dd}`
|
||
|
}
|
||
|
return `${yyyy}-${MM}-${dd} ${hh}:${mm}:${ss}`
|
||
|
}
|
||
|
|
||
|
|
||
|
// 获取当前近多少天 7后7天 -7 前五天
|
||
|
export function getRecentDay(n) {
|
||
|
var currentDate = new Date();
|
||
|
var preDate = new Date(currentDate.getTime() + n * 24 * 3600 * 1000)
|
||
|
let year = preDate.getFullYear()
|
||
|
let mon = preDate.getMonth() + 1
|
||
|
let day = preDate.getDate()
|
||
|
let s = year + '-' + (mon < 10 ? ('0' + mon) : mon) + '-' + (day < 10 ? ('0' + day) : day)
|
||
|
return s
|
||
|
}
|
||
|
|
||
|
// 获取n近7月 7后7 -7 前
|
||
|
export function getnRencebtMonth(n) {
|
||
|
let date = new Date();
|
||
|
date.setMonth(date.getMonth() - n)
|
||
|
date.toLocaleDateString()
|
||
|
let y = date.getFullYear()
|
||
|
let m = date.getMonth() + 1
|
||
|
m = m < 10 ? ('0' + m) : m + ''
|
||
|
return y + m
|
||
|
}
|
||
|
/**
|
||
|
* 数据去重 相同数据值累加
|
||
|
* @param {Object} array 数据
|
||
|
*/
|
||
|
export function setArray(array) {
|
||
|
let newArr = []
|
||
|
array.forEach(item => {
|
||
|
const res = newArr.findIndex(ol => {
|
||
|
//组织机构代码相同 并且报警类别相同
|
||
|
return item.ssbmdm == ol.ssbmdm && item.bjlb == ol.bjlb
|
||
|
})
|
||
|
if (res !== -1) {
|
||
|
newArr[res].sl = newArr[res].sl + item.sl
|
||
|
} else {
|
||
|
newArr.push(item)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return newArr
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 合并数据
|
||
|
* @param {Object} array 数据
|
||
|
*/
|
||
|
export function hbArray(array, item1, item2, item3) {
|
||
|
let newArr = []
|
||
|
array.forEach(item => {
|
||
|
const res = newArr.findIndex(ol => {
|
||
|
//组织机构代码相同 并且报警类别相同
|
||
|
return item.product == ol.product
|
||
|
})
|
||
|
if (res !== -1) {
|
||
|
newArr[res][item1] = newArr[res][item1] + item[item1]
|
||
|
newArr[res][item2] = newArr[res][item2] + item[item2]
|
||
|
newArr[res][item3] = newArr[res][item3] + item[item3]
|
||
|
} else {
|
||
|
newArr.push(item)
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return newArr
|
||
|
}
|
||
|
//时间格式
|
||
|
export function dateFormat(type, time) {
|
||
|
let date
|
||
|
if (time) {
|
||
|
date = new Date(time);
|
||
|
} else {
|
||
|
date = new Date();
|
||
|
}
|
||
|
let year = date.getFullYear();
|
||
|
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
|
||
|
let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
|
||
|
let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
|
||
|
let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
|
||
|
let day
|
||
|
|
||
|
if (type == 'z') {
|
||
|
//前一天日期
|
||
|
day = date.getDate() - 1;
|
||
|
day = day < 10 ? "0" + day : day;
|
||
|
return `${year}-${month}-${day}`;
|
||
|
} else if (type == 'all') {
|
||
|
//格式化日期时间
|
||
|
day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
||
|
day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
||
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||
|
} else {
|
||
|
//当天日期
|
||
|
day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
||
|
return `${year}-${month}-${day}`;
|
||
|
}
|
||
|
return day
|
||
|
}
|
||
|
//地址解析
|
||
|
// export function getAddressApi(coords, fun) {
|
||
|
// let {
|
||
|
// jd,
|
||
|
// wd
|
||
|
// } = coords
|
||
|
// getAddress({
|
||
|
// jd,
|
||
|
// wd
|
||
|
// }).then(res => {
|
||
|
// fun(res)
|
||
|
// })
|
||
|
// }
|
||
|
//数字超长处理
|
||
|
export function handleNum(num) {
|
||
|
var data = 0
|
||
|
if (num) {
|
||
|
try {
|
||
|
if (num * 1 > 100000) {
|
||
|
data = (num / 10000).toFixed(0) + '万'
|
||
|
} else {
|
||
|
data = (num * 1).toFixed(0)
|
||
|
}
|
||
|
} catch (error) {
|
||
|
data = 0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return data
|
||
|
}
|
||
|
/**
|
||
|
* 文件是否是图片
|
||
|
* @param {*} val
|
||
|
*/
|
||
|
export function IS_PNG(val) {
|
||
|
return ['bmp', 'jpg', 'png', 'tif', 'gif', 'pcx', 'tga', 'exif', 'fpx', 'svg', 'psd', 'cdr', 'pcd', 'dxf', 'ufo',
|
||
|
'eps', 'ai', 'raw', 'wmf', 'webp', 'avif', 'apng'
|
||
|
].indexOf(val.toLowerCase()) !== -1
|
||
|
}
|
||
|
/**
|
||
|
* 文件是否是音频
|
||
|
* @param {*} val
|
||
|
*/
|
||
|
export function IS_MP3(val) {
|
||
|
return ['mp3', 'wav', 'wma', 'mp2', 'flac', 'midi', 'ra', 'ape', 'aac', 'cda', 'mov'].indexOf(val.toLowerCase()) !==
|
||
|
-1
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 文件是否是视频
|
||
|
* @param {*} val
|
||
|
*/
|
||
|
export function IS_MP4(val) {
|
||
|
return ['avi', 'wmv', 'mpeg', 'mp4', 'm4v', 'mov', 'asf', 'fiv', 'f4v', 'mvb', 'rm', '3gp', 'vob'].indexOf(val
|
||
|
.toLowerCase()) !== -1
|
||
|
}
|
||
|
/**
|
||
|
* 获取用户所属区域数据
|
||
|
* @param {*} fun 回调方法
|
||
|
*/
|
||
|
// export function getUserAreaData(fun) {
|
||
|
// getUserArea().then(res => {
|
||
|
// if (res && res.jd && res.wd) {
|
||
|
// let centerCoord = [res.jd, res.wd]
|
||
|
// let leavel = res.level.slice(0, 1)
|
||
|
// let coorList = [...handelArr(res.dtm), ...handelArr(res.dtm1), ...handelArr(res.dtm2)]
|
||
|
// fun(coorList, centerCoord, leavel)
|
||
|
// }
|
||
|
// })
|
||
|
// }
|
||
|
|
||
|
function handelArr(arr) {
|
||
|
let brr = []
|
||
|
if (arr && arr.length > 0) {
|
||
|
let obj = {}
|
||
|
let coords = "";
|
||
|
for (let i = 0; i < arr.length; i++) {
|
||
|
coords += arr[i] + ","
|
||
|
}
|
||
|
obj.coords = coords
|
||
|
brr.push(obj)
|
||
|
}
|
||
|
return brr
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 时间 天数
|
||
|
* @param {*} val
|
||
|
*/
|
||
|
export function setEchartTime(val) {
|
||
|
let date = new Date();
|
||
|
let arrTime = [];
|
||
|
if (val == 0) {
|
||
|
for (let i = 0; i < 24; i++) {
|
||
|
arrTime.push(i)
|
||
|
}
|
||
|
} else {
|
||
|
for (let i = 0; i < val; i++) {
|
||
|
let date1 = new Date(date.getTime() - i * 24 * 60 * 60 * 1000)
|
||
|
arrTime.push(_setTime(date1))
|
||
|
}
|
||
|
arrTime.reverse()
|
||
|
}
|
||
|
return arrTime
|
||
|
}
|
||
|
//设置时间
|
||
|
function _setTime(date) {
|
||
|
let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
|
||
|
let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
|
||
|
return `${month}-${day}`;
|
||
|
}
|
||
|
|
||
|
|