37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
import { get, post, put, del } from "@/utils/request";
|
|
import { API_BASE } from "@/utils/config";
|
|
|
|
export const getSpots = (params) => get("/spots", params);
|
|
|
|
export const getNearbySpots = (params) => get("/spots/nearby", params);
|
|
|
|
export const getSpotDetail = (id) => get(`/spots/${id}`);
|
|
|
|
export const createSpot = (data) => post("/spots", data);
|
|
|
|
export const updateSpot = (id, data) => put(`/spots/${id}`, data);
|
|
|
|
export const deleteSpot = (id) => del(`/spots/${id}`);
|
|
|
|
export const getMySpots = (params) => get("/spots/mine", params);
|
|
|
|
export const uploadImage = (filePath) => {
|
|
const token = uni.getStorageSync("access_token");
|
|
return new Promise((resolve, reject) => {
|
|
uni.uploadFile({
|
|
url: API_BASE + "/upload/image",
|
|
filePath,
|
|
name: "file",
|
|
header: token ? { Authorization: `Bearer ${token}` } : {},
|
|
success: (res) => {
|
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
resolve(JSON.parse(res.data));
|
|
} else {
|
|
reject(new Error("上传失败"));
|
|
}
|
|
},
|
|
fail: (err) => reject(err),
|
|
});
|
|
});
|
|
};
|