295 lines
8.0 KiB
JavaScript
295 lines
8.0 KiB
JavaScript
import request from "@/utils/request.js"
|
|
|
|
/**
|
|
* 微信小程序登录
|
|
* @param {object} params - 登录参数 { code: string }
|
|
*/
|
|
export function login(params) {
|
|
return request.post('/member/auth/miniapp/login', params)
|
|
}
|
|
|
|
/**
|
|
* 发送短信验证码
|
|
* @param {object} params - { phone: string }
|
|
*/
|
|
export function sendCode(params) {
|
|
return request.post('/auth/phone/send-code', params)
|
|
}
|
|
|
|
/**
|
|
* 手机号验证码登录
|
|
* @param {object} params - { phone: string, code: string }
|
|
*/
|
|
export function loginWithPhone(params) {
|
|
return request.post('/auth/phone/code-login', params)
|
|
}
|
|
|
|
/**
|
|
* 手机号一键登录
|
|
* @param {object} params - { accessToken: string, openid: string, nickname?: string, avatar?: string }
|
|
*/
|
|
export function oneClickLogin(params) {
|
|
return request.post('/auth/phone/one-click-login', params)
|
|
}
|
|
|
|
/**
|
|
* 退出登录
|
|
*/
|
|
export function logout() {
|
|
return request.post('/member/auth/logout')
|
|
}
|
|
|
|
/**
|
|
* 获取签到二维码
|
|
* @param {object} options - 请求选项 { cache: boolean, cacheTime: number }
|
|
*/
|
|
export function getQRCode(options = { cache: true, cacheTime: 5 * 60 * 1000 }) {
|
|
return request.get('/checkIn/qrcode', {}, options)
|
|
}
|
|
|
|
/**
|
|
* 扫码签到
|
|
* @param {object} params - { qrcode: string, memberId: number }
|
|
*/
|
|
export function checkIn(params) {
|
|
return request.post('/checkIn', params)
|
|
}
|
|
|
|
/**
|
|
* 获取签到记录(分页)
|
|
* @param {object} params - { page: number, size: number }
|
|
* @param {object} options - 请求选项
|
|
*/
|
|
export function getCheckInRecords(params = {}, options = {}) {
|
|
const { page = 0, size = 5 } = params
|
|
return request.post('/checkIn/page', { page, size }, options)
|
|
}
|
|
|
|
/**
|
|
* 获取用户未读消息数量
|
|
* @param {number} userId - 用户ID
|
|
* @param {object} options - 请求选项
|
|
*/
|
|
export function getUnreadMessageCount(userId, options = {}) {
|
|
return request.get(`/messages/user/${userId}/unread`, {}, options)
|
|
}
|
|
|
|
// ========== 消息相关API ==========
|
|
|
|
/**
|
|
* 获取用户消息列表(支持分页)
|
|
* @param {number} userId - 用户ID
|
|
* @param {object} params - 查询参数
|
|
* @param {number} params.page - 页码(从0开始)
|
|
* @param {number} params.size - 每页条数
|
|
* @param {object} options - 请求选项
|
|
* @returns {Promise} 消息列表
|
|
*/
|
|
export function getUserMessages(userId, params = {}, options = {}) {
|
|
const { page = 0, size = 10 } = params
|
|
return request.get(`/messages/user/${userId}/page`, { page, size }, options)
|
|
}
|
|
|
|
/**
|
|
* 获取未读消息列表(支持分页)
|
|
* @param {number} userId - 用户ID
|
|
* @param {object} params - 查询参数
|
|
* @param {number} params.page - 页码(从0开始)
|
|
* @param {number} params.size - 每页条数
|
|
* @param {object} options - 请求选项
|
|
* @returns {Promise} 未读消息列表
|
|
*/
|
|
export function getUnreadMessages(userId, params = {}, options = {}) {
|
|
const { page = 0, size = 10 } = params
|
|
return request.get(`/messages/user/${userId}/unread/page`, { page, size }, options)
|
|
}
|
|
|
|
/**
|
|
* 标记消息为已读
|
|
* @param {number|string} id - 消息ID
|
|
* @param {object} options - 请求选项
|
|
* @returns {Promise} 操作结果
|
|
*/
|
|
export function markMessageAsRead(id, options = {}) {
|
|
return request.put(`/messages/${id}/read`, {}, options)
|
|
}
|
|
|
|
/**
|
|
* 标记所有消息为已读
|
|
* @param {number} userId - 用户ID
|
|
* @param {object} options - 请求选项
|
|
* @returns {Promise} 操作结果
|
|
*/
|
|
export function markAllMessagesAsRead(userId, options = {}) {
|
|
return request.put(`/messages/user/${userId}/read`, {}, options)
|
|
}
|
|
|
|
/**
|
|
* 删除消息
|
|
* @param {number|string} id - 消息ID
|
|
* @param {object} options - 请求选项
|
|
* @returns {Promise} 操作结果
|
|
*/
|
|
export function deleteMessage(id, options = {}) {
|
|
return request.delete(`/messages/${id}`, {}, options)
|
|
}
|
|
|
|
/**
|
|
* 获取用户信息(基础信息缓存)
|
|
* @param {object} options - 请求选项 { cache: boolean, cacheTime: number }
|
|
*/
|
|
export function getUserInfo(options = { cache: true, cacheTime: 30 * 60 * 1000 }) {
|
|
return request.get('/member/info', {}, options)
|
|
}
|
|
|
|
/**
|
|
* 获取会员详细信息(包含会员卡、积分等)
|
|
* @param {object} options - 请求选项 { cache: boolean }
|
|
*/
|
|
export function getMemberDetail(options = { cache: false }) {
|
|
return request.get('/member/info', {}, options)
|
|
}
|
|
|
|
/**
|
|
* 获取签到统计
|
|
* @param {object} params - 查询参数 { startDate: string, endDate: string }
|
|
* @param {object} options - 请求选项 { cache: boolean }
|
|
*/
|
|
export function getCheckInStats(params = {}, options = { cache: false }) {
|
|
return request.get('/checkIn/statistics', params, options)
|
|
}
|
|
|
|
/**
|
|
* 更新用户信息
|
|
* @param {object} params - 用户信息参数
|
|
*/
|
|
export function updateUserInfo(params) {
|
|
return request.put('/member/info', params)
|
|
}
|
|
|
|
// ========== 系统配置相关API ==========
|
|
|
|
/**
|
|
* 根据配置键获取配置值
|
|
* @param {string} configKey - 配置键
|
|
* @param {object} options - 请求选项
|
|
*/
|
|
export function getConfigByKey(configKey, options = {}) {
|
|
return request.get(`/config/key/${configKey}`, {}, options)
|
|
}
|
|
|
|
// ========== 课程相关API ==========
|
|
|
|
/**
|
|
* 获取推荐课程列表
|
|
* @param {object} options - 请求选项 { cache: boolean, cacheTime: number }
|
|
*/
|
|
export function getRecommendCourses(options = { cache: true, cacheTime: 10 * 60 * 1000 }) {
|
|
return request.get('/course/recommend', {}, options)
|
|
}
|
|
|
|
/**
|
|
* 获取课程详情
|
|
* @param {number} id - 课程ID
|
|
* @param {object} options - 请求选项 { cache: boolean, cacheTime: number }
|
|
*/
|
|
export function getCourseDetail(id, options = { cache: true, cacheTime: 15 * 60 * 1000 }) {
|
|
return request.get(`/course/${id}`, {}, options)
|
|
}
|
|
|
|
/**
|
|
* 获取团课列表(分页)
|
|
* @param {object} params - 查询参数 { page: number, size: number, sort: string, order: string, keyword: string }
|
|
* @param {object} options - 请求选项 { cache: boolean, cacheTime: number }
|
|
*/
|
|
export function getGroupCoursePage(params = {}, options = { cache: true, cacheTime: 5 * 60 * 1000 }) {
|
|
const { page = 0, size = 10, sort = 'id', order = 'asc', keyword } = params
|
|
return request.post('/groupCourse/page', { page, size, sort, order, keyword }, options)
|
|
}
|
|
|
|
// ========== 团课预约相关API ==========
|
|
|
|
/**
|
|
* 预约团课
|
|
* @param {object} params - 预约参数
|
|
* @param {number} params.courseId - 团课ID
|
|
* @param {number} params.memberId - 会员ID
|
|
*/
|
|
export function bookGroupCourse(params) {
|
|
return request.post('/groupCourse/book', params)
|
|
}
|
|
|
|
/**
|
|
* 取消预约
|
|
* @param {number} bookingId - 预约ID
|
|
*/
|
|
export function cancelBooking(bookingId) {
|
|
return request.delete(`/groupCourse/book/${bookingId}`, {})
|
|
}
|
|
|
|
/**
|
|
* 团课签到
|
|
* @param {number} memberId - 会员ID
|
|
* @param {number} courseId - 团课ID
|
|
*/
|
|
export function signinGroupCourse(memberId, courseId) {
|
|
return request.post(`/groupCourse/signin/${memberId}`, { courseId })
|
|
}
|
|
|
|
/**
|
|
* 查询会员预约记录
|
|
* @param {number} memberId - 会员ID
|
|
*/
|
|
export function getMemberBookings(memberId, options = { cache: false }) {
|
|
return request.get(`/groupCourse/bookings/member/${memberId}`, {}, options)
|
|
}
|
|
|
|
/**
|
|
* 查询课程预约记录
|
|
* @param {number} courseId - 团课ID
|
|
*/
|
|
export function getCourseBookings(courseId, options = { cache: false }) {
|
|
return request.get(`/groupCourse/bookings/course/${courseId}`, {}, options)
|
|
}
|
|
|
|
// ========== 轮播图相关API ==========
|
|
|
|
/**
|
|
* 获取启用的轮播图列表
|
|
* @param {object} options - 请求选项 { cache: boolean, cacheTime: number }
|
|
*/
|
|
export function getActiveBanners(options = { cache: true, cacheTime: 10 * 60 * 1000 }) {
|
|
return request.get('/banner/active', {}, options)
|
|
}
|
|
|
|
export default {
|
|
login,
|
|
sendCode,
|
|
loginWithPhone,
|
|
oneClickLogin,
|
|
logout,
|
|
getQRCode,
|
|
checkIn,
|
|
getCheckInRecords,
|
|
getCheckInStats,
|
|
getUnreadMessageCount,
|
|
getUserMessages,
|
|
getUnreadMessages,
|
|
markMessageAsRead,
|
|
markAllMessagesAsRead,
|
|
deleteMessage,
|
|
getUserInfo,
|
|
getMemberDetail,
|
|
updateUserInfo,
|
|
getConfigByKey,
|
|
getRecommendCourses,
|
|
getCourseDetail,
|
|
getGroupCoursePage,
|
|
bookGroupCourse,
|
|
cancelBooking,
|
|
signinGroupCourse,
|
|
getMemberBookings,
|
|
getCourseBookings,
|
|
getActiveBanners
|
|
}
|