|
@@ -12,31 +12,38 @@ function deepClone(obj) {
|
|
return JSON.parse(JSON.stringify(obj))
|
|
return JSON.parse(JSON.stringify(obj))
|
|
}
|
|
}
|
|
|
|
|
|
-/**
|
|
|
|
- * 日期格式化 new Date().format('yyyy-MM-dd hh:mm:ss')
|
|
|
|
- * @param fmt
|
|
|
|
- * @returns {*}
|
|
|
|
- */
|
|
|
|
-Date.prototype.format = function (fmt) {
|
|
|
|
- const o = {
|
|
|
|
- "M+": this.getMonth() + 1, //月份
|
|
|
|
- "d+": this.getDate(), //日
|
|
|
|
- "h+": this.getHours(), //小时
|
|
|
|
- "m+": this.getMinutes(), //分
|
|
|
|
- "s+": this.getSeconds(), //秒
|
|
|
|
- "q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
|
|
|
- "S": this.getMilliseconds() //毫秒
|
|
|
|
- };
|
|
|
|
- if (/(y+)/.test(fmt)) {
|
|
|
|
- fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
|
|
|
- }
|
|
|
|
- for (const k in o) {
|
|
|
|
- if (new RegExp("(" + k + ")").test(fmt)) {
|
|
|
|
- fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
|
|
|
|
|
+// 日期工具类
|
|
|
|
+const dataUtil = {
|
|
|
|
+ // 日期 -> 字符串:formatDate(date, 'yyyy-MM-dd hh:mm:ss');
|
|
|
|
+ formatDate: function (date, format) {
|
|
|
|
+ const pad = (n) => (n < 10 ? '0' + n : n);
|
|
|
|
+ const replacements = {
|
|
|
|
+ 'yyyy': date.getFullYear(),
|
|
|
|
+ 'MM': pad(date.getMonth() + 1),
|
|
|
|
+ 'dd': pad(date.getDate()),
|
|
|
|
+ 'hh': pad(date.getHours()),
|
|
|
|
+ 'mm': pad(date.getMinutes()),
|
|
|
|
+ 'ss': pad(date.getSeconds()),
|
|
|
|
+ 'qq': Math.floor((date.getMonth() + 3) / 3), //季度
|
|
|
|
+ 'SSS': pad(date.getMilliseconds(), 3) //毫秒
|
|
|
|
+ };
|
|
|
|
+ let result = format;
|
|
|
|
+ for (const key in replacements) {
|
|
|
|
+ result = result.replace(key, replacements[key]);
|
|
}
|
|
}
|
|
- }
|
|
|
|
- return fmt;
|
|
|
|
-};
|
|
|
|
|
|
+ return result;
|
|
|
|
+ },
|
|
|
|
+ // 日期字符串 -> 日期: parseDate("2022-10-30 16:13:49")
|
|
|
|
+ parseDate: function (dateString) {
|
|
|
|
+ const date = new Date(Date.parse(dateString));
|
|
|
|
+ return date;
|
|
|
|
+ },
|
|
|
|
+ // 当前日期
|
|
|
|
+ getNowStr: function () {
|
|
|
|
+ return this.formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss');
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
|
|
// 添加响应拦截器
|
|
// 添加响应拦截器
|
|
axios.interceptors.response.use(function (response) {
|
|
axios.interceptors.response.use(function (response) {
|
|
@@ -51,7 +58,7 @@ axios.interceptors.response.use(function (response) {
|
|
* 远程请求
|
|
* 远程请求
|
|
* @type {{async: (function(*, *, *, *): Promise<unknown>), xhr_send: request.xhr_send, sync: (function(*, *, *, *): any)}}
|
|
* @type {{async: (function(*, *, *, *): Promise<unknown>), xhr_send: request.xhr_send, sync: (function(*, *, *, *): any)}}
|
|
*/
|
|
*/
|
|
-const request = {
|
|
|
|
|
|
+const requestUtil = {
|
|
xhr_send: function (xhr, method, headers, data) {
|
|
xhr_send: function (xhr, method, headers, data) {
|
|
if (headers) {
|
|
if (headers) {
|
|
for (const key in headers) {
|
|
for (const key in headers) {
|
|
@@ -70,7 +77,7 @@ const request = {
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 异步请求:request.async('https://jsonplaceholder.typicode.com/posts/1', 'GET', null, null)
|
|
|
|
|
|
+ * 异步请求:requestUtil.async('https://jsonplaceholder.typicode.com/posts/1', 'GET', null, null)
|
|
* .then(data => console.log(data))
|
|
* .then(data => console.log(data))
|
|
* .catch(error => console.error(error));
|
|
* .catch(error => console.error(error));
|
|
*/
|
|
*/
|
|
@@ -180,7 +187,8 @@ function getQueryString(name) {
|
|
return getQueryStringByUrl(location.href, name);
|
|
return getQueryStringByUrl(location.href, name);
|
|
}
|
|
}
|
|
|
|
|
|
-const random = {
|
|
|
|
|
|
+// 随机数
|
|
|
|
+const randomUtil = {
|
|
/**
|
|
/**
|
|
* 获取随机数
|
|
* 获取随机数
|
|
* @param min
|
|
* @param min
|
|
@@ -339,18 +347,4 @@ const copyUtil = {
|
|
console.error('复制失败', err);
|
|
console.error('复制失败', err);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * 在指定dom里面 添加 a 超链接 addLink(".media-title", " 转到豆瓣", `https://search.douban.com/movie/subject_search`);
|
|
|
|
- * @param domSelector
|
|
|
|
- * @param link_str
|
|
|
|
- * @param linkUrl
|
|
|
|
- */
|
|
|
|
-function addLink(domSelector, link_str, linkUrl) {
|
|
|
|
- const eleScript = document.createElement("a");
|
|
|
|
- eleScript.innerHTML = link_str.replaceAll(" ", " ");
|
|
|
|
- eleScript.href = linkUrl;
|
|
|
|
- document.querySelector(domSelector).appendChild(eleScript);
|
|
|
|
-}
|
|
|
|
|
|
+}
|