|
@@ -4,7 +4,7 @@ const deepmerge = require("deepmerge");
|
|
* 判断对象类型
|
|
* 判断对象类型
|
|
* @param {*} obj 对象
|
|
* @param {*} obj 对象
|
|
*/
|
|
*/
|
|
-function objTypeOf(obj) {
|
|
|
|
|
|
+export function objTypeOf(obj) {
|
|
const toString = Object.prototype.toString;
|
|
const toString = Object.prototype.toString;
|
|
const map = {
|
|
const map = {
|
|
"[object Boolean]": "boolean",
|
|
"[object Boolean]": "boolean",
|
|
@@ -25,7 +25,7 @@ function objTypeOf(obj) {
|
|
* 深拷贝
|
|
* 深拷贝
|
|
* @param {Object/Array} data 需要拷贝的数据
|
|
* @param {Object/Array} data 需要拷贝的数据
|
|
*/
|
|
*/
|
|
-function deepCopy(data, options) {
|
|
|
|
|
|
+export function deepCopy(data, options) {
|
|
const defObj = objTypeOf(data) === "array" ? [] : {};
|
|
const defObj = objTypeOf(data) === "array" ? [] : {};
|
|
return deepmerge(defObj, data, options || {});
|
|
return deepmerge(defObj, data, options || {});
|
|
}
|
|
}
|
|
@@ -35,7 +35,7 @@ function deepCopy(data, options) {
|
|
* @param {Object} target 目标对象
|
|
* @param {Object} target 目标对象
|
|
* @param {Object} sources 源对象
|
|
* @param {Object} sources 源对象
|
|
*/
|
|
*/
|
|
-function objAssign(target, sources) {
|
|
|
|
|
|
+export function objAssign(target, sources) {
|
|
let targ = { ...target };
|
|
let targ = { ...target };
|
|
for (let k in targ) {
|
|
for (let k in targ) {
|
|
targ[k] = sources.hasOwnProperty(k) ? sources[k] : targ[k];
|
|
targ[k] = sources.hasOwnProperty(k) ? sources[k] : targ[k];
|
|
@@ -47,7 +47,7 @@ function objAssign(target, sources) {
|
|
* 文件流下载
|
|
* 文件流下载
|
|
* @param {Object} option 文件下载设置
|
|
* @param {Object} option 文件下载设置
|
|
*/
|
|
*/
|
|
-function download(option) {
|
|
|
|
|
|
+export function download(option) {
|
|
let defOpt = {
|
|
let defOpt = {
|
|
type: "get",
|
|
type: "get",
|
|
url: "",
|
|
url: "",
|
|
@@ -113,7 +113,7 @@ function download(option) {
|
|
* @param {Function} fetchFunc 下载程序,返回promise
|
|
* @param {Function} fetchFunc 下载程序,返回promise
|
|
* @param {String} fileName 保存的文件名
|
|
* @param {String} fileName 保存的文件名
|
|
*/
|
|
*/
|
|
-async function downloadBlob(fetchFunc, fileName) {
|
|
|
|
|
|
+export async function downloadBlob(fetchFunc, fileName) {
|
|
const res = await fetchFunc().catch(() => {});
|
|
const res = await fetchFunc().catch(() => {});
|
|
if (!res) return;
|
|
if (!res) return;
|
|
|
|
|
|
@@ -133,7 +133,7 @@ async function downloadBlob(fetchFunc, fileName) {
|
|
* @param {Function} h createElement
|
|
* @param {Function} h createElement
|
|
* @param {Array} actions 操作分类数组
|
|
* @param {Array} actions 操作分类数组
|
|
*/
|
|
*/
|
|
-function tableAction(h, actions) {
|
|
|
|
|
|
+export function tableAction(h, actions) {
|
|
return actions.map(item => {
|
|
return actions.map(item => {
|
|
let attr = {
|
|
let attr = {
|
|
props: {
|
|
props: {
|
|
@@ -159,7 +159,7 @@ function tableAction(h, actions) {
|
|
* @param {Number} len 推荐8的倍数
|
|
* @param {Number} len 推荐8的倍数
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
-function randomCode(len = 16) {
|
|
|
|
|
|
+export function randomCode(len = 16) {
|
|
if (len <= 0) return;
|
|
if (len <= 0) return;
|
|
let steps = Math.ceil(len / 8);
|
|
let steps = Math.ceil(len / 8);
|
|
let stepNums = [];
|
|
let stepNums = [];
|
|
@@ -177,7 +177,7 @@ function randomCode(len = 16) {
|
|
* 序列化参数
|
|
* 序列化参数
|
|
* @param {Object} params 参数对象
|
|
* @param {Object} params 参数对象
|
|
*/
|
|
*/
|
|
-function qsParams(params) {
|
|
|
|
|
|
+export function qsParams(params) {
|
|
return Object.entries(params)
|
|
return Object.entries(params)
|
|
.map(el => `${el[0]}=${el[1]}`)
|
|
.map(el => `${el[0]}=${el[1]}`)
|
|
.join("&");
|
|
.join("&");
|
|
@@ -188,7 +188,7 @@ function qsParams(params) {
|
|
* @param {String} format 时间格式
|
|
* @param {String} format 时间格式
|
|
* @param {Date} date 需要格式化的时间对象
|
|
* @param {Date} date 需要格式化的时间对象
|
|
*/
|
|
*/
|
|
-function formatDate(format = "YYYY/MM/DD HH:mm:ss", date = new Date()) {
|
|
|
|
|
|
+export function formatDate(format = "YYYY/MM/DD HH:mm:ss", date = new Date()) {
|
|
if (objTypeOf(date) !== "date") return;
|
|
if (objTypeOf(date) !== "date") return;
|
|
const options = {
|
|
const options = {
|
|
"Y+": date.getFullYear(),
|
|
"Y+": date.getFullYear(),
|
|
@@ -208,10 +208,102 @@ function formatDate(format = "YYYY/MM/DD HH:mm:ss", date = new Date()) {
|
|
return format;
|
|
return format;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * 获取时间长度文字
|
|
|
|
+ * @param {Number} timeNumber 时间数值,单位:毫秒
|
|
|
|
+ */
|
|
|
|
+export function timeNumberToText(timeNumber) {
|
|
|
|
+ const DAY_TIME = 24 * 60 * 60 * 1000;
|
|
|
|
+ const HOUR_TIME = 60 * 60 * 1000;
|
|
|
|
+ const MINUTE_TIME = 60 * 1000;
|
|
|
|
+ const SECOND_TIME = 1000;
|
|
|
|
+ let [day, hour, minute, second] = [0, 0, 0, 0];
|
|
|
|
+ let residueTime = timeNumber;
|
|
|
|
+
|
|
|
|
+ if (residueTime >= DAY_TIME) {
|
|
|
|
+ day = Math.floor(residueTime / DAY_TIME);
|
|
|
|
+ residueTime -= day * DAY_TIME;
|
|
|
|
+ day += "天";
|
|
|
|
+ }
|
|
|
|
+ if (residueTime >= HOUR_TIME) {
|
|
|
|
+ hour = Math.floor(residueTime / HOUR_TIME);
|
|
|
|
+ residueTime -= hour * HOUR_TIME;
|
|
|
|
+ hour += "小时";
|
|
|
|
+ }
|
|
|
|
+ if (residueTime >= MINUTE_TIME) {
|
|
|
|
+ minute = Math.floor(residueTime / MINUTE_TIME);
|
|
|
|
+ residueTime -= minute * MINUTE_TIME;
|
|
|
|
+ minute += "分钟";
|
|
|
|
+ }
|
|
|
|
+ if (residueTime >= SECOND_TIME) {
|
|
|
|
+ second = Math.round(residueTime / SECOND_TIME);
|
|
|
|
+ second += "秒";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [day, hour, minute, second].filter(item => !!item).join("");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 警告时间
|
|
|
|
+ * @param {Number} timeNumber 时间数值,单位:毫秒
|
|
|
|
+ * @param {Number} wainingTime 最大剩余警告时间数值,单位:毫秒
|
|
|
|
+ */
|
|
|
|
+export function residueFloorTime(timeNumber, wainingTime = 0) {
|
|
|
|
+ if (timeNumber < 0) {
|
|
|
|
+ return { status: "danger", title: "已过期" };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const DAY_TIME = 24 * 60 * 60 * 1000;
|
|
|
|
+ const HOUR_TIME = 60 * 60 * 1000;
|
|
|
|
+ const MINUTE_TIME = 60 * 1000;
|
|
|
|
+ const status = timeNumber < wainingTime ? "warning" : "primary";
|
|
|
|
+ let [day, hour, minute] = [0, 0, 0];
|
|
|
|
+ let residueTime = timeNumber;
|
|
|
|
+
|
|
|
|
+ if (residueTime >= DAY_TIME) {
|
|
|
|
+ day = Math.floor(residueTime / DAY_TIME);
|
|
|
|
+ residueTime -= day * DAY_TIME;
|
|
|
|
+ return {
|
|
|
|
+ status,
|
|
|
|
+ title: `剩余${day}天`
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ if (residueTime >= HOUR_TIME) {
|
|
|
|
+ hour = Math.floor(residueTime / HOUR_TIME);
|
|
|
|
+ residueTime -= hour * HOUR_TIME;
|
|
|
|
+ return {
|
|
|
|
+ status,
|
|
|
|
+ title: `剩余${hour}小时`
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ if (residueTime >= MINUTE_TIME) {
|
|
|
|
+ minute = Math.floor(residueTime / MINUTE_TIME);
|
|
|
|
+ return {
|
|
|
|
+ status,
|
|
|
|
+ title: `剩余${minute}分钟`
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ status,
|
|
|
|
+ title: `不足1分钟`
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export function parseTimeRangeDateAndTime(startTime, endTime) {
|
|
|
|
+ const st = formatDate("YYYY-MM-DD HH:mm", new Date(startTime)).split(" ");
|
|
|
|
+ const et = formatDate("YYYY-MM-DD HH:mm", new Date(endTime)).split(" ");
|
|
|
|
+
|
|
|
|
+ return {
|
|
|
|
+ date: st[0],
|
|
|
|
+ time: `${st[1]}-${et[1]}`
|
|
|
|
+ };
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 获取本地时间,格式:年月日时分秒
|
|
* 获取本地时间,格式:年月日时分秒
|
|
*/
|
|
*/
|
|
-function localNowDateTime() {
|
|
|
|
|
|
+export function localNowDateTime() {
|
|
return formatDate("YYYY年MM月DD日HH时mm分ss秒");
|
|
return formatDate("YYYY年MM月DD日HH时mm分ss秒");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -219,7 +311,7 @@ function localNowDateTime() {
|
|
* 获取指定元素个数的数组
|
|
* 获取指定元素个数的数组
|
|
* @param {Number} num
|
|
* @param {Number} num
|
|
*/
|
|
*/
|
|
-function getNumList(num) {
|
|
|
|
|
|
+export function getNumList(num) {
|
|
return "#".repeat(num).split("");
|
|
return "#".repeat(num).split("");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -227,7 +319,7 @@ function getNumList(num) {
|
|
* 清除html标签
|
|
* 清除html标签
|
|
* @param {String} str html字符串
|
|
* @param {String} str html字符串
|
|
*/
|
|
*/
|
|
-function removeHtmlTag(str) {
|
|
|
|
|
|
+export function removeHtmlTag(str) {
|
|
return str.replace(/<[^>]+>/g, "");
|
|
return str.replace(/<[^>]+>/g, "");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -235,13 +327,13 @@ function removeHtmlTag(str) {
|
|
* 计算总数
|
|
* 计算总数
|
|
* @param {Array} dataList 需要统计的数组
|
|
* @param {Array} dataList 需要统计的数组
|
|
*/
|
|
*/
|
|
-function calcSum(dataList) {
|
|
|
|
|
|
+export function calcSum(dataList) {
|
|
return dataList.reduce(function(total, item) {
|
|
return dataList.reduce(function(total, item) {
|
|
return total + item;
|
|
return total + item;
|
|
}, 0);
|
|
}, 0);
|
|
}
|
|
}
|
|
|
|
|
|
-function isEmptyObject(obj) {
|
|
|
|
|
|
+export function isEmptyObject(obj) {
|
|
return !Object.keys(obj).length;
|
|
return !Object.keys(obj).length;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -249,7 +341,7 @@ function isEmptyObject(obj) {
|
|
* 解决后台返回的数据中number位数超过16位的情况
|
|
* 解决后台返回的数据中number位数超过16位的情况
|
|
* @param {String} text json格式字符串
|
|
* @param {String} text json格式字符串
|
|
*/
|
|
*/
|
|
-function jsonBigNumberToString(text) {
|
|
|
|
|
|
+export function jsonBigNumberToString(text) {
|
|
return text
|
|
return text
|
|
.replace(/\\":[0-9]{16,19}/g, function(match) {
|
|
.replace(/\\":[0-9]{16,19}/g, function(match) {
|
|
return match.slice(0, 3) + '\\"' + match.slice(3) + '\\"';
|
|
return match.slice(0, 3) + '\\"' + match.slice(3) + '\\"';
|
|
@@ -259,14 +351,14 @@ function jsonBigNumberToString(text) {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-function humpToLowLine(a) {
|
|
|
|
|
|
+export function humpToLowLine(a) {
|
|
return a
|
|
return a
|
|
.replace(/([A-Z])/g, "-$1")
|
|
.replace(/([A-Z])/g, "-$1")
|
|
.toLowerCase()
|
|
.toLowerCase()
|
|
.slice(1);
|
|
.slice(1);
|
|
}
|
|
}
|
|
|
|
|
|
-function pickByNotNull(params) {
|
|
|
|
|
|
+export function pickByNotNull(params) {
|
|
let nData = {};
|
|
let nData = {};
|
|
Object.entries(params).forEach(([key, val]) => {
|
|
Object.entries(params).forEach(([key, val]) => {
|
|
if (val === null || val === "null" || val === "") return;
|
|
if (val === null || val === "null" || val === "") return;
|
|
@@ -274,23 +366,3 @@ function pickByNotNull(params) {
|
|
});
|
|
});
|
|
return nData;
|
|
return nData;
|
|
}
|
|
}
|
|
-
|
|
|
|
-export {
|
|
|
|
- objTypeOf,
|
|
|
|
- deepCopy,
|
|
|
|
- objAssign,
|
|
|
|
- download,
|
|
|
|
- downloadBlob,
|
|
|
|
- tableAction,
|
|
|
|
- randomCode,
|
|
|
|
- qsParams,
|
|
|
|
- formatDate,
|
|
|
|
- localNowDateTime,
|
|
|
|
- getNumList,
|
|
|
|
- removeHtmlTag,
|
|
|
|
- calcSum,
|
|
|
|
- isEmptyObject,
|
|
|
|
- jsonBigNumberToString,
|
|
|
|
- humpToLowLine,
|
|
|
|
- pickByNotNull
|
|
|
|
-};
|
|
|