Generating commit message...
This commit is contained in:
189
mini-program/api/services.js
Normal file
189
mini-program/api/services.js
Normal file
@@ -0,0 +1,189 @@
|
||||
import request from './request.js'
|
||||
import config from './config.js'
|
||||
|
||||
const { endpoints } = config
|
||||
|
||||
// 用户服务
|
||||
export const userService = {
|
||||
// 登录
|
||||
login: (data) => request.post(endpoints.USER.LOGIN, data),
|
||||
|
||||
// 注册
|
||||
register: (data) => request.post(endpoints.USER.REGISTER, data),
|
||||
|
||||
// 获取用户信息
|
||||
getProfile: () => request.get(endpoints.USER.PROFILE),
|
||||
|
||||
// 更新用户信息
|
||||
updateProfile: (data) => request.put(endpoints.USER.UPDATE_PROFILE, data),
|
||||
|
||||
// 上传头像
|
||||
uploadAvatar: (filePath) => request.upload(endpoints.USER.UPLOAD_AVATAR, filePath),
|
||||
|
||||
// 退出登录
|
||||
logout: () => {
|
||||
uni.removeStorageSync('token')
|
||||
uni.removeStorageSync('refreshToken')
|
||||
return Promise.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
// 旅行计划服务
|
||||
export const travelService = {
|
||||
// 获取旅行计划列表
|
||||
getList: (params = {}) => request.get(endpoints.TRAVEL.LIST, params),
|
||||
|
||||
// 获取旅行计划详情
|
||||
getDetail: (id) => request.get(`${endpoints.TRAVEL.DETAIL}/${id}`),
|
||||
|
||||
// 创建旅行计划
|
||||
create: (data) => request.post(endpoints.TRAVEL.CREATE, data),
|
||||
|
||||
// 加入旅行计划
|
||||
join: (travelId) => request.post(`${endpoints.TRAVEL.JOIN}/${travelId}`),
|
||||
|
||||
// 获取我的旅行计划
|
||||
getMyPlans: (params = {}) => request.get(endpoints.TRAVEL.MY_PLANS, params),
|
||||
|
||||
// 搜索旅行计划
|
||||
search: (keyword, params = {}) => request.get(endpoints.TRAVEL.SEARCH, { keyword, ...params })
|
||||
}
|
||||
|
||||
// 动物认养服务
|
||||
export const animalService = {
|
||||
// 获取动物列表
|
||||
getList: (params = {}) => request.get(endpoints.ANIMAL.LIST, params),
|
||||
|
||||
// 获取动物详情
|
||||
getDetail: (id) => request.get(`${endpoints.ANIMAL.DETAIL}/${id}`),
|
||||
|
||||
// 认养动物
|
||||
adopt: (animalId, data) => request.post(`${endpoints.ANIMAL.ADOPT}/${animalId}`, data),
|
||||
|
||||
// 获取我的动物
|
||||
getMyAnimals: (params = {}) => request.get(endpoints.ANIMAL.MY_ANIMALS, params),
|
||||
|
||||
// 获取动物分类
|
||||
getCategories: () => request.get(endpoints.ANIMAL.CATEGORIES)
|
||||
}
|
||||
|
||||
// 送花服务
|
||||
export const flowerService = {
|
||||
// 获取花束列表
|
||||
getList: (params = {}) => request.get(endpoints.FLOWER.LIST, params),
|
||||
|
||||
// 获取花束详情
|
||||
getDetail: (id) => request.get(`${endpoints.FLOWER.DETAIL}/${id}`),
|
||||
|
||||
// 下单
|
||||
order: (data) => request.post(endpoints.FLOWER.ORDER, data),
|
||||
|
||||
// 获取我的订单
|
||||
getMyOrders: (params = {}) => request.get(endpoints.FLOWER.MY_ORDERS, params),
|
||||
|
||||
// 获取花束分类
|
||||
getCategories: () => request.get(endpoints.FLOWER.CATEGORIES)
|
||||
}
|
||||
|
||||
// 订单服务
|
||||
export const orderService = {
|
||||
// 获取订单列表
|
||||
getList: (params = {}) => request.get(endpoints.ORDER.LIST, params),
|
||||
|
||||
// 获取订单详情
|
||||
getDetail: (id) => request.get(`${endpoints.ORDER.DETAIL}/${id}`),
|
||||
|
||||
// 取消订单
|
||||
cancel: (id) => request.post(`${endpoints.ORDER.CANCEL}/${id}`),
|
||||
|
||||
// 支付订单
|
||||
pay: (id) => request.post(`${endpoints.ORDER.PAY}/${id}`),
|
||||
|
||||
// 确认收货
|
||||
confirm: (id) => request.post(`${endpoints.ORDER.CONFIRM}/${id}`)
|
||||
}
|
||||
|
||||
// 支付服务
|
||||
export const paymentService = {
|
||||
// 创建支付
|
||||
create: (data) => request.post(endpoints.PAYMENT.CREATE, data),
|
||||
|
||||
// 查询支付状态
|
||||
query: (paymentId) => request.get(`${endpoints.PAYMENT.QUERY}/${paymentId}`),
|
||||
|
||||
// 退款
|
||||
refund: (paymentId, data) => request.post(`${endpoints.PAYMENT.REFUND}/${paymentId}`, data)
|
||||
}
|
||||
|
||||
// 系统服务
|
||||
export const systemService = {
|
||||
// 获取系统配置
|
||||
getConfig: () => request.get(endpoints.SYSTEM.CONFIG),
|
||||
|
||||
// 获取公告列表
|
||||
getNotices: (params = {}) => request.get(endpoints.SYSTEM.NOTICE, params),
|
||||
|
||||
// 提交反馈
|
||||
submitFeedback: (data) => request.post(endpoints.SYSTEM.FEEDBACK, data)
|
||||
}
|
||||
|
||||
// 首页数据服务
|
||||
export const homeService = {
|
||||
// 获取首页数据
|
||||
getHomeData: () => request.get('/home/data'),
|
||||
|
||||
// 获取轮播图
|
||||
getBanners: () => request.get('/home/banners'),
|
||||
|
||||
// 获取推荐旅行计划
|
||||
getRecommendedTravels: () => request.get('/home/recommended-travels'),
|
||||
|
||||
// 获取热门动物
|
||||
getHotAnimals: () => request.get('/home/hot-animals'),
|
||||
|
||||
// 获取精选花束
|
||||
getFeaturedFlowers: () => request.get('/home/featured-flowers')
|
||||
}
|
||||
|
||||
// 工具函数
|
||||
export const apiUtils = {
|
||||
// 生成分页参数
|
||||
generatePagination: (page = 1, pageSize = 10) => ({
|
||||
page,
|
||||
pageSize,
|
||||
skip: (page - 1) * pageSize
|
||||
}),
|
||||
|
||||
// 处理上传进度
|
||||
handleUploadProgress: (progressEvent) => {
|
||||
const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||
return percent
|
||||
},
|
||||
|
||||
// 处理下载进度
|
||||
handleDownloadProgress: (progressEvent) => {
|
||||
const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||
return percent
|
||||
},
|
||||
|
||||
// 格式化错误信息
|
||||
formatError: (error) => {
|
||||
if (error.code) {
|
||||
return error.message
|
||||
}
|
||||
return '网络连接失败,请检查网络设置'
|
||||
}
|
||||
}
|
||||
|
||||
// 默认导出所有服务
|
||||
export default {
|
||||
userService,
|
||||
travelService,
|
||||
animalService,
|
||||
flowerService,
|
||||
orderService,
|
||||
paymentService,
|
||||
systemService,
|
||||
homeService,
|
||||
apiUtils
|
||||
}
|
||||
Reference in New Issue
Block a user