| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169 |
- /**
- * API 接口配置文件
- */
- // 开发环境和生产环境的 API 基础地址
- // 所有请求通过网关转发
- const BASE_URL = process.env.NODE_ENV === 'development'
- ? 'https://api.zhongruanke.cn/api' // 开发环境 - 通过网关
- : 'https://api.zhongruanke.cn/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) => {
- 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' }),
- // 用户签到相关(独立于红娘签到)
- checkinStatus: (userId) => request({
- url: `/user/checkin/status?userId=${userId}`
- }),
- checkinStats: (userId) => request({
- url: `/user/checkin/stats?userId=${userId}`
- }),
- doCheckin: (userId) => request({
- url: `/user/checkin/do?userId=${userId}`,
- method: 'POST'
- }),
- checkinInfo: (userId, year, month) => request({
- url: `/user/checkin/info?userId=${userId}&year=${year}&month=${month}`
- }),
- // 更新用户基本信息(昵称、头像等)
- 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: 'https://api.zhongruanke.cn/api/login/wechat/login',
- method: 'POST',
- data: data // ✅ 传递完整的登录数据对象(包含code, nickname, avatarUrl, phoneCode)
- }),
- // 获取微信手机号(直连 login 服务)
- wechatPhone: (code) => request({
- url: 'https://api.zhongruanke.cn/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'
- }),
- // 获取签到信息,包括当月已签到日期
- checkinInfo: (makerId, year, month) => request({
- url: `/matchmaker/checkin/info?makerId=${makerId}&year=${year}&month=${month}`
- }),
- // 更新红娘资料(编辑资料页使用)
- updateProfile: (matchmakerId, data) => request({
- url: `/matchmaker/update/${matchmakerId}`,
- method: 'PUT',
- data
- }),
- // 上传红娘头像
- uploadAvatar: (filePath) => {
- return new Promise((resolve, reject) => {
- uni.uploadFile({
- url: BASE_URL + '/matchmaker/upload/avatar',
- filePath: filePath,
- name: 'file',
- header: {
- 'Content-Type': 'multipart/form-data'
- },
- success: (res) => {
- console.log('上传响应:', res)
- try {
- const data = JSON.parse(res.data)
- if (data.code === 200 || data.code === 0 || data.success) {
- resolve(data.data)
- } else {
- console.error('上传失败:', data)
- reject(new Error(data.message || data.msg || '上传失败'))
- }
- } catch (e) {
- console.error('解析响应失败:', e, res.data)
- reject(new Error('解析响应数据失败'))
- }
- },
- fail: (error) => {
- console.error('上传请求失败:', error)
- reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
- }
- })
- })
- },
- // 获取本月签到记录
- 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'
- }),
- // 获取用户喜欢的列表
- getLikedUsers: (userId, limit, offset) => request({
- url: `/recommend/liked-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
- }),
- // 获取用户喜欢的用户数量
- getLikedUsersCount: (userId) => request({
- url: `/recommend/liked-users-count?userId=${userId}`
- }),
- // 获取喜欢我的用户列表
- getLikedMeUsers: (userId, limit, offset) => request({
- url: `/recommend/liked-me-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
- }),
- // 获取喜欢我的用户数量
- getLikedMeUsersCount: (userId) => request({
- url: `/recommend/liked-me-users-count?userId=${userId}`
- }),
- // 保存用户浏览记录
- saveUserLook: (userId, lookUserId) => request({
- url: `/recommend/save-look?userId=${userId}&lookUserId=${lookUserId}`,
- method: 'POST'
- }),
- // 获取用户浏览记录列表
- getBrowseHistory: (userId, limit, offset) => request({
- url: `/recommend/browse-history?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
- }),
- // 获取用户浏览记录数量
- getBrowseHistoryCount: (userId) => request({
- url: `/recommend/browse-history-count?userId=${userId}`
- })
- },
- // 消息相关
- 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) => {
- 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) {
- 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 }
|