You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
908 B
28 lines
908 B
import { request, AxiosRequestConfig } from '@/request.ts'
|
|
import { IPage, IPageResult } from '@/types'
|
|
|
|
|
|
export const createCURD = <TParams, TResult>(api: string, options?: AxiosRequestConfig) => {
|
|
|
|
return {
|
|
list: (params?: TParams & IPage) => {
|
|
return request.post<IPageResult<TResult>>(`${api}/list`, { ...options, ...params }).then(data => data.data)
|
|
},
|
|
add: (data: TParams) => {
|
|
return request.post<TResult>(`${api}/add`, data, options)
|
|
},
|
|
update: (data: TParams) => {
|
|
return request.post(`${api}/edit`, data, options)
|
|
},
|
|
delete: (id: number) => {
|
|
return request.delete(`${api}/delete`, { ...options, params: { id } })
|
|
},
|
|
batchDelete: (ids: number[]) => {
|
|
return request.delete(`${api}/deletes`, { ...options, params: { ids } })
|
|
},
|
|
info: (id: number) => {
|
|
return request.get<TResult>(`${api}/${id}`, options)
|
|
}
|
|
}
|
|
|
|
}
|