|
@@ -1,84 +1,84 @@
|
|
|
-import CryptoJS from 'crypto-js'
|
|
|
|
|
-import CityLinkageJson from '@/components/ma-cityLinkage/lib/city.json'
|
|
|
|
|
|
|
+import CryptoJS from "crypto-js";
|
|
|
|
|
+import CityLinkageJson from "@/components/ma-cityLinkage/lib/city.json";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 根据类型获取颜色
|
|
* 根据类型获取颜色
|
|
|
*/
|
|
*/
|
|
|
-const typeColor = (type = 'default') => {
|
|
|
|
|
- let color = ''
|
|
|
|
|
|
|
+const typeColor = (type = "default") => {
|
|
|
|
|
+ let color = "";
|
|
|
switch (type) {
|
|
switch (type) {
|
|
|
- case 'default':
|
|
|
|
|
- color = '#35495E'
|
|
|
|
|
- break
|
|
|
|
|
- case 'primary':
|
|
|
|
|
- color = '#3488ff'
|
|
|
|
|
- break
|
|
|
|
|
- case 'success':
|
|
|
|
|
- color = '#43B883'
|
|
|
|
|
- break
|
|
|
|
|
- case 'warning':
|
|
|
|
|
- color = '#e6a23c'
|
|
|
|
|
- break
|
|
|
|
|
- case 'danger':
|
|
|
|
|
- color = '#f56c6c'
|
|
|
|
|
- break
|
|
|
|
|
|
|
+ case "default":
|
|
|
|
|
+ color = "#35495E";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "primary":
|
|
|
|
|
+ color = "#3488ff";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "success":
|
|
|
|
|
+ color = "#43B883";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "warning":
|
|
|
|
|
+ color = "#e6a23c";
|
|
|
|
|
+ break;
|
|
|
|
|
+ case "danger":
|
|
|
|
|
+ color = "#f56c6c";
|
|
|
|
|
+ break;
|
|
|
default:
|
|
default:
|
|
|
- break
|
|
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- return color
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return color;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
-const tool = {}
|
|
|
|
|
|
|
+const tool = {};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* LocalStorage
|
|
* LocalStorage
|
|
|
*/
|
|
*/
|
|
|
tool.local = {
|
|
tool.local = {
|
|
|
set(table, settings) {
|
|
set(table, settings) {
|
|
|
- let _set = JSON.stringify(settings)
|
|
|
|
|
- return localStorage.setItem(table, _set)
|
|
|
|
|
|
|
+ let _set = JSON.stringify(settings);
|
|
|
|
|
+ return localStorage.setItem(table, _set);
|
|
|
},
|
|
},
|
|
|
get(table) {
|
|
get(table) {
|
|
|
- let data = localStorage.getItem(table)
|
|
|
|
|
|
|
+ let data = localStorage.getItem(table);
|
|
|
try {
|
|
try {
|
|
|
- data = JSON.parse(data)
|
|
|
|
|
|
|
+ data = JSON.parse(data);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
- return null
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
- return data
|
|
|
|
|
|
|
+ return data;
|
|
|
},
|
|
},
|
|
|
remove(table) {
|
|
remove(table) {
|
|
|
- return localStorage.removeItem(table)
|
|
|
|
|
|
|
+ return localStorage.removeItem(table);
|
|
|
},
|
|
},
|
|
|
clear() {
|
|
clear() {
|
|
|
- return localStorage.clear()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return localStorage.clear();
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* SessionStorage
|
|
* SessionStorage
|
|
|
*/
|
|
*/
|
|
|
tool.session = {
|
|
tool.session = {
|
|
|
set(table, settings) {
|
|
set(table, settings) {
|
|
|
- let _set = JSON.stringify(settings)
|
|
|
|
|
- return sessionStorage.setItem(table, _set)
|
|
|
|
|
|
|
+ let _set = JSON.stringify(settings);
|
|
|
|
|
+ return sessionStorage.setItem(table, _set);
|
|
|
},
|
|
},
|
|
|
get(table) {
|
|
get(table) {
|
|
|
- let data = sessionStorage.getItem(table)
|
|
|
|
|
|
|
+ let data = sessionStorage.getItem(table);
|
|
|
try {
|
|
try {
|
|
|
- data = JSON.parse(data)
|
|
|
|
|
|
|
+ data = JSON.parse(data);
|
|
|
} catch (err) {
|
|
} catch (err) {
|
|
|
- return null
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
- return data
|
|
|
|
|
|
|
+ return data;
|
|
|
},
|
|
},
|
|
|
remove(table) {
|
|
remove(table) {
|
|
|
- return sessionStorage.removeItem(table)
|
|
|
|
|
|
|
+ return sessionStorage.removeItem(table);
|
|
|
},
|
|
},
|
|
|
clear() {
|
|
clear() {
|
|
|
- return sessionStorage.clear()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return sessionStorage.clear();
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* CookieStorage
|
|
* CookieStorage
|
|
@@ -91,38 +91,38 @@ tool.cookie = {
|
|
|
domain: null,
|
|
domain: null,
|
|
|
secure: false,
|
|
secure: false,
|
|
|
httpOnly: false,
|
|
httpOnly: false,
|
|
|
- ...config
|
|
|
|
|
- }
|
|
|
|
|
- var cookieStr = `${name}=${escape(value)}`
|
|
|
|
|
|
|
+ ...config,
|
|
|
|
|
+ };
|
|
|
|
|
+ var cookieStr = `${name}=${escape(value)}`;
|
|
|
if (cfg.expires) {
|
|
if (cfg.expires) {
|
|
|
- var exp = new Date()
|
|
|
|
|
- exp.setTime(exp.getTime() + parseInt(cfg.expires) * 1000)
|
|
|
|
|
- cookieStr += `;expires=${exp.toGMTString()}`
|
|
|
|
|
|
|
+ var exp = new Date();
|
|
|
|
|
+ exp.setTime(exp.getTime() + parseInt(cfg.expires) * 1000);
|
|
|
|
|
+ cookieStr += `;expires=${exp.toGMTString()}`;
|
|
|
}
|
|
}
|
|
|
if (cfg.path) {
|
|
if (cfg.path) {
|
|
|
- cookieStr += `;path=${cfg.path}`
|
|
|
|
|
|
|
+ cookieStr += `;path=${cfg.path}`;
|
|
|
}
|
|
}
|
|
|
if (cfg.domain) {
|
|
if (cfg.domain) {
|
|
|
- cookieStr += `;domain=${cfg.domain}`
|
|
|
|
|
|
|
+ cookieStr += `;domain=${cfg.domain}`;
|
|
|
}
|
|
}
|
|
|
- document.cookie = cookieStr
|
|
|
|
|
|
|
+ document.cookie = cookieStr;
|
|
|
},
|
|
},
|
|
|
get(name) {
|
|
get(name) {
|
|
|
var arr = document.cookie.match(
|
|
var arr = document.cookie.match(
|
|
|
- new RegExp('(^| )' + name + '=([^;]*)(;|$)')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ new RegExp("(^| )" + name + "=([^;]*)(;|$)")
|
|
|
|
|
+ );
|
|
|
if (arr != null) {
|
|
if (arr != null) {
|
|
|
- return unescape(arr[2])
|
|
|
|
|
|
|
+ return unescape(arr[2]);
|
|
|
} else {
|
|
} else {
|
|
|
- return null
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
remove(name) {
|
|
remove(name) {
|
|
|
- var exp = new Date()
|
|
|
|
|
- exp.setTime(exp.getTime() - 1)
|
|
|
|
|
- document.cookie = `${name}=;expires=${exp.toGMTString()}`
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ var exp = new Date();
|
|
|
|
|
+ exp.setTime(exp.getTime() - 1);
|
|
|
|
|
+ document.cookie = `${name}=;expires=${exp.toGMTString()}`;
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 全屏操作
|
|
* 全屏操作
|
|
@@ -133,62 +133,62 @@ tool.screen = (element) => {
|
|
|
document.mozFullScreen ||
|
|
document.mozFullScreen ||
|
|
|
document.msFullscreenElement ||
|
|
document.msFullscreenElement ||
|
|
|
document.fullscreenElement
|
|
document.fullscreenElement
|
|
|
- )
|
|
|
|
|
|
|
+ );
|
|
|
if (isFull) {
|
|
if (isFull) {
|
|
|
if (document.exitFullscreen) {
|
|
if (document.exitFullscreen) {
|
|
|
- document.exitFullscreen()
|
|
|
|
|
|
|
+ document.exitFullscreen();
|
|
|
} else if (document.msExitFullscreen) {
|
|
} else if (document.msExitFullscreen) {
|
|
|
- document.msExitFullscreen()
|
|
|
|
|
|
|
+ document.msExitFullscreen();
|
|
|
} else if (document.mozCancelFullScreen) {
|
|
} else if (document.mozCancelFullScreen) {
|
|
|
- document.mozCancelFullScreen()
|
|
|
|
|
|
|
+ document.mozCancelFullScreen();
|
|
|
} else if (document.webkitExitFullscreen) {
|
|
} else if (document.webkitExitFullscreen) {
|
|
|
- document.webkitExitFullscreen()
|
|
|
|
|
|
|
+ document.webkitExitFullscreen();
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (element.requestFullscreen) {
|
|
if (element.requestFullscreen) {
|
|
|
- element.requestFullscreen()
|
|
|
|
|
|
|
+ element.requestFullscreen();
|
|
|
} else if (element.msRequestFullscreen) {
|
|
} else if (element.msRequestFullscreen) {
|
|
|
- element.msRequestFullscreen()
|
|
|
|
|
|
|
+ element.msRequestFullscreen();
|
|
|
} else if (element.mozRequestFullScreen) {
|
|
} else if (element.mozRequestFullScreen) {
|
|
|
- element.mozRequestFullScreen()
|
|
|
|
|
|
|
+ element.mozRequestFullScreen();
|
|
|
} else if (element.webkitRequestFullscreen) {
|
|
} else if (element.webkitRequestFullscreen) {
|
|
|
- element.webkitRequestFullscreen()
|
|
|
|
|
|
|
+ element.webkitRequestFullscreen();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取设备信息
|
|
* 获取设备信息
|
|
|
*/
|
|
*/
|
|
|
tool.getDevice = function () {
|
|
tool.getDevice = function () {
|
|
|
const hasTouchScreen =
|
|
const hasTouchScreen =
|
|
|
- 'ontouchstart' in window || navigator.maxTouchPoints > 0
|
|
|
|
|
- const isSmallScreen = window.innerWidth < 768
|
|
|
|
|
|
|
+ "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
|
|
|
+ const isSmallScreen = window.innerWidth < 768;
|
|
|
|
|
|
|
|
if (hasTouchScreen && isSmallScreen) {
|
|
if (hasTouchScreen && isSmallScreen) {
|
|
|
- return 'mobile'
|
|
|
|
|
|
|
+ return "mobile";
|
|
|
} else {
|
|
} else {
|
|
|
- return 'desktop'
|
|
|
|
|
|
|
+ return "desktop";
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 处理图片
|
|
* 处理图片
|
|
|
*/
|
|
*/
|
|
|
tool.parseImage = (url) => {
|
|
tool.parseImage = (url) => {
|
|
|
if (url === undefined) {
|
|
if (url === undefined) {
|
|
|
- return import.meta.env.VITE_APP_BASE + 'not-image.png'
|
|
|
|
|
|
|
+ return import.meta.env.VITE_APP_BASE + "not-image.png";
|
|
|
}
|
|
}
|
|
|
- if (typeof url === 'string' && url !== null) {
|
|
|
|
|
- return url
|
|
|
|
|
|
|
+ if (typeof url === "string" && url !== null) {
|
|
|
|
|
+ return url;
|
|
|
} else {
|
|
} else {
|
|
|
if (url !== null) {
|
|
if (url !== null) {
|
|
|
- return url[0]
|
|
|
|
|
|
|
+ return url[0];
|
|
|
} else {
|
|
} else {
|
|
|
- return import.meta.env.VITE_APP_BASE + 'not-image.png'
|
|
|
|
|
|
|
+ return import.meta.env.VITE_APP_BASE + "not-image.png";
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 城市代码翻译成名称
|
|
* 城市代码翻译成名称
|
|
@@ -197,37 +197,37 @@ tool.cityToCode = function (
|
|
|
province,
|
|
province,
|
|
|
city = undefined,
|
|
city = undefined,
|
|
|
area = undefined,
|
|
area = undefined,
|
|
|
- split = ' / '
|
|
|
|
|
|
|
+ split = " / "
|
|
|
) {
|
|
) {
|
|
|
try {
|
|
try {
|
|
|
let provinceData = CityLinkageJson.filter(
|
|
let provinceData = CityLinkageJson.filter(
|
|
|
(item) => province == item.code
|
|
(item) => province == item.code
|
|
|
- )[0]
|
|
|
|
|
|
|
+ )[0];
|
|
|
if (!city) {
|
|
if (!city) {
|
|
|
- return provinceData.name
|
|
|
|
|
|
|
+ return provinceData.name;
|
|
|
}
|
|
}
|
|
|
- let cityData = provinceData.children.filter((item) => city == item.code)[0]
|
|
|
|
|
|
|
+ let cityData = provinceData.children.filter((item) => city == item.code)[0];
|
|
|
|
|
|
|
|
if (!area) {
|
|
if (!area) {
|
|
|
- return [provinceData.name, cityData.name].join(split)
|
|
|
|
|
|
|
+ return [provinceData.name, cityData.name].join(split);
|
|
|
}
|
|
}
|
|
|
- let areaData = cityData.children.filter((item) => area == item.code)[0]
|
|
|
|
|
|
|
+ let areaData = cityData.children.filter((item) => area == item.code)[0];
|
|
|
|
|
|
|
|
- return [provinceData.name, cityData.name, areaData.name].join(split)
|
|
|
|
|
|
|
+ return [provinceData.name, cityData.name, areaData.name].join(split);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- return ''
|
|
|
|
|
|
|
+ return "";
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 复制对象
|
|
* 复制对象
|
|
|
*/
|
|
*/
|
|
|
tool.objCopy = (obj) => {
|
|
tool.objCopy = (obj) => {
|
|
|
if (obj === undefined) {
|
|
if (obj === undefined) {
|
|
|
- return undefined
|
|
|
|
|
|
|
+ return undefined;
|
|
|
}
|
|
}
|
|
|
- return JSON.parse(JSON.stringify(obj))
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return JSON.parse(JSON.stringify(obj));
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生车随机id
|
|
* 生车随机id
|
|
@@ -235,80 +235,80 @@ tool.objCopy = (obj) => {
|
|
|
tool.generateId = function () {
|
|
tool.generateId = function () {
|
|
|
return Math.floor(
|
|
return Math.floor(
|
|
|
Math.random() * 100000 + Math.random() * 20000 + Math.random() * 5000
|
|
Math.random() * 100000 + Math.random() * 20000 + Math.random() * 5000
|
|
|
- )
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ );
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 日期格式化
|
|
* 日期格式化
|
|
|
*/
|
|
*/
|
|
|
-tool.dateFormat = (date, fmt = 'yyyy-MM-dd hh:mm:ss', isDefault = '-') => {
|
|
|
|
|
|
|
+tool.dateFormat = (date, fmt = "yyyy-MM-dd hh:mm:ss", isDefault = "-") => {
|
|
|
if (date.toString().length == 10) {
|
|
if (date.toString().length == 10) {
|
|
|
- date = date * 1000
|
|
|
|
|
|
|
+ date = date * 1000;
|
|
|
}
|
|
}
|
|
|
- date = new Date(date)
|
|
|
|
|
|
|
+ date = new Date(date);
|
|
|
|
|
|
|
|
if (date.valueOf() < 1) {
|
|
if (date.valueOf() < 1) {
|
|
|
- return isDefault
|
|
|
|
|
|
|
+ return isDefault;
|
|
|
}
|
|
}
|
|
|
let o = {
|
|
let o = {
|
|
|
- 'M+': date.getMonth() + 1, //月份
|
|
|
|
|
- 'd+': date.getDate(), //日
|
|
|
|
|
- 'h+': date.getHours(), //小时
|
|
|
|
|
- 'm+': date.getMinutes(), //分
|
|
|
|
|
- 's+': date.getSeconds(), //秒
|
|
|
|
|
- 'q+': Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
|
- S: date.getMilliseconds() //毫秒
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ "M+": date.getMonth() + 1, //月份
|
|
|
|
|
+ "d+": date.getDate(), //日
|
|
|
|
|
+ "h+": date.getHours(), //小时
|
|
|
|
|
+ "m+": date.getMinutes(), //分
|
|
|
|
|
+ "s+": date.getSeconds(), //秒
|
|
|
|
|
+ "q+": Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
|
+ S: date.getMilliseconds(), //毫秒
|
|
|
|
|
+ };
|
|
|
if (/(y+)/.test(fmt)) {
|
|
if (/(y+)/.test(fmt)) {
|
|
|
fmt = fmt.replace(
|
|
fmt = fmt.replace(
|
|
|
RegExp.$1,
|
|
RegExp.$1,
|
|
|
- (date.getFullYear() + '').substr(4 - RegExp.$1.length)
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ (date.getFullYear() + "").substr(4 - RegExp.$1.length)
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
for (let k in o) {
|
|
for (let k in o) {
|
|
|
- if (new RegExp('(' + k + ')').test(fmt)) {
|
|
|
|
|
|
|
+ if (new RegExp("(" + k + ")").test(fmt)) {
|
|
|
fmt = fmt.replace(
|
|
fmt = fmt.replace(
|
|
|
RegExp.$1,
|
|
RegExp.$1,
|
|
|
- RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return fmt
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return fmt;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 千分符
|
|
* 千分符
|
|
|
*/
|
|
*/
|
|
|
tool.groupSeparator = (num) => {
|
|
tool.groupSeparator = (num) => {
|
|
|
- num = num + ''
|
|
|
|
|
- if (!num.includes('.')) {
|
|
|
|
|
- num += '.'
|
|
|
|
|
|
|
+ num = num + "";
|
|
|
|
|
+ if (!num.includes(".")) {
|
|
|
|
|
+ num += ".";
|
|
|
}
|
|
}
|
|
|
return num
|
|
return num
|
|
|
.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
|
|
.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
|
|
|
- return $1 + ','
|
|
|
|
|
|
|
+ return $1 + ",";
|
|
|
})
|
|
})
|
|
|
- .replace(/\.$/, '')
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ .replace(/\.$/, "");
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* md5加密
|
|
* md5加密
|
|
|
*/
|
|
*/
|
|
|
tool.md5 = (str) => {
|
|
tool.md5 = (str) => {
|
|
|
- return CryptoJS.MD5(str).toString()
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return CryptoJS.MD5(str).toString();
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Base64加密解密
|
|
* Base64加密解密
|
|
|
*/
|
|
*/
|
|
|
tool.base64 = {
|
|
tool.base64 = {
|
|
|
encode(data) {
|
|
encode(data) {
|
|
|
- return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
|
|
|
|
|
|
|
+ return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data));
|
|
|
},
|
|
},
|
|
|
decode(cipher) {
|
|
decode(cipher) {
|
|
|
- return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8);
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* AES加密解密
|
|
* AES加密解密
|
|
@@ -320,10 +320,10 @@ tool.aes = {
|
|
|
CryptoJS.enc.Utf8.parse(secretKey),
|
|
CryptoJS.enc.Utf8.parse(secretKey),
|
|
|
{
|
|
{
|
|
|
mode: CryptoJS.mode.ECB,
|
|
mode: CryptoJS.mode.ECB,
|
|
|
- padding: CryptoJS.pad.Pkcs7
|
|
|
|
|
|
|
+ padding: CryptoJS.pad.Pkcs7,
|
|
|
}
|
|
}
|
|
|
- )
|
|
|
|
|
- return result.toString()
|
|
|
|
|
|
|
+ );
|
|
|
|
|
+ return result.toString();
|
|
|
},
|
|
},
|
|
|
decode(cipher, secretKey) {
|
|
decode(cipher, secretKey) {
|
|
|
const result = CryptoJS.AES.decrypt(
|
|
const result = CryptoJS.AES.decrypt(
|
|
@@ -331,72 +331,72 @@ tool.aes = {
|
|
|
CryptoJS.enc.Utf8.parse(secretKey),
|
|
CryptoJS.enc.Utf8.parse(secretKey),
|
|
|
{
|
|
{
|
|
|
mode: CryptoJS.mode.ECB,
|
|
mode: CryptoJS.mode.ECB,
|
|
|
- padding: CryptoJS.pad.Pkcs7
|
|
|
|
|
|
|
+ padding: CryptoJS.pad.Pkcs7,
|
|
|
}
|
|
}
|
|
|
- )
|
|
|
|
|
- return CryptoJS.enc.Utf8.stringify(result)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ );
|
|
|
|
|
+ return CryptoJS.enc.Utf8.stringify(result);
|
|
|
|
|
+ },
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 打印信息
|
|
* 打印信息
|
|
|
*/
|
|
*/
|
|
|
-tool.capsule = (title, info, type = 'primary') => {
|
|
|
|
|
|
|
+tool.capsule = (title, info, type = "primary") => {
|
|
|
console.log(
|
|
console.log(
|
|
|
`%c ${title} %c ${info} %c`,
|
|
`%c ${title} %c ${info} %c`,
|
|
|
- 'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;',
|
|
|
|
|
|
|
+ "background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;",
|
|
|
`background:${typeColor(
|
|
`background:${typeColor(
|
|
|
type
|
|
type
|
|
|
)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
|
|
)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
|
|
|
- 'background:transparent'
|
|
|
|
|
- )
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ "background:transparent"
|
|
|
|
|
+ );
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 文件大小单位处理
|
|
* 文件大小单位处理
|
|
|
*/
|
|
*/
|
|
|
tool.formatSize = (size) => {
|
|
tool.formatSize = (size) => {
|
|
|
- if (typeof size == 'undefined') {
|
|
|
|
|
- return '0'
|
|
|
|
|
|
|
+ if (typeof size == "undefined") {
|
|
|
|
|
+ return "0";
|
|
|
}
|
|
}
|
|
|
- let units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
|
|
|
|
|
- let index = 0
|
|
|
|
|
|
|
+ let units = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
|
|
|
+ let index = 0;
|
|
|
for (let i = 0; size >= 1024 && i < 5; i++) {
|
|
for (let i = 0; size >= 1024 && i < 5; i++) {
|
|
|
- size /= 1024
|
|
|
|
|
- index = i
|
|
|
|
|
|
|
+ size /= 1024;
|
|
|
|
|
+ index = i;
|
|
|
}
|
|
}
|
|
|
- return Math.round(size, 2) + units[index]
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return Math.round(size, 2) + units[index];
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 下载资源
|
|
* 下载资源
|
|
|
*/
|
|
*/
|
|
|
-tool.download = (res, downName = '') => {
|
|
|
|
|
- const aLink = document.createElement('a')
|
|
|
|
|
- let fileName = downName
|
|
|
|
|
- let blob = res //第三方请求返回blob对象
|
|
|
|
|
|
|
+tool.download = (res, downName = "") => {
|
|
|
|
|
+ const aLink = document.createElement("a");
|
|
|
|
|
+ let fileName = downName;
|
|
|
|
|
+ let blob = res; //第三方请求返回blob对象
|
|
|
|
|
|
|
|
//通过后端接口返回
|
|
//通过后端接口返回
|
|
|
if (res.headers && res.data) {
|
|
if (res.headers && res.data) {
|
|
|
blob = new Blob([res.data], {
|
|
blob = new Blob([res.data], {
|
|
|
- type: res.headers['content-type'].replace(';charset=utf8', '')
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ type: res.headers["content-type"].replace(";charset=utf8", ""),
|
|
|
|
|
+ });
|
|
|
if (!downName) {
|
|
if (!downName) {
|
|
|
- const contentDisposition = decodeURI(res.headers['content-disposition'])
|
|
|
|
|
- const result = contentDisposition.match(/filename=\"(.+)/gi)
|
|
|
|
|
- fileName = result[0].replace(/filename=\"/gi, '')
|
|
|
|
|
- fileName = fileName.replace('"', '')
|
|
|
|
|
|
|
+ const contentDisposition = decodeURI(res.headers["content-disposition"]);
|
|
|
|
|
+ const result = contentDisposition.match(/filename=\"(.+)/gi);
|
|
|
|
|
+ fileName = result[0].replace(/filename=\"/gi, "");
|
|
|
|
|
+ fileName = fileName.replace('"', "");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- aLink.href = URL.createObjectURL(blob)
|
|
|
|
|
|
|
+ aLink.href = URL.createObjectURL(blob);
|
|
|
// 设置下载文件名称
|
|
// 设置下载文件名称
|
|
|
- aLink.setAttribute('download', fileName)
|
|
|
|
|
- document.body.appendChild(aLink)
|
|
|
|
|
- aLink.click()
|
|
|
|
|
- document.body.removeChild(aLink)
|
|
|
|
|
- URL.revokeObjectURL(aLink.href)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ aLink.setAttribute("download", fileName);
|
|
|
|
|
+ document.body.appendChild(aLink);
|
|
|
|
|
+ aLink.click();
|
|
|
|
|
+ document.body.removeChild(aLink);
|
|
|
|
|
+ URL.revokeObjectURL(aLink.href);
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 对象转url参数
|
|
* 对象转url参数
|
|
@@ -404,97 +404,125 @@ tool.download = (res, downName = '') => {
|
|
|
* @param {*} isPrefix
|
|
* @param {*} isPrefix
|
|
|
*/
|
|
*/
|
|
|
tool.httpBuild = (data, isPrefix = false) => {
|
|
tool.httpBuild = (data, isPrefix = false) => {
|
|
|
- let prefix = isPrefix ? '?' : ''
|
|
|
|
|
- let _result = []
|
|
|
|
|
|
|
+ let prefix = isPrefix ? "?" : "";
|
|
|
|
|
+ let _result = [];
|
|
|
for (let key in data) {
|
|
for (let key in data) {
|
|
|
- let value = data[key]
|
|
|
|
|
|
|
+ let value = data[key];
|
|
|
// 去掉为空的参数
|
|
// 去掉为空的参数
|
|
|
- if (['', undefined, null].includes(value)) {
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ if (["", undefined, null].includes(value)) {
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
if (value.constructor === Array) {
|
|
if (value.constructor === Array) {
|
|
|
value.forEach((_value) => {
|
|
value.forEach((_value) => {
|
|
|
_result.push(
|
|
_result.push(
|
|
|
- encodeURIComponent(key) + '[]=' + encodeURIComponent(_value)
|
|
|
|
|
- )
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ encodeURIComponent(key) + "[]=" + encodeURIComponent(_value)
|
|
|
|
|
+ );
|
|
|
|
|
+ });
|
|
|
} else {
|
|
} else {
|
|
|
- _result.push(encodeURIComponent(key) + '=' + encodeURIComponent(value))
|
|
|
|
|
|
|
+ _result.push(encodeURIComponent(key) + "=" + encodeURIComponent(value));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return _result.length ? prefix + _result.join('&') : ''
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return _result.length ? prefix + _result.join("&") : "";
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取URL请求参数
|
|
* 获取URL请求参数
|
|
|
*/
|
|
*/
|
|
|
tool.getRequestParams = (url) => {
|
|
tool.getRequestParams = (url) => {
|
|
|
- const theRequest = new Object()
|
|
|
|
|
- if (url.indexOf('?') != -1) {
|
|
|
|
|
- const params = url.split('?')[1].split('&')
|
|
|
|
|
|
|
+ const theRequest = new Object();
|
|
|
|
|
+ if (url.indexOf("?") != -1) {
|
|
|
|
|
+ const params = url.split("?")[1].split("&");
|
|
|
for (let i = 0; i < params.length; i++) {
|
|
for (let i = 0; i < params.length; i++) {
|
|
|
- const param = params[i].split('=')
|
|
|
|
|
- theRequest[param[0]] = decodeURIComponent(param[1])
|
|
|
|
|
|
|
+ const param = params[i].split("=");
|
|
|
|
|
+ theRequest[param[0]] = decodeURIComponent(param[1]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return theRequest
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return theRequest;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
tool.attachUrl = (path) => {
|
|
tool.attachUrl = (path) => {
|
|
|
// 非完整url地址在此处理
|
|
// 非完整url地址在此处理
|
|
|
- return path
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return path;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
tool.viewImage = (path) => {
|
|
tool.viewImage = (path) => {
|
|
|
// 非完整url地址在此处理
|
|
// 非完整url地址在此处理
|
|
|
- return path
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return path;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
tool.showFile = (path) => {
|
|
tool.showFile = (path) => {
|
|
|
// 非完整url地址在此处理
|
|
// 非完整url地址在此处理
|
|
|
- return path
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return path;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取token
|
|
* 获取token
|
|
|
*/
|
|
*/
|
|
|
tool.getToken = () => {
|
|
tool.getToken = () => {
|
|
|
- return tool.local.get(import.meta.env.VITE_APP_TOKEN_PREFIX)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return tool.local.get(import.meta.env.VITE_APP_TOKEN_PREFIX);
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 转Unix时间戳
|
|
* 转Unix时间戳
|
|
|
*/
|
|
*/
|
|
|
tool.toUnixTime = (date) => {
|
|
tool.toUnixTime = (date) => {
|
|
|
- return Math.floor(new Date(date).getTime() / 1000)
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ return Math.floor(new Date(date).getTime() / 1000);
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通过value获取颜色
|
|
* 通过value获取颜色
|
|
|
*/
|
|
*/
|
|
|
tool.getColor = (value, data, colors = []) => {
|
|
tool.getColor = (value, data, colors = []) => {
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
- return ''
|
|
|
|
|
|
|
+ return "";
|
|
|
}
|
|
}
|
|
|
if (colors && colors.length > 0) {
|
|
if (colors && colors.length > 0) {
|
|
|
- const index = data.findIndex((item) => item.value == value)
|
|
|
|
|
- return colors[index] ?? ''
|
|
|
|
|
|
|
+ const index = data.findIndex((item) => item.value == value);
|
|
|
|
|
+ return colors[index] ?? "";
|
|
|
} else {
|
|
} else {
|
|
|
- const item = data.find((item) => item.value == value)
|
|
|
|
|
- return item?.color ?? ''
|
|
|
|
|
|
|
+ const item = data.find((item) => item.value == value);
|
|
|
|
|
+ return item?.color ?? "";
|
|
|
}
|
|
}
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通过value获取label
|
|
* 通过value获取label
|
|
|
*/
|
|
*/
|
|
|
tool.getLabel = (value, data) => {
|
|
tool.getLabel = (value, data) => {
|
|
|
if (!data) {
|
|
if (!data) {
|
|
|
- return ''
|
|
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ const item = data.find((item) => item.value == value);
|
|
|
|
|
+ return item?.label ?? "";
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 复制文本到剪贴板
|
|
|
|
|
+ */
|
|
|
|
|
+tool.copy = (text) => {
|
|
|
|
|
+ if (navigator.clipboard && window.isSecureContext) {
|
|
|
|
|
+ // 现代浏览器支持 navigator.clipboard API
|
|
|
|
|
+ return navigator.clipboard.writeText(text);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 兼容旧浏览器
|
|
|
|
|
+ const textArea = document.createElement("textarea");
|
|
|
|
|
+ textArea.value = text;
|
|
|
|
|
+ textArea.style.position = "fixed";
|
|
|
|
|
+ textArea.style.left = "-999999px";
|
|
|
|
|
+ textArea.style.top = "-999999px";
|
|
|
|
|
+ document.body.appendChild(textArea);
|
|
|
|
|
+ textArea.focus();
|
|
|
|
|
+ textArea.select();
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ if (document.execCommand("copy")) {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reject();
|
|
|
|
|
+ }
|
|
|
|
|
+ document.body.removeChild(textArea);
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
- const item = data.find((item) => item.value == value)
|
|
|
|
|
- return item?.label ?? ''
|
|
|
|
|
-}
|
|
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
-export default tool
|
|
|
|
|
|
|
+export default tool;
|