|
|
|
|
@ -18,10 +18,8 @@ export function wildcardCompare(str: string, pattern: string): boolean {
|
|
|
|
|
return regexPattern.test(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 日期格式化
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* 日期格式化
|
|
|
|
|
* @param {*} time 时间(Date对象、时间戳、时间字符串)
|
|
|
|
|
* @param {*} pattern 格式模板 默认'{y}-{m}-{d} {h}:{i}:{s}' y:年 m:月 d:日 h:时 i:分 s:秒 a:星期
|
|
|
|
|
* @returns 按照模板格式的时间字符串
|
|
|
|
|
@ -57,11 +55,11 @@ export function parseTime(time: string | Date | number, pattern: string) {
|
|
|
|
|
}
|
|
|
|
|
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result: any, key: keyof typeof formatObj) => {
|
|
|
|
|
let value = formatObj[key]
|
|
|
|
|
if (key === 'a') {
|
|
|
|
|
return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
|
|
|
if (key === 'a') {
|
|
|
|
|
return ['日', '一', '二', '三', '四', '五', '六'][value]
|
|
|
|
|
}
|
|
|
|
|
if (result.length > 0 && value < 10) {
|
|
|
|
|
return '0' + value
|
|
|
|
|
if (result.length > 0 && value < 10) {
|
|
|
|
|
return '0' + value
|
|
|
|
|
}
|
|
|
|
|
return String(value || 0)
|
|
|
|
|
})
|
|
|
|
|
@ -71,40 +69,40 @@ export function parseTime(time: string | Date | number, pattern: string) {
|
|
|
|
|
/**
|
|
|
|
|
* 编码请求参数
|
|
|
|
|
* @param params 要编码的参数
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns 编码后的字符串
|
|
|
|
|
*/
|
|
|
|
|
export function tansParams(params:any) {
|
|
|
|
|
let result = ''
|
|
|
|
|
for (const propName of Object.keys(params)) {
|
|
|
|
|
const value = params[propName];
|
|
|
|
|
var part = encodeURIComponent(propName) + "=";
|
|
|
|
|
if (value !== null && typeof (value) !== "undefined") {
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
|
for (const key of Object.keys(value)) {
|
|
|
|
|
if (value[key] !== null && typeof (value[key]) !== 'undefined') {
|
|
|
|
|
let params = propName + '[' + key + ']';
|
|
|
|
|
var subPart = encodeURIComponent(params) + "=";
|
|
|
|
|
result += subPart + encodeURIComponent(value[key]) + "&";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result += part + encodeURIComponent(value) + "&";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
export function tansParams(params: any) {
|
|
|
|
|
let result = ''
|
|
|
|
|
for (const propName of Object.keys(params)) {
|
|
|
|
|
const value = params[propName];
|
|
|
|
|
var part = encodeURIComponent(propName) + "=";
|
|
|
|
|
if (value !== null && typeof (value) !== "undefined") {
|
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
|
for (const key of Object.keys(value)) {
|
|
|
|
|
if (value[key] !== null && typeof (value[key]) !== 'undefined') {
|
|
|
|
|
let params = propName + '[' + key + ']';
|
|
|
|
|
var subPart = encodeURIComponent(params) + "=";
|
|
|
|
|
result += subPart + encodeURIComponent(value[key]) + "&";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
result += part + encodeURIComponent(value) + "&";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解码请求参数
|
|
|
|
|
* @param str 要解码的字符串
|
|
|
|
|
* @returns
|
|
|
|
|
* @returns 解码后的对象
|
|
|
|
|
*/
|
|
|
|
|
export function untansParams(str:string){
|
|
|
|
|
export function untansParams(str: string) {
|
|
|
|
|
const params = {}
|
|
|
|
|
const pairs = decodeURIComponent(str).split('&');
|
|
|
|
|
for (const pair of pairs) {
|
|
|
|
|
if(pair == '') continue
|
|
|
|
|
if (pair == '') continue
|
|
|
|
|
let [k, v] = pair.split('=');
|
|
|
|
|
let o = undefined
|
|
|
|
|
if (k.indexOf('[')) {
|
|
|
|
|
@ -115,15 +113,37 @@ export function untansParams(str:string){
|
|
|
|
|
k = match[2];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(o == undefined){
|
|
|
|
|
if (o == undefined) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
params[k] = v
|
|
|
|
|
}else{
|
|
|
|
|
} else {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
if(params[o] == undefined)params[o] = {}
|
|
|
|
|
if (params[o] == undefined) params[o] = {}
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
params[o][k] = v
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return params
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 深度复制
|
|
|
|
|
* @param obj 待复制的对象
|
|
|
|
|
* @returns 复制的对象
|
|
|
|
|
*/
|
|
|
|
|
export function deepClone(obj: any) {
|
|
|
|
|
if (obj == null || typeof obj !== 'object') {
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
let result;
|
|
|
|
|
if (Array.isArray(obj)) {
|
|
|
|
|
result = [];
|
|
|
|
|
} else {
|
|
|
|
|
result = new Map();
|
|
|
|
|
}
|
|
|
|
|
for (let [key, value] of Object.entries(obj)) {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
result[key] = deepClone(value);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|