diff --git a/src/utils/ajax.ts b/src/utils/ajax.ts deleted file mode 100644 index f4200a4..0000000 --- a/src/utils/ajax.ts +++ /dev/null @@ -1,39 +0,0 @@ -const serverUrl = import.meta.env.DEV ? "http://172.16.4.152:4500" : ""; - -interface AjaxRes { - code: number; - text: string; - data: T; -} - -const ajaxGet = (url: string): Promise> => { - return fetch(serverUrl + url) - .then((res) => res.json()) - .catch((err) => { - console.log(`catch error when fetch url: ${url}`, err); - return { code: 1, text: "网络异常" }; - }); -}; - -const ajaxPost = ( - url: string, - data: Record -): Promise> => { - return fetch(serverUrl + url, { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(data), - }) - .then((res) => res.json()) - .catch((err) => { - console.log(`catch error when fetch url: ${url}`, err); - return { code: 1, text: "网络异常" }; - }); -}; - -export default { - get: ajaxGet, - post: ajaxPost, -}; diff --git a/src/utils/api.ts b/src/utils/api.ts deleted file mode 100644 index 8d74523..0000000 --- a/src/utils/api.ts +++ /dev/null @@ -1,42 +0,0 @@ -import ajax from "./ajax"; - -export const getItems = () => { - return ajax.get("/api/items/search"); -}; - -export const getItemById = (id: string) => { - return ajax.get(`/api/items/detail?id=${id}`); -}; - -export const getMyItems = () => { - return ajax.get("/api/my/search"); -}; - -export const addItem = (data: any) => { - // return ajax.post("/api/items/add-internal", data); - return ajax.post("/api/items/add", data); -}; - -export const editItem = (data: any) => { - return ajax.post("/api/items/edit", data); -}; - -export const deleteItem = (id: string) => { - return ajax.post("/api/items/delete", { id }); -}; - -export const addFavorite = (id: string) => { - return ajax.post("/api/favorite/add", { id }); -}; - -export const deleteFavorite = (id: string) => { - return ajax.post("/api/favorite/delete", { id }); -}; - -export const addShared = (id: string) => { - return ajax.post("/api/shared/add", { id }); -}; - -export const deleteShared = (id: string) => { - return ajax.post("/api/shared/delete", { id }); -};