feat: add vue3(element-plus)
This commit is contained in:
45
yudao-ui-admin-vue3/src/config/axios/helper.ts
Normal file
45
yudao-ui-admin-vue3/src/config/axios/helper.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { isObject, isString } from '@/utils/is'
|
||||
|
||||
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
|
||||
|
||||
export function joinTimestamp<T extends boolean>(
|
||||
join: boolean,
|
||||
restful: T
|
||||
): T extends true ? string : object
|
||||
|
||||
export function joinTimestamp(join: boolean, restful = false): string | object {
|
||||
if (!join) {
|
||||
return restful ? '' : {}
|
||||
}
|
||||
const now = new Date().getTime()
|
||||
if (restful) {
|
||||
return `?_t=${now}`
|
||||
}
|
||||
return { _t: now }
|
||||
}
|
||||
|
||||
/** 格式化请求参数中的时间 */
|
||||
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) {
|
||||
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: any) {
|
||||
throw new Error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isObject(params[key])) {
|
||||
formatRequestDate(params[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user