38 lines
962 B
TypeScript
38 lines
962 B
TypeScript
import request from '@/utils/request'
|
|
import login from './login'
|
|
import commodity from './commodity'
|
|
|
|
const totalApiConfig = {
|
|
login,
|
|
commodity
|
|
}
|
|
|
|
Object.values(totalApiConfig).forEach((apiConfig) => {
|
|
Object.values(apiConfig).forEach((arr) => {
|
|
const [url, other = {}] = arr as [string, Recordable<any>]
|
|
Object.setPrototypeOf(arr, {
|
|
post: (data: any = {}) => {
|
|
let newUrl = url
|
|
if (other.id) {
|
|
newUrl += url.endsWith('/') ? data.id : `/${data.id}`
|
|
delete data.id
|
|
}
|
|
return request.post({ url: newUrl, data, ...other })
|
|
},
|
|
get: (data: any = {}) => {
|
|
let newUrl = url
|
|
if (other.id) {
|
|
newUrl += url.endsWith('/') ? data.id : `/${data.id}`
|
|
delete data.id
|
|
}
|
|
return request.get({ url: newUrl, params: data, ...other })
|
|
}
|
|
})
|
|
})
|
|
})
|
|
|
|
export default totalApiConfig
|
|
|
|
export const api = totalApiConfig
|
|
export const abc = 123
|