vben
2021-11-10 3fcfac1f37c2aeabbb2af4897ada6ba8c225c667
src/utils/http/axios/helper.ts
@@ -1,11 +1,13 @@
import { isObject, isString } from '/@/utils/is';
export function createNow<T extends boolean>(
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export function joinTimestamp<T extends boolean>(
  join: boolean,
  restful: T
  restful: T,
): T extends true ? string : object;
export function createNow(join: boolean, restful = false): string | object {
export function joinTimestamp(join: boolean, restful = false): string | object {
  if (!join) {
    return restful ? '' : {};
  }
@@ -13,19 +15,20 @@
  if (restful) {
    return `?_t=${now}`;
  }
  return {
    _t: now,
  };
  return { _t: now };
}
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm';
/**
 * @description: 格式化请求参数时间
 * @description: Format request parameter time
 */
export function formatRequestDate(params: any) {
export function formatRequestDate(params: Recordable) {
  if (Object.prototype.toString.call(params) !== '[object Object]') {
    return;
  }
  for (const key in params) {
    if (params[key] && params[key]._isAMomentObject) {
    const format = params[key]?.format ?? null;
    if (format && typeof format === 'function') {
      params[key] = params[key].format(DATE_TIME_FORMAT);
    }
    if (isString(key)) {
@@ -33,7 +36,7 @@
      if (value) {
        try {
          params[key] = isString(value) ? value.trim() : value;
        } catch (error) {
        } catch (error: any) {
          throw new Error(error);
        }
      }