| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086 |
- /**
- * API 接口配置文件
- */
- // 开发环境和生产环境的 API 基础地址
- // 所有请求通过网关转发
- const BASE_URL = process.env.NODE_ENV === 'development'
- ? 'http://localhost:8083/api' // 开发环境 - 通过网关
- : 'https://your-domain.com/api' // 生产环境
- /**
- * 封装 uni.request
- */
- const request = (options) => {
- return new Promise((resolve, reject) => {
- const token = uni.getStorageSync('token')
- const headers = {
- 'Content-Type': 'application/json'
- }
- if (token) {
- headers['Authorization'] = token
- }
- uni.request({
- url: (/^https?:\/\//.test(options.url) ? options.url : (BASE_URL + options.url)),
- method: options.method || 'GET',
- data: options.data || {},
- header: headers,
- dataType: 'json',
- success: (res) => {
- console.log('API请求成功:', options.url, '状态码:', res.statusCode, '返回数据:', res.data)
- if (res.statusCode === 200) {
- // 根据后端约定的数据格式处理
- if (res.data.code === 200 || res.data.code === 0 || res.data.success) {
- resolve(res.data.data || res.data)
- } else if (res.data.code === 403) {
- // 业务层面的403错误,清除token并跳转登录
- uni.removeStorageSync('token')
- uni.removeStorageSync('userInfo')
- uni.showToast({
- title: res.data.message || res.data.msg || '拒绝访问,请重新登录',
- icon: 'none'
- })
- uni.navigateTo({
- url: '/pages/page3/page3'
- })
- reject(res.data)
- } else {
- uni.showToast({
- title: res.data.message || res.data.msg || '请求失败',
- icon: 'none'
- })
- reject(res.data)
- }
- } else if (res.statusCode === 401) {
- // 未授权,跳转登录
- uni.removeStorageSync('token')
- uni.removeStorageSync('userInfo')
- uni.showToast({
- title: '未授权,请重新登录',
- icon: 'none'
- })
- uni.navigateTo({
- url: '/pages/page3/page3'
- })
- reject(res)
- } else if (res.statusCode === 403) {
- // 拒绝访问,清除token并跳转登录
- uni.removeStorageSync('token')
- uni.removeStorageSync('userInfo')
- uni.showToast({
- title: '拒绝访问,请重新登录',
- icon: 'none'
- })
- uni.navigateTo({
- url: '/pages/page3/page3'
- })
- reject(res)
- } else {
- uni.showToast({
- title: '网络请求失败',
- icon: 'none'
- })
- reject(res)
- }
- },
- fail: (err) => {
- console.error('API请求失败:', options.url, '错误信息:', err)
- uni.showToast({
- title: (err && err.errMsg) ? err.errMsg.replace('request:','') : '网络连接失败',
- icon: 'none'
- })
- reject(err)
- }
- })
- })
- }
- /**
- * API 接口列表
- */
- export default {
- // 地区
- area: {
- // 获取省份列表
- getProvinces: () => request({ url: '/recommend/area/provinces' }),
- // 获取城市列表(可选省份ID)
- getCities: (provinceId) => {
- const url = provinceId ? `/recommend/area/cities?provinceId=${provinceId}` : '/recommend/area/cities'
- return request({ url })
- },
- // 获取区域列表(根据城市ID)
- getAreas: (cityId) => request({ url: `/recommend/area/areas?cityId=${cityId}` })
- },
- // 用户相关
- user: {
- // 获取用户信息
- getInfo: () => request({ url: '/user/info' }),
-
- // 获取指定用户的详细信息(包含简介和照片)
- getDetailInfo: (userId) => request({
- url: `/user/info?userId=${userId}`
- }),
-
- // 查询用户是否为红娘
- getMatchmakerStatus: (userId) => request({
- url: `/user/matchmaker-status?userId=${userId}`
- }),
-
- // 获取今日匹配数
- getMatchCount: () => request({ url: '/user/match-count' }),
-
- // 更新用户基本信息(昵称、头像等)
- updateInfo: (data) => request({
- url: '/user/basic',
- method: 'PUT',
- data
- }),
-
- // 更新单个字段
- updateField: (userId, fieldName, fieldValue) => request({
- url: `/user/basic/field?userId=${userId}&fieldName=${fieldName}&fieldValue=${encodeURIComponent(fieldValue)}`,
- method: 'PUT'
- })
- },
- // 认证相关
- auth: {
- // 密码登录(手机号+密码)
- loginByPassword: (phone, password) => request({
- // 直连 login 服务(开发环境),避免网关未配置导致未路由
- url: 'http://localhost:8087/api/login/password',
- method: 'POST',
- data: { phone, password }
- }),
- // 发送登录验证码(走网关 -> 登录服务)
- sendCode: (phone) => request({
- url: '/login/send-code',
- method: 'POST',
- data: { phone }
- }),
- // 验证码登录(走网关 -> 登录服务)
- smsLogin: (phone, code) => request({
- url: '/login/sms-login',
- method: 'POST',
- data: { phone, code }
- }),
- // 微信登录(直连 login 服务)
- wechatLogin: (data) => request({
- url: 'http://localhost:8087/api/login/wechat/login',
- method: 'POST',
- data: data // ✅ 传递完整的登录数据对象(包含code, nickname, avatarUrl, phoneCode)
- }),
- // 获取微信手机号(直连 login 服务)
- wechatPhone: (code) => request({
- url: 'http://localhost:8087/api/login/wechat/phone',
- method: 'POST',
- data: { code }
- })
- },
- // 首页相关
- home: {
- // 获取轮播图
- getBanners: () => request({ url: '/home/banners' }),
-
- // 获取公告列表
- getNotices: () => request({ url: '/announcement/active' }),
-
- // 获取首页金刚区功能列表
- getFunctionGrid: () => request({ url: '/home/function-grid' }),
-
- // 根据类型获取金刚区功能列表
- getFunctionGridByType: (type) => request({ url: `/home/function-grid/type?type=${type}` }),
-
- // 获取未读消息数
- getUnreadCount: () => request({ url: '/home/unread-count' })
- },
- // 成功案例
- successCase: {
- // 获取成功案例列表
- getList: (params) => request({
- url: '/success-case/list',
- method: 'GET',
- data: params
- }),
-
- // 获取成功案例详情
- getDetail: (caseNo) => request({
- url: `/success-case/detail/${caseNo}`,
- method: 'GET'
- }),
-
- // 获取案例时间线
- getTimeline: (caseNo) => request({
- url: `/success-case/timeline/${caseNo}`,
- method: 'GET'
- })
- },
- // 活动相关
- activity: {
- // 获取活动列表
- getList: (params) => request({
- url: '/activity/list',
- method: 'GET',
- data: params
- }),
-
- // 获取活动详情
- getDetail: (id) => request({
- url: `/activity/detail/${id}`,
- method: 'GET'
- }),
-
- // 报名活动
- register: (activityId, userId) => request({
- url: `/activity/register/${activityId}?userId=${userId}`,
- method: 'POST'
- }),
-
- // 取消报名
- cancelRegister: (activityId) => request({
- url: `/activity/cancel/${activityId}`,
- method: 'POST'
- }),
-
- // 获取我的活动列表
- getMyActivities: (params) => request({
- url: '/activity/my',
- method: 'GET',
- data: params
- }),
-
- // 创建活动订单并获取支付参数
- createOrder: (userId, activityId, activityName, price) => request({
- url: '/activity-order/create',
- method: 'POST',
- data: {
- userId,
- activityId,
- activityName,
- price
- }
- })
- },
- // 课程相关
- course: {
- // 获取课程列表
- getList: (params) => request({
- url: '/course/list',
- method: 'GET',
- data: params
- }),
-
- // 获取课程详情(带学习进度)
- getDetail: (courseId, makerId) => request({
- url: `/course/detail/${courseId}${makerId ? '?makerId=' + makerId : ''}`,
- method: 'GET'
- }),
-
- // 更新学习进度
- updateProgress: (makerId, courseId, progress) => request({
- url: '/course/progress',
- method: 'POST',
- data: { makerId, courseId, progress }
- }),
-
- // 完成课程(领取积分)
- complete: (makerId, courseId) => request({
- url: '/course/complete',
- method: 'POST',
- data: { makerId, courseId }
- }),
-
- // 获取我的学习记录
- getMyProgress: (makerId) => request({
- url: `/course/my-progress?makerId=${makerId}`,
- method: 'GET'
- }),
-
- // 购买课程(旧接口-模拟)
- purchase: (courseId, data) => request({
- url: `/course/purchase/${courseId}`,
- method: 'POST',
- data
- }),
-
- // 积分兑换课程(红娘端 - 旧接口,已废弃)
- exchange: (data) => request({
- url: '/course/exchange',
- method: 'POST',
- data
- }),
-
- // 获取已兑换的课程列表(红娘端 - 旧接口,已废弃)
- getPurchasedList: (makerId) => request({
- url: `/course/purchased?makerId=${makerId}`,
- method: 'GET'
- })
- },
- // 红娘课程相关(独立于用户课程)
- matchmakerCourse: {
- // 获取红娘课程列表
- getList: (params = {}) => request({
- url: '/matchmaker-course/list',
- method: 'GET',
- data: params
- }),
-
- // 根据分类获取红娘课程列表
- getListByCategory: (categoryName) => request({
- url: `/matchmaker-course/list/category?categoryName=${encodeURIComponent(categoryName)}`,
- method: 'GET'
- }),
-
- // 获取所有课程分类
- getCategories: () => request({
- url: '/matchmaker-course/categories',
- method: 'GET'
- }),
-
- // 获取红娘课程详情
- getDetail: (id) => request({
- url: `/matchmaker-course/detail/${id}`,
- method: 'GET'
- }),
-
- // 检查是否已兑换
- checkExchanged: (makerId, courseId) => request({
- url: `/matchmaker-course/check-exchanged?makerId=${makerId}&courseId=${courseId}`,
- method: 'GET'
- }),
-
- // 积分兑换课程
- exchange: (data) => request({
- url: '/matchmaker-course/exchange',
- method: 'POST',
- data
- }),
-
- // 获取已兑换的课程列表
- getPurchasedList: (makerId) => request({
- url: `/matchmaker-course/purchased?makerId=${makerId}`,
- method: 'GET'
- })
- },
- // 课程订单相关(微信支付)
- courseOrder: {
- // 购买课程(获取微信支付参数)
- purchase: (data) => request({
- url: '/course-order/purchase',
- method: 'POST',
- data
- }),
-
- // 检查是否已购买课程
- checkPurchased: (userId, courseId) => request({
- url: `/course-order/check?userId=${userId}&courseId=${courseId}`,
- method: 'GET'
- }),
-
- // 获取已购买的课程列表
- getPurchasedCourses: (userId) => request({
- url: `/course-order/purchased?userId=${userId}`,
- method: 'GET'
- })
- },
- // 红娘相关
- matchmaker: {
- // 获取红娘列表
- getList: (params) => request({
- url: '/matchmaker/list',
- method: 'POST',
- data: params
- }),
-
- // 获取全职红娘列表
- getFormalList: (pageNum, pageSize) => request({
- url: `/matchmaker/formal?pageNum=${pageNum}&pageSize=${pageSize}`
- }),
-
- // 获取红娘详情
- getDetail: (id) => request({
- url: `/matchmaker/detail/${id}`
- }),
-
- // 根据userId查询红娘信息
- getByUserId: (userId) => request({
- url: `/matchmaker/by-user/${userId}`
- }),
-
- // 预约红娘
- book: (matchmakerId, data) => request({
- url: `/matchmaker/book/${matchmakerId}`,
- method: 'POST',
- data
- }),
-
- // 提交红娘申请
- submitApply: (data) => request({
- url: '/matchmaker-apply/submit',
- method: 'POST',
- data
- }),
-
- // 查询红娘申请状态
- getApplyStatus: (userId) => request({
- url: `/matchmaker-apply/status?userId=${userId}`,
- method: 'GET'
- }),
-
- // 工作台相关
- getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
-
- // 获取我的资源
- getMyResources: (params) => request({
- url: '/matchmaker/resources',
- method: 'GET',
- data: params
- }),
-
- // 获取排行榜数据(总排行榜)
- getRankingData: (params) => request({
- url: '/matchmaker/ranking',
- method: 'GET',
- data: params
- }),
-
- // 获取本周排行榜(按点赞数和成功人数平均数排名)
- getWeeklyRanking: (params) => request({
- url: '/matchmaker/weekly-ranking',
- method: 'GET',
- data: params
- }),
-
- // 给红娘点赞(一周只能给同一红娘点赞一次)
- likeMatchmaker: (userId, matchmakerId) => request({
- url: `/matchmaker/like?userId=${userId}&matchmakerId=${matchmakerId}`,
- method: 'POST'
- }),
-
- // 检查是否已点赞
- checkLikeStatus: (userId, matchmakerId) => request({
- url: `/matchmaker/check-like?userId=${userId}&matchmakerId=${matchmakerId}`,
- method: 'GET'
- }),
-
- // 签到相关
- checkinStatus: (makerId) => request({
- url: `/matchmaker/checkin/status?makerId=${makerId}`
- }),
-
- checkinStats: (makerId) => request({
- url: `/matchmaker/checkin/stats?makerId=${makerId}`
- }),
-
- doCheckin: (makerId) => request({
- url: `/matchmaker/checkin/do?makerId=${makerId}`,
- method: 'POST'
- }),
- // 更新红娘资料(编辑资料页使用)
- updateProfile: (matchmakerId, data) => request({
- url: `/matchmaker/update/${matchmakerId}`,
- method: 'PUT',
- data
- }),
-
- // 获取本月签到记录
- checkinList: (makerId, year, month) => request({
- url: `/matchmaker/checkin/list?makerId=${makerId}&year=${year}&month=${month}`
- })
- },
- // 推荐相关
- recommend: {
- // 获取推荐用户列表(网关转发到推荐服务)
- getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
- let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
- if (excludeIds) {
- url += `&excludeIds=${excludeIds}`;
- }
- return request({ url });
- },
- // 行为反馈:like/dislike
- feedback: ({ userId, targetUserId, type }) => request({
- url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
- }),
- // 曝光上报
- exposure: ({ userId, shownUserIds }) => request({
- url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
- }),
- // 规则检索
- search: (query) => request({
- url: '/recommend/search',
- method: 'POST',
- data: query
- }),
- // 获取今日推荐
- getTodayRecommend: () => request({
- url: '/recommend/today'
- })
- },
- // 消息相关
- message: {
- // 获取消息列表
- getList: (params) => request({
- url: '/message/list',
- data: params
- }),
-
- // 获取会话列表
- getConversations: () => request({
- url: '/message/conversations'
- }),
-
- // 发送消息
- send: (data) => request({
- url: '/message/send',
- method: 'POST',
- data
- }),
- // ===== 系统消息 =====
- getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
- const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
- // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
- return res.data || res
- },
- getSystemUnreadCount: async (userId) => {
- const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
- return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
- },
- markSystemRead: (id) => request({
- url: `/message/system/read/${id}`,
- method: 'POST'
- }),
- getSystemDetail: async (id) => {
- const res = await request({ url: `/message/system/detail/${id}` })
- return res.data || res
- },
- markAllSystemRead: (userId) => request({
- url: `/message/system/read-all?userId=${userId}`,
- method: 'POST'
- })
- },
- // 动态相关
- dynamic: {
- // 获取推荐动态列表(广场)
- getRecommendList: (params) => request({
- url: '/dynamic/recommend',
- data: params
- }),
- // 获取动态列表
- getList: (params) => request({
- url: '/dynamic/list',
- data: params
- }),
- // 获取动态详情
- getDetail: (dynamicId, userId) => request({
- url: `/dynamic/detail/${dynamicId}`,
- data: { userId }
- }),
- // 发表评论
- addComment: (dynamicId, content, images, parentCommentId = 0) => request({
- url: `/dynamic/comment`,
- method: 'POST',
- data: { dynamicId, content, images, parentCommentId, userId: 1 },
- header: { 'Content-Type': 'application/json' }
- }),
- // 评论列表
- getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
- url: `/dynamic/comment/list/${dynamicId}`,
- data: { pageNum, pageSize }
- }),
- // 评论点赞/取消
- likeComment: (commentId, userId) => {
- // 如果没有传入userId,从本地存储获取
- if (!userId) {
- const userInfo = uni.getStorageSync('userInfo');
- userId = userInfo ? (userInfo.userId || userInfo.id) : null;
- }
- if (!userId) {
- return Promise.reject(new Error('用户未登录'));
- }
- return request({
- url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
- method: 'POST'
- });
- },
- unlikeComment: (commentId, userId) => {
- // 如果没有传入userId,从本地存储获取
- if (!userId) {
- const userInfo = uni.getStorageSync('userInfo');
- userId = userInfo ? (userInfo.userId || userInfo.id) : null;
- }
- if (!userId) {
- return Promise.reject(new Error('用户未登录'));
- }
- return request({
- url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
- method: 'DELETE'
- });
- },
- // 获取用户动态列表
- getUserDynamics: (userId, params) => {
- const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
- let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
- if (currentUserId) {
- url += `¤tUserId=${currentUserId}`
- }
- return request({
- url: url,
- method: 'GET'
- })
- },
- // 点赞动态
- like: (dynamicId, userId) => {
- // 如果没有传入userId,从本地存储获取
- if (!userId) {
- const userInfo = uni.getStorageSync('userInfo');
- userId = userInfo ? (userInfo.userId || userInfo.id) : null;
- }
- if (!userId) {
- return Promise.reject(new Error('用户未登录'));
- }
- return request({
- url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
- method: 'POST'
- });
- },
- // 取消点赞
- unlike: (dynamicId, userId) => {
- // 如果没有传入userId,从本地存储获取
- if (!userId) {
- const userInfo = uni.getStorageSync('userInfo');
- userId = userInfo ? (userInfo.userId || userInfo.id) : null;
- }
- if (!userId) {
- return Promise.reject(new Error('用户未登录'));
- }
- return request({
- url: `/dynamic/like/${dynamicId}?userId=${userId}`,
- method: 'DELETE'
- });
- },
- // 收藏动态
- favorite: (dynamicId, userId) => {
- // 如果没有传入userId,从本地存储获取
- if (!userId) {
- const userInfo = uni.getStorageSync('userInfo');
- userId = userInfo ? (userInfo.userId || userInfo.id) : null;
- }
- if (!userId) {
- return Promise.reject(new Error('用户未登录'));
- }
- return request({
- url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
- method: 'POST'
- });
- },
- // 取消收藏
- unfavorite: (dynamicId, userId) => {
- // 如果没有传入userId,从本地存储获取
- if (!userId) {
- const userInfo = uni.getStorageSync('userInfo');
- userId = userInfo ? (userInfo.userId || userInfo.id) : null;
- }
- if (!userId) {
- return Promise.reject(new Error('用户未登录'));
- }
- return request({
- url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
- method: 'DELETE'
- });
- },
- // 创建个人动态
- createUserDynamic: (payload) => request({
- url: '/dynamic/user',
- method: 'POST',
- data: payload,
- header: { 'Content-Type': 'application/json' }
- }),
- // 更新个人动态
- updateUserDynamic: (dynamicId, userId, payload) => request({
- url: `/dynamic/user/${dynamicId}?userId=${userId}`,
- method: 'PUT',
- data: payload,
- header: { 'Content-Type': 'application/json' }
- }),
- // 删除个人动态
- deleteUserDynamic: (dynamicId, userId) => request({
- url: `/dynamic/user/${dynamicId}?userId=${userId}`,
- method: 'DELETE'
- }),
- // 删除动态(旧接口,保留兼容)
- delete: (dynamicId) => request({
- url: `/dynamic/${dynamicId}`,
- method: 'DELETE'
- }),
- // 发布动态(文本或已存在的媒体URL列表)
- publish: (payload) => request({
- url: '/dynamic/publish',
- method: 'POST',
- data: payload,
- header: { 'Content-Type': 'application/json' }
- }),
- // 单个文件上传方法
- uploadSingle: (filePath) => {
- return new Promise((resolve, reject) => {
- console.log('开始上传文件:', filePath)
- console.log('上传URL:', BASE_URL + '/dynamic/publish/upload')
- uni.uploadFile({
- url: BASE_URL + '/dynamic/publish/upload',
- filePath: filePath,
- name: 'file',
- success: (res) => {
- console.log('上传响应:', res)
- try {
- const data = JSON.parse(res.data)
- console.log('解析后的响应数据:', data)
- if (data.code === 200 || data.code === 0 || data.success) {
- console.log('上传成功,返回URL:', data.data)
- resolve(data.data)
- } else {
- console.error('上传失败,服务器返回错误:', data)
- reject(new Error(data.message || '上传失败'))
- }
- } catch (e) {
- console.error('解析响应数据失败:', e, '原始响应:', res.data)
- reject(new Error('解析响应数据失败'))
- }
- },
- fail: (error) => {
- console.error('上传请求失败:', error)
- reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
- }
- })
- })
- },
- // 批量上传多个文件(遍历调用单个上传)
- uploadBatch: (filePaths) => {
- return new Promise(async (resolve, reject) => {
- const urls = []
- try {
- for (let filePath of filePaths) {
- const url = await new Promise((resolveUpload, rejectUpload) => {
- uni.uploadFile({
- url: BASE_URL + '/dynamic/publish/upload',
- filePath: filePath,
- name: 'file',
- success: (res) => {
- try {
- const data = JSON.parse(res.data)
- if (data.code === 200 || data.code === 0 || data.success) {
- resolveUpload(data.data)
- } else {
- rejectUpload(data)
- }
- } catch (e) {
- rejectUpload(e)
- }
- },
- fail: rejectUpload
- })
- })
- urls.push(url)
- }
- resolve(urls)
- } catch (e) {
- reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
- }
- })
- },
- // 提交举报
- submitReport: (data) => request({
- url: '/dynamic/report',
- method: 'POST',
- data
- }),
-
- // 获取用户收藏列表
- getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
- url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
- }),
-
- // 获取用户点赞列表
- getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
- url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
- }),
-
- // 获取用户浏览记录列表
- getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
- url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
- }),
-
- // 清空用户浏览记录
- clearBrowseHistory: (userId) => request({
- url: `/dynamic/browse-history?userId=${userId}`,
- method: 'DELETE'
- })
- },
- // VIP相关
- vip: {
- // 获取VIP信息(状态、套餐等)
- getInfo: (userId) => request({
- url: `/vip/info?userId=${userId}`
- }),
-
- // 获取VIP套餐列表
- getPackages: () => request({
- url: '/vip/packages'
- }),
-
- // 购买VIP套餐(获取支付参数)
- purchase: (userId, packageId) => request({
- url: '/vip/purchase',
- method: 'POST',
- data: { userId, packageId }
- }),
-
- // 查询订单状态
- getOrderStatus: (orderNo) => request({
- url: `/vip/order/status?orderNo=${orderNo}`
- }),
- // 新增:查询支付状态(userId + packageId)
- checkPayStatus: (userId, packageId) => request({
- url: '/vip/checkPayStatus',
- method: 'GET',
- data: { userId, packageId }
- })
- },
-
- // 用户反馈
- feedback: {
- // 提交用户反馈
- submit: (data) => request({
- url: '/feedback/submit',
- method: 'POST',
- data
- }),
- // 上传反馈图片
- uploadImage: (filePath) => {
- return new Promise((resolve, reject) => {
- uni.uploadFile({
- url: BASE_URL + '/feedback/upload',
- filePath: filePath,
- name: 'file',
- success: (res) => {
- try {
- const data = JSON.parse(res.data)
- if (data.code === 200 || data.code === 0 || data.success) {
- resolve(data.data)
- } else {
- reject(new Error(data.message || '上传失败'))
- }
- } catch (e) {
- reject(new Error('解析响应数据失败'))
- }
- },
- fail: (error) => {
- reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
- }
- })
- })
- }
- },
- // 积分商城相关
- pointsMall: {
- // 获取商品列表
- getProducts: (params) => request({
- url: '/points/products',
- method: 'GET',
- data: params
- }),
-
- // 获取推荐商品
- getRecommendProducts: (limit = 10) => request({
- url: `/points/products/recommend?limit=${limit}`,
- method: 'GET'
- }),
-
- // 获取商品详情
- getProductDetail: (id) => request({
- url: `/points/products/${id}`,
- method: 'GET'
- }),
-
- // 获取积分余额
- getBalance: (makerId) => request({
- url: `/points/balance?makerId=${makerId}`,
- method: 'GET'
- }),
-
- // 获取积分明细
- getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
- url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
- method: 'GET'
- }),
-
- // 获取积分规则
- getRules: () => request({
- url: '/points/rules',
- method: 'GET'
- }),
-
- // 兑换商品
- exchange: (data) => request({
- url: '/points/exchange',
- method: 'POST',
- data
- }),
-
- // 获取订单列表
- getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
- let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
- if (status !== undefined && status !== null) {
- url += `&status=${status}`
- }
- return request({ url, method: 'GET' })
- },
-
- // 获取订单详情
- getOrderDetail: (orderNo) => request({
- url: `/points/orders/${orderNo}`,
- method: 'GET'
- }),
-
- // 增加积分(签到等)
- addPoints: (makerId, ruleType, reason) => request({
- url: '/points/add',
- method: 'POST',
- data: { makerId, ruleType, reason }
- })
- },
- // 我的资源相关(通过网关访问8081服务)
- myResource: {
- // 获取资源列表
- getList: (matchmakerId, keyword, pageNum = 1, pageSize = 10) => {
- let url = `/my-resource/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
- if (keyword) {
- url += `&keyword=${encodeURIComponent(keyword)}`
- }
- return request({ url })
- },
-
- // 搜索资源(按姓名或手机号)
- search: (matchmakerId, keyword, gender) => {
- let url = `/my-resource/search?matchmakerId=${matchmakerId}`
- if (keyword) {
- url += `&keyword=${encodeURIComponent(keyword)}`
- }
- if (gender) {
- url += `&gender=${gender}`
- }
- return request({ url })
- },
-
- // 获取资源下拉列表
- getDropdown: (matchmakerId, gender) => {
- let url = `/my-resource/dropdown?matchmakerId=${matchmakerId}`
- if (gender) {
- url += `&gender=${gender}`
- }
- return request({ url })
- },
-
- // 获取已注册用户的资源下拉列表(user_id不为空)
- getRegisteredDropdown: (matchmakerId, gender) => {
- let url = `/my-resource/registered-dropdown?matchmakerId=${matchmakerId}`
- if (gender) {
- url += `&gender=${gender}`
- }
- return request({ url })
- },
-
- // 搜索已注册用户的资源(user_id不为空)
- searchRegistered: (matchmakerId, keyword, gender) => {
- let url = `/my-resource/registered-search?matchmakerId=${matchmakerId}`
- if (keyword) {
- url += `&keyword=${encodeURIComponent(keyword)}`
- }
- if (gender) {
- url += `&gender=${gender}`
- }
- return request({ url })
- }
- },
- // 撮合成功案例上传相关(通过网关访问1004服务)
- successCaseUpload: {
- // 提交成功案例
- submit: (data) => request({
- url: '/success-case-upload/submit',
- method: 'POST',
- data
- }),
-
- // 获取成功案例列表
- getList: (matchmakerId, pageNum = 1, pageSize = 10) => request({
- url: `/success-case-upload/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
- }),
-
- // 获取审核记录列表
- getAuditRecords: (matchmakerId, auditStatus, pageNum = 1, pageSize = 20) => {
- let url = `/success-case-upload/audit-records?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
- if (auditStatus !== null && auditStatus !== undefined) {
- url += `&auditStatus=${auditStatus}`
- }
- return request({ url })
- },
-
- // 获取审核记录详情
- getAuditRecordDetail: (id) => request({
- url: `/success-case-upload/audit-records/${id}`
- }),
-
- // 标记审核记录为已读
- markAsRead: (id) => request({
- url: `/success-case-upload/audit-records/${id}/read`,
- method: 'POST'
- }),
-
- // 获取未读审核记录数量
- getUnreadCount: (matchmakerId) => request({
- url: `/success-case-upload/audit-records/unread-count?matchmakerId=${matchmakerId}`
- })
- }
- }
- // 导出 request 函数供其他模块使用
- export { request }
|