mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-09 13:40:06 +00:00
43 lines
1018 B
TypeScript
43 lines
1018 B
TypeScript
import { isObject, isString } from '/@/utils/is';
|
|
|
|
export function createNow<T extends boolean>(
|
|
join: boolean,
|
|
restful: T
|
|
): T extends true ? string : object;
|
|
|
|
export function createNow(join: boolean, restful = false): string | object {
|
|
if (!join) {
|
|
return restful ? '' : {};
|
|
}
|
|
const now = new Date().getTime();
|
|
if (restful) {
|
|
return `?_t=${now}`;
|
|
}
|
|
return { _t: now };
|
|
}
|
|
|
|
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm';
|
|
/**
|
|
* @description: Format request parameter time
|
|
*/
|
|
export function formatRequestDate(params: any) {
|
|
for (const key in params) {
|
|
if (params[key] && params[key]._isAMomentObject) {
|
|
params[key] = params[key].format(DATE_TIME_FORMAT);
|
|
}
|
|
if (isString(key)) {
|
|
const value = params[key];
|
|
if (value) {
|
|
try {
|
|
params[key] = isString(value) ? value.trim() : value;
|
|
} catch (error) {
|
|
throw new Error(error);
|
|
}
|
|
}
|
|
}
|
|
if (isObject(params[key])) {
|
|
formatRequestDate(params[key]);
|
|
}
|
|
}
|
|
}
|