import useRequest from '@/services/request'; const { get, put, post, del, getList, getAll, putList, postList, delList, } = useRequest(); export const useService = (endpoint: string): Services => { return { getById: async (id: string) => { return await get(`${endpoint}/${id}`); }, create: async (form: T) => { return await post(`${endpoint}`, form); }, updateById: async (id: string, form: T) => { return await put(`${endpoint}/${id}`, form); }, deleteById: async (id: string) => { return await del(`${endpoint}/${id}`); }, getList: async (params?: ListRequestParams) => { return await getList(`${endpoint}`, params); }, getAll: async () => { return await getAll(`${endpoint}`); }, createList: async (data: T[]) => { return await postList(`${endpoint}/batch`, data); }, updateList: async (ids: string[], data: T, fields: string[]) => { return await putList(`${endpoint}`, {ids, data: JSON.stringify(data), fields}); }, deleteList: async (ids: string[]) => { return await delList(`${endpoint}`, {ids}); }, }; };