api.js 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. /**
  2. * API 接口配置文件
  3. */
  4. // 开发环境和生产环境的 API 基础地址
  5. // 所有请求通过网关转发
  6. const BASE_URL = process.env.NODE_ENV === 'development'
  7. ? 'https://api.zhongruanke.cn/api' // 开发环境 - 通过网关
  8. : 'https://api.zhongruanke.cn/api' // 生产环境
  9. /**
  10. * 封装 uni.request
  11. */
  12. const request = (options) => {
  13. return new Promise((resolve, reject) => {
  14. const token = uni.getStorageSync('token')
  15. const headers = {
  16. 'Content-Type': 'application/json'
  17. }
  18. if (token) {
  19. headers['Authorization'] = token
  20. }
  21. uni.request({
  22. url: (/^https?:\/\//.test(options.url) ? options.url : (BASE_URL + options.url)),
  23. method: options.method || 'GET',
  24. data: options.data || {},
  25. header: headers,
  26. dataType: 'json',
  27. success: (res) => {
  28. if (res.statusCode === 200) {
  29. // 根据后端约定的数据格式处理
  30. if (res.data.code === 200 || res.data.code === 0 || res.data.success) {
  31. resolve(res.data.data || res.data)
  32. } else if (res.data.code === 403) {
  33. // 业务层面的403错误,清除token并跳转登录
  34. uni.removeStorageSync('token')
  35. uni.removeStorageSync('userInfo')
  36. uni.showToast({
  37. title: res.data.message || res.data.msg || '拒绝访问,请重新登录',
  38. icon: 'none'
  39. })
  40. uni.navigateTo({
  41. url: '/pages/page3/page3'
  42. })
  43. reject(res.data)
  44. } else {
  45. uni.showToast({
  46. title: res.data.message || res.data.msg || '请求失败',
  47. icon: 'none'
  48. })
  49. reject(res.data)
  50. }
  51. } else if (res.statusCode === 401) {
  52. // 未授权,跳转登录
  53. uni.removeStorageSync('token')
  54. uni.removeStorageSync('userInfo')
  55. uni.showToast({
  56. title: '未授权,请重新登录',
  57. icon: 'none'
  58. })
  59. uni.navigateTo({
  60. url: '/pages/page3/page3'
  61. })
  62. reject(res)
  63. } else if (res.statusCode === 403) {
  64. // 拒绝访问,清除token并跳转登录
  65. uni.removeStorageSync('token')
  66. uni.removeStorageSync('userInfo')
  67. uni.showToast({
  68. title: '拒绝访问,请重新登录',
  69. icon: 'none'
  70. })
  71. uni.navigateTo({
  72. url: '/pages/page3/page3'
  73. })
  74. reject(res)
  75. } else {
  76. uni.showToast({
  77. title: '网络请求失败',
  78. icon: 'none'
  79. })
  80. reject(res)
  81. }
  82. },
  83. fail: (err) => {
  84. console.error('API请求失败:', options.url, '错误信息:', err)
  85. uni.showToast({
  86. title: (err && err.errMsg) ? err.errMsg.replace('request:','') : '网络连接失败',
  87. icon: 'none'
  88. })
  89. reject(err)
  90. }
  91. })
  92. })
  93. }
  94. /**
  95. * API 接口列表
  96. */
  97. export default {
  98. // 底部导航栏配置
  99. tabbar: {
  100. // 获取用户端导航配置
  101. getUserTabbar: () => request({ url: '/tabbar/user' }),
  102. // 获取红娘端导航配置
  103. getMatchmakerTabbar: () => request({ url: '/tabbar/matchmaker' }),
  104. // 获取指定客户端类型的导航配置
  105. getTabbarConfig: (clientType = 'user') => request({ url: `/tabbar/config?clientType=${clientType}` })
  106. },
  107. // 地区
  108. area: {
  109. // 获取省份列表
  110. getProvinces: () => request({ url: '/recommend/area/provinces' }),
  111. // 获取城市列表(可选省份ID)
  112. getCities: (provinceId) => {
  113. const url = provinceId ? `/recommend/area/cities?provinceId=${provinceId}` : '/recommend/area/cities'
  114. return request({ url })
  115. },
  116. // 获取区域列表(根据城市ID)
  117. getAreas: (cityId) => request({ url: `/recommend/area/areas?cityId=${cityId}` })
  118. },
  119. // 用户相关
  120. user: {
  121. // 获取用户信息
  122. getInfo: () => request({ url: '/user/info' }),
  123. // 获取指定用户的详细信息(包含简介和照片)
  124. getDetailInfo: (userId) => request({
  125. url: `/user/info?userId=${userId}`
  126. }),
  127. // 查询用户是否为红娘
  128. getMatchmakerStatus: (userId) => request({
  129. url: `/user/matchmaker-status?userId=${userId}`
  130. }),
  131. // 获取今日匹配数
  132. getMatchCount: () => request({ url: '/user/match-count' }),
  133. // 用户签到相关(独立于红娘签到)
  134. checkinStatus: (userId) => request({
  135. url: `/user/checkin/status?userId=${userId}`
  136. }),
  137. checkinStats: (userId) => request({
  138. url: `/user/checkin/stats?userId=${userId}`
  139. }),
  140. doCheckin: (userId) => request({
  141. url: `/user/checkin/do?userId=${userId}`,
  142. method: 'POST'
  143. }),
  144. checkinInfo: (userId, year, month) => request({
  145. url: `/user/checkin/info?userId=${userId}&year=${year}&month=${month}`
  146. }),
  147. // 更新用户基本信息(昵称、头像等)
  148. updateInfo: (data) => request({
  149. url: '/user/basic',
  150. method: 'PUT',
  151. data
  152. }),
  153. // 更新单个字段
  154. updateField: (userId, fieldName, fieldValue) => request({
  155. url: `/user/basic/field?userId=${userId}&fieldName=${fieldName}&fieldValue=${encodeURIComponent(fieldValue)}`,
  156. method: 'PUT'
  157. })
  158. },
  159. // 认证相关
  160. auth: {
  161. // 密码登录(手机号+密码)
  162. loginByPassword: (phone, password) => request({
  163. // 直连 login 服务(开发环境),避免网关未配置导致未路由
  164. url: 'http://localhost:8087/api/login/password',
  165. method: 'POST',
  166. data: { phone, password }
  167. }),
  168. // 发送登录验证码(走网关 -> 登录服务)
  169. sendCode: (phone) => request({
  170. url: '/login/send-code',
  171. method: 'POST',
  172. data: { phone }
  173. }),
  174. // 验证码登录(走网关 -> 登录服务)
  175. smsLogin: (phone, code) => request({
  176. url: '/login/sms-login',
  177. method: 'POST',
  178. data: { phone, code }
  179. }),
  180. // 微信登录(直连 login 服务)
  181. wechatLogin: (data) => request({
  182. url: 'https://api.zhongruanke.cn/api/login/wechat/login',
  183. method: 'POST',
  184. data: data // ✅ 传递完整的登录数据对象(包含code, nickname, avatarUrl, phoneCode)
  185. }),
  186. // 获取微信手机号(直连 login 服务)
  187. wechatPhone: (code) => request({
  188. url: 'https://api.zhongruanke.cn/api/login/wechat/phone',
  189. method: 'POST',
  190. data: { code }
  191. })
  192. },
  193. // 首页相关
  194. home: {
  195. // 获取轮播图
  196. getBanners: () => request({ url: '/home/banners' }),
  197. // 获取公告列表
  198. getNotices: () => request({ url: '/announcement/active' }),
  199. // 获取首页金刚区功能列表
  200. getFunctionGrid: () => request({ url: '/home/function-grid' }),
  201. // 根据类型获取金刚区功能列表
  202. getFunctionGridByType: (type) => request({ url: `/home/function-grid/type?type=${type}` }),
  203. // 获取未读消息数
  204. getUnreadCount: () => request({ url: '/home/unread-count' })
  205. },
  206. // 成功案例
  207. successCase: {
  208. // 获取成功案例列表
  209. getList: (params) => request({
  210. url: '/success-case/list',
  211. method: 'GET',
  212. data: params
  213. }),
  214. // 获取成功案例详情
  215. getDetail: (caseNo) => request({
  216. url: `/success-case/detail/${caseNo}`,
  217. method: 'GET'
  218. }),
  219. // 获取案例时间线
  220. getTimeline: (caseNo) => request({
  221. url: `/success-case/timeline/${caseNo}`,
  222. method: 'GET'
  223. })
  224. },
  225. // 活动相关
  226. activity: {
  227. // 获取活动列表
  228. getList: (params) => request({
  229. url: '/activity/list',
  230. method: 'GET',
  231. data: params
  232. }),
  233. // 获取活动详情
  234. getDetail: (id) => request({
  235. url: `/activity/detail/${id}`,
  236. method: 'GET'
  237. }),
  238. // 报名活动
  239. register: (activityId, userId) => request({
  240. url: `/activity/register/${activityId}?userId=${userId}`,
  241. method: 'POST'
  242. }),
  243. // 取消报名
  244. cancelRegister: (activityId) => request({
  245. url: `/activity/cancel/${activityId}`,
  246. method: 'POST'
  247. }),
  248. // 获取我的活动列表
  249. getMyActivities: (params) => request({
  250. url: '/activity/my',
  251. method: 'GET',
  252. data: params
  253. }),
  254. // 创建活动订单并获取支付参数
  255. createOrder: (userId, activityId, activityName, price) => request({
  256. url: '/activity-order/create',
  257. method: 'POST',
  258. data: {
  259. userId,
  260. activityId,
  261. activityName,
  262. price
  263. }
  264. })
  265. },
  266. // 课程相关
  267. course: {
  268. // 获取课程列表
  269. getList: (params) => request({
  270. url: '/course/list',
  271. method: 'GET',
  272. data: params
  273. }),
  274. // 获取课程详情(带学习进度)
  275. getDetail: (courseId, makerId) => request({
  276. url: `/course/detail/${courseId}${makerId ? '?makerId=' + makerId : ''}`,
  277. method: 'GET'
  278. }),
  279. // 更新学习进度
  280. updateProgress: (makerId, courseId, progress) => request({
  281. url: '/course/progress',
  282. method: 'POST',
  283. data: { makerId, courseId, progress }
  284. }),
  285. // 完成课程(领取积分)
  286. complete: (makerId, courseId) => request({
  287. url: '/course/complete',
  288. method: 'POST',
  289. data: { makerId, courseId }
  290. }),
  291. // 获取我的学习记录
  292. getMyProgress: (makerId) => request({
  293. url: `/course/my-progress?makerId=${makerId}`,
  294. method: 'GET'
  295. }),
  296. // 购买课程(旧接口-模拟)
  297. purchase: (courseId, data) => request({
  298. url: `/course/purchase/${courseId}`,
  299. method: 'POST',
  300. data
  301. }),
  302. // 积分兑换课程(红娘端 - 旧接口,已废弃)
  303. exchange: (data) => request({
  304. url: '/course/exchange',
  305. method: 'POST',
  306. data
  307. }),
  308. // 获取已兑换的课程列表(红娘端 - 旧接口,已废弃)
  309. getPurchasedList: (makerId) => request({
  310. url: `/course/purchased?makerId=${makerId}`,
  311. method: 'GET'
  312. })
  313. },
  314. // 红娘课程相关(独立于用户课程)
  315. matchmakerCourse: {
  316. // 获取红娘课程列表
  317. getList: (params = {}) => request({
  318. url: '/matchmaker-course/list',
  319. method: 'GET',
  320. data: params
  321. }),
  322. // 根据分类获取红娘课程列表
  323. getListByCategory: (categoryName) => request({
  324. url: `/matchmaker-course/list/category?categoryName=${encodeURIComponent(categoryName)}`,
  325. method: 'GET'
  326. }),
  327. // 获取所有课程分类
  328. getCategories: () => request({
  329. url: '/matchmaker-course/categories',
  330. method: 'GET'
  331. }),
  332. // 获取红娘课程详情
  333. getDetail: (id) => request({
  334. url: `/matchmaker-course/detail/${id}`,
  335. method: 'GET'
  336. }),
  337. // 检查是否已兑换
  338. checkExchanged: (makerId, courseId) => request({
  339. url: `/matchmaker-course/check-exchanged?makerId=${makerId}&courseId=${courseId}`,
  340. method: 'GET'
  341. }),
  342. // 积分兑换课程
  343. exchange: (data) => request({
  344. url: '/matchmaker-course/exchange',
  345. method: 'POST',
  346. data
  347. }),
  348. // 获取已兑换的课程列表
  349. getPurchasedList: (makerId) => request({
  350. url: `/matchmaker-course/purchased?makerId=${makerId}`,
  351. method: 'GET'
  352. })
  353. },
  354. // 课程订单相关(微信支付)
  355. courseOrder: {
  356. // 购买课程(获取微信支付参数)
  357. purchase: (data) => request({
  358. url: '/course-order/purchase',
  359. method: 'POST',
  360. data
  361. }),
  362. // 检查是否已购买课程
  363. checkPurchased: (userId, courseId) => request({
  364. url: `/course-order/check?userId=${userId}&courseId=${courseId}`,
  365. method: 'GET'
  366. }),
  367. // 获取已购买的课程列表
  368. getPurchasedCourses: (userId) => request({
  369. url: `/course-order/purchased?userId=${userId}`,
  370. method: 'GET'
  371. })
  372. },
  373. // 红娘相关
  374. matchmaker: {
  375. // 获取红娘列表
  376. getList: (params) => request({
  377. url: '/matchmaker/list',
  378. method: 'POST',
  379. data: params
  380. }),
  381. // 获取全职红娘列表
  382. getFormalList: (pageNum, pageSize) => request({
  383. url: `/matchmaker/formal?pageNum=${pageNum}&pageSize=${pageSize}`
  384. }),
  385. // 获取红娘详情
  386. getDetail: (id) => request({
  387. url: `/matchmaker/detail/${id}`
  388. }),
  389. // 根据userId查询红娘信息
  390. getByUserId: (userId) => request({
  391. url: `/matchmaker/by-user/${userId}`
  392. }),
  393. // 预约红娘
  394. book: (matchmakerId, data) => request({
  395. url: `/matchmaker/book/${matchmakerId}`,
  396. method: 'POST',
  397. data
  398. }),
  399. // 提交红娘申请
  400. submitApply: (data) => request({
  401. url: '/matchmaker-apply/submit',
  402. method: 'POST',
  403. data
  404. }),
  405. // 查询红娘申请状态
  406. getApplyStatus: (userId) => request({
  407. url: `/matchmaker-apply/status?userId=${userId}`,
  408. method: 'GET'
  409. }),
  410. // 工作台相关
  411. getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
  412. // 获取我的资源
  413. getMyResources: (params) => request({
  414. url: '/matchmaker/resources',
  415. method: 'GET',
  416. data: params
  417. }),
  418. // 获取排行榜数据(总排行榜)
  419. getRankingData: (params) => request({
  420. url: '/matchmaker/ranking',
  421. method: 'GET',
  422. data: params
  423. }),
  424. // 获取本周排行榜(按点赞数和成功人数平均数排名)
  425. getWeeklyRanking: (params) => request({
  426. url: '/matchmaker/weekly-ranking',
  427. method: 'GET',
  428. data: params
  429. }),
  430. // 给红娘点赞(一周只能给同一红娘点赞一次)
  431. likeMatchmaker: (userId, matchmakerId) => request({
  432. url: `/matchmaker/like?userId=${userId}&matchmakerId=${matchmakerId}`,
  433. method: 'POST'
  434. }),
  435. // 检查是否已点赞
  436. checkLikeStatus: (userId, matchmakerId) => request({
  437. url: `/matchmaker/check-like?userId=${userId}&matchmakerId=${matchmakerId}`,
  438. method: 'GET'
  439. }),
  440. // 签到相关
  441. checkinStatus: (makerId) => request({
  442. url: `/matchmaker/checkin/status?makerId=${makerId}`
  443. }),
  444. checkinStats: (makerId) => request({
  445. url: `/matchmaker/checkin/stats?makerId=${makerId}`
  446. }),
  447. doCheckin: (makerId) => request({
  448. url: `/matchmaker/checkin/do?makerId=${makerId}`,
  449. method: 'POST'
  450. }),
  451. // 获取签到信息,包括当月已签到日期
  452. checkinInfo: (makerId, year, month) => request({
  453. url: `/matchmaker/checkin/info?makerId=${makerId}&year=${year}&month=${month}`
  454. }),
  455. // 更新红娘资料(编辑资料页使用)
  456. updateProfile: (matchmakerId, data) => request({
  457. url: `/matchmaker/update/${matchmakerId}`,
  458. method: 'PUT',
  459. data
  460. }),
  461. // 上传红娘头像
  462. uploadAvatar: (filePath) => {
  463. return new Promise((resolve, reject) => {
  464. uni.uploadFile({
  465. url: BASE_URL + '/matchmaker/upload/avatar',
  466. filePath: filePath,
  467. name: 'file',
  468. header: {
  469. 'Content-Type': 'multipart/form-data'
  470. },
  471. success: (res) => {
  472. console.log('上传响应:', res)
  473. try {
  474. const data = JSON.parse(res.data)
  475. if (data.code === 200 || data.code === 0 || data.success) {
  476. resolve(data.data)
  477. } else {
  478. console.error('上传失败:', data)
  479. reject(new Error(data.message || data.msg || '上传失败'))
  480. }
  481. } catch (e) {
  482. console.error('解析响应失败:', e, res.data)
  483. reject(new Error('解析响应数据失败'))
  484. }
  485. },
  486. fail: (error) => {
  487. console.error('上传请求失败:', error)
  488. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  489. }
  490. })
  491. })
  492. },
  493. // 获取本月签到记录
  494. checkinList: (makerId, year, month) => request({
  495. url: `/matchmaker/checkin/list?makerId=${makerId}&year=${year}&month=${month}`
  496. })
  497. },
  498. // 推荐相关
  499. recommend: {
  500. // 获取推荐用户列表(网关转发到推荐服务)
  501. getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
  502. let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
  503. if (excludeIds) {
  504. url += `&excludeIds=${excludeIds}`;
  505. }
  506. return request({ url });
  507. },
  508. // 行为反馈:like/dislike
  509. feedback: ({ userId, targetUserId, type }) => request({
  510. url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
  511. }),
  512. // 曝光上报
  513. exposure: ({ userId, shownUserIds }) => request({
  514. url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
  515. }),
  516. // 规则检索
  517. search: (query) => request({
  518. url: '/recommend/search',
  519. method: 'POST',
  520. data: query
  521. }),
  522. // 获取今日推荐
  523. getTodayRecommend: () => request({
  524. url: '/recommend/today'
  525. }),
  526. // 获取用户喜欢的列表
  527. getLikedUsers: (userId, limit, offset) => request({
  528. url: `/recommend/liked-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  529. }),
  530. // 获取用户喜欢的用户数量
  531. getLikedUsersCount: (userId) => request({
  532. url: `/recommend/liked-users-count?userId=${userId}`
  533. }),
  534. // 获取喜欢我的用户列表
  535. getLikedMeUsers: (userId, limit, offset) => request({
  536. url: `/recommend/liked-me-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  537. }),
  538. // 获取喜欢我的用户数量
  539. getLikedMeUsersCount: (userId) => request({
  540. url: `/recommend/liked-me-users-count?userId=${userId}`
  541. }),
  542. // 保存用户浏览记录
  543. saveUserLook: (userId, lookUserId) => request({
  544. url: `/recommend/save-look?userId=${userId}&lookUserId=${lookUserId}`,
  545. method: 'POST'
  546. }),
  547. // 获取用户浏览记录列表
  548. getBrowseHistory: (userId, limit, offset) => request({
  549. url: `/recommend/browse-history?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  550. }),
  551. // 获取用户浏览记录数量
  552. getBrowseHistoryCount: (userId) => request({
  553. url: `/recommend/browse-history-count?userId=${userId}`
  554. })
  555. },
  556. // 消息相关
  557. message: {
  558. // 获取消息列表
  559. getList: (params) => request({
  560. url: '/message/list',
  561. data: params
  562. }),
  563. // 获取会话列表
  564. getConversations: () => request({
  565. url: '/message/conversations'
  566. }),
  567. // 发送消息
  568. send: (data) => request({
  569. url: '/message/send',
  570. method: 'POST',
  571. data
  572. }),
  573. // ===== 系统消息 =====
  574. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  575. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  576. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  577. return res.data || res
  578. },
  579. getSystemUnreadCount: async (userId) => {
  580. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  581. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  582. },
  583. markSystemRead: (id) => request({
  584. url: `/message/system/read/${id}`,
  585. method: 'POST'
  586. }),
  587. getSystemDetail: async (id) => {
  588. const res = await request({ url: `/message/system/detail/${id}` })
  589. return res.data || res
  590. },
  591. markAllSystemRead: (userId) => request({
  592. url: `/message/system/read-all?userId=${userId}`,
  593. method: 'POST'
  594. })
  595. },
  596. // 动态相关
  597. dynamic: {
  598. // 获取推荐动态列表(广场)
  599. getRecommendList: (params) => request({
  600. url: '/dynamic/recommend',
  601. data: params
  602. }),
  603. // 获取动态列表
  604. getList: (params) => request({
  605. url: '/dynamic/list',
  606. data: params
  607. }),
  608. // 获取动态详情
  609. getDetail: (dynamicId, userId) => request({
  610. url: `/dynamic/detail/${dynamicId}`,
  611. data: { userId }
  612. }),
  613. // 发表评论
  614. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  615. url: `/dynamic/comment`,
  616. method: 'POST',
  617. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  618. header: { 'Content-Type': 'application/json' }
  619. }),
  620. // 评论列表
  621. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  622. url: `/dynamic/comment/list/${dynamicId}`,
  623. data: { pageNum, pageSize }
  624. }),
  625. // 评论点赞/取消
  626. likeComment: (commentId, userId) => {
  627. // 如果没有传入userId,从本地存储获取
  628. if (!userId) {
  629. const userInfo = uni.getStorageSync('userInfo');
  630. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  631. }
  632. if (!userId) {
  633. return Promise.reject(new Error('用户未登录'));
  634. }
  635. return request({
  636. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  637. method: 'POST'
  638. });
  639. },
  640. unlikeComment: (commentId, userId) => {
  641. // 如果没有传入userId,从本地存储获取
  642. if (!userId) {
  643. const userInfo = uni.getStorageSync('userInfo');
  644. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  645. }
  646. if (!userId) {
  647. return Promise.reject(new Error('用户未登录'));
  648. }
  649. return request({
  650. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  651. method: 'DELETE'
  652. });
  653. },
  654. // 获取用户动态列表
  655. getUserDynamics: (userId, params) => {
  656. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  657. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  658. if (currentUserId) {
  659. url += `&currentUserId=${currentUserId}`
  660. }
  661. return request({
  662. url: url,
  663. method: 'GET'
  664. })
  665. },
  666. // 点赞动态
  667. like: (dynamicId, userId) => {
  668. // 如果没有传入userId,从本地存储获取
  669. if (!userId) {
  670. const userInfo = uni.getStorageSync('userInfo');
  671. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  672. }
  673. if (!userId) {
  674. return Promise.reject(new Error('用户未登录'));
  675. }
  676. return request({
  677. url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
  678. method: 'POST'
  679. });
  680. },
  681. // 取消点赞
  682. unlike: (dynamicId, userId) => {
  683. // 如果没有传入userId,从本地存储获取
  684. if (!userId) {
  685. const userInfo = uni.getStorageSync('userInfo');
  686. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  687. }
  688. if (!userId) {
  689. return Promise.reject(new Error('用户未登录'));
  690. }
  691. return request({
  692. url: `/dynamic/like/${dynamicId}?userId=${userId}`,
  693. method: 'DELETE'
  694. });
  695. },
  696. // 收藏动态
  697. favorite: (dynamicId, userId) => {
  698. // 如果没有传入userId,从本地存储获取
  699. if (!userId) {
  700. const userInfo = uni.getStorageSync('userInfo');
  701. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  702. }
  703. if (!userId) {
  704. return Promise.reject(new Error('用户未登录'));
  705. }
  706. return request({
  707. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  708. method: 'POST'
  709. });
  710. },
  711. // 取消收藏
  712. unfavorite: (dynamicId, userId) => {
  713. // 如果没有传入userId,从本地存储获取
  714. if (!userId) {
  715. const userInfo = uni.getStorageSync('userInfo');
  716. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  717. }
  718. if (!userId) {
  719. return Promise.reject(new Error('用户未登录'));
  720. }
  721. return request({
  722. url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
  723. method: 'DELETE'
  724. });
  725. },
  726. // 创建个人动态
  727. createUserDynamic: (payload) => request({
  728. url: '/dynamic/user',
  729. method: 'POST',
  730. data: payload,
  731. header: { 'Content-Type': 'application/json' }
  732. }),
  733. // 更新个人动态
  734. updateUserDynamic: (dynamicId, userId, payload) => request({
  735. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  736. method: 'PUT',
  737. data: payload,
  738. header: { 'Content-Type': 'application/json' }
  739. }),
  740. // 删除个人动态
  741. deleteUserDynamic: (dynamicId, userId) => request({
  742. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  743. method: 'DELETE'
  744. }),
  745. // 删除动态(旧接口,保留兼容)
  746. delete: (dynamicId) => request({
  747. url: `/dynamic/${dynamicId}`,
  748. method: 'DELETE'
  749. }),
  750. // 发布动态(文本或已存在的媒体URL列表)
  751. publish: (payload) => request({
  752. url: '/dynamic/publish',
  753. method: 'POST',
  754. data: payload,
  755. header: { 'Content-Type': 'application/json' }
  756. }),
  757. // 单个文件上传方法
  758. uploadSingle: (filePath) => {
  759. return new Promise((resolve, reject) => {
  760. uni.uploadFile({
  761. url: BASE_URL + '/dynamic/publish/upload',
  762. filePath: filePath,
  763. name: 'file',
  764. success: (res) => {
  765. try {
  766. const data = JSON.parse(res.data)
  767. if (data.code === 200 || data.code === 0 || data.success) {
  768. resolve(data.data)
  769. } else {
  770. console.error('上传失败,服务器返回错误:', data)
  771. reject(new Error(data.message || '上传失败'))
  772. }
  773. } catch (e) {
  774. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  775. reject(new Error('解析响应数据失败'))
  776. }
  777. },
  778. fail: (error) => {
  779. console.error('上传请求失败:', error)
  780. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  781. }
  782. })
  783. })
  784. },
  785. // 批量上传多个文件(遍历调用单个上传)
  786. uploadBatch: (filePaths) => {
  787. return new Promise(async (resolve, reject) => {
  788. const urls = []
  789. try {
  790. for (let filePath of filePaths) {
  791. const url = await new Promise((resolveUpload, rejectUpload) => {
  792. uni.uploadFile({
  793. url: BASE_URL + '/dynamic/publish/upload',
  794. filePath: filePath,
  795. name: 'file',
  796. success: (res) => {
  797. try {
  798. const data = JSON.parse(res.data)
  799. if (data.code === 200 || data.code === 0 || data.success) {
  800. resolveUpload(data.data)
  801. } else {
  802. rejectUpload(data)
  803. }
  804. } catch (e) {
  805. rejectUpload(e)
  806. }
  807. },
  808. fail: rejectUpload
  809. })
  810. })
  811. urls.push(url)
  812. }
  813. resolve(urls)
  814. } catch (e) {
  815. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  816. }
  817. })
  818. },
  819. // 提交举报
  820. submitReport: (data) => request({
  821. url: '/dynamic/report',
  822. method: 'POST',
  823. data
  824. }),
  825. // 获取用户收藏列表
  826. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  827. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  828. }),
  829. // 获取用户点赞列表
  830. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  831. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  832. }),
  833. // 获取用户浏览记录列表
  834. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  835. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  836. }),
  837. // 清空用户浏览记录
  838. clearBrowseHistory: (userId) => request({
  839. url: `/dynamic/browse-history?userId=${userId}`,
  840. method: 'DELETE'
  841. })
  842. },
  843. // VIP相关
  844. vip: {
  845. // 获取VIP信息(状态、套餐等)
  846. getInfo: (userId) => request({
  847. url: `/vip/info?userId=${userId}`
  848. }),
  849. // 获取VIP套餐列表
  850. getPackages: () => request({
  851. url: '/vip/packages'
  852. }),
  853. // 购买VIP套餐(获取支付参数)
  854. purchase: (userId, packageId) => request({
  855. url: '/vip/purchase',
  856. method: 'POST',
  857. data: { userId, packageId }
  858. }),
  859. // 查询订单状态
  860. getOrderStatus: (orderNo) => request({
  861. url: `/vip/order/status?orderNo=${orderNo}`
  862. }),
  863. // 新增:查询支付状态(userId + packageId)
  864. checkPayStatus: (userId, packageId) => request({
  865. url: '/vip/checkPayStatus',
  866. method: 'GET',
  867. data: { userId, packageId }
  868. })
  869. },
  870. // 用户反馈
  871. feedback: {
  872. // 提交用户反馈
  873. submit: (data) => request({
  874. url: '/feedback/submit',
  875. method: 'POST',
  876. data
  877. }),
  878. // 上传反馈图片
  879. uploadImage: (filePath) => {
  880. return new Promise((resolve, reject) => {
  881. uni.uploadFile({
  882. url: BASE_URL + '/feedback/upload',
  883. filePath: filePath,
  884. name: 'file',
  885. success: (res) => {
  886. try {
  887. const data = JSON.parse(res.data)
  888. if (data.code === 200 || data.code === 0 || data.success) {
  889. resolve(data.data)
  890. } else {
  891. reject(new Error(data.message || '上传失败'))
  892. }
  893. } catch (e) {
  894. reject(new Error('解析响应数据失败'))
  895. }
  896. },
  897. fail: (error) => {
  898. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  899. }
  900. })
  901. })
  902. }
  903. },
  904. // 积分商城相关
  905. pointsMall: {
  906. // 获取商品列表
  907. getProducts: (params) => request({
  908. url: '/points/products',
  909. method: 'GET',
  910. data: params
  911. }),
  912. // 获取推荐商品
  913. getRecommendProducts: (limit = 10) => request({
  914. url: `/points/products/recommend?limit=${limit}`,
  915. method: 'GET'
  916. }),
  917. // 获取商品详情
  918. getProductDetail: (id) => request({
  919. url: `/points/products/${id}`,
  920. method: 'GET'
  921. }),
  922. // 获取积分余额
  923. getBalance: (makerId) => request({
  924. url: `/points/balance?makerId=${makerId}`,
  925. method: 'GET'
  926. }),
  927. // 获取积分明细
  928. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  929. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  930. method: 'GET'
  931. }),
  932. // 获取积分规则
  933. getRules: () => request({
  934. url: '/points/rules',
  935. method: 'GET'
  936. }),
  937. // 兑换商品
  938. exchange: (data) => request({
  939. url: '/points/exchange',
  940. method: 'POST',
  941. data
  942. }),
  943. // 获取订单列表
  944. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  945. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  946. if (status !== undefined && status !== null) {
  947. url += `&status=${status}`
  948. }
  949. return request({ url, method: 'GET' })
  950. },
  951. // 获取订单详情
  952. getOrderDetail: (orderNo) => request({
  953. url: `/points/orders/${orderNo}`,
  954. method: 'GET'
  955. }),
  956. // 增加积分(签到等)
  957. addPoints: (makerId, ruleType, reason) => request({
  958. url: '/points/add',
  959. method: 'POST',
  960. data: { makerId, ruleType, reason }
  961. })
  962. },
  963. // 我的资源相关(通过网关访问8081服务)
  964. myResource: {
  965. // 获取资源列表
  966. getList: (matchmakerId, keyword, pageNum = 1, pageSize = 10) => {
  967. let url = `/my-resource/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  968. if (keyword) {
  969. url += `&keyword=${encodeURIComponent(keyword)}`
  970. }
  971. return request({ url })
  972. },
  973. // 搜索资源(按姓名或手机号)
  974. search: (matchmakerId, keyword, gender) => {
  975. let url = `/my-resource/search?matchmakerId=${matchmakerId}`
  976. if (keyword) {
  977. url += `&keyword=${encodeURIComponent(keyword)}`
  978. }
  979. if (gender) {
  980. url += `&gender=${gender}`
  981. }
  982. return request({ url })
  983. },
  984. // 获取资源下拉列表
  985. getDropdown: (matchmakerId, gender) => {
  986. let url = `/my-resource/dropdown?matchmakerId=${matchmakerId}`
  987. if (gender) {
  988. url += `&gender=${gender}`
  989. }
  990. return request({ url })
  991. },
  992. // 获取已注册用户的资源下拉列表(user_id不为空)
  993. getRegisteredDropdown: (matchmakerId, gender) => {
  994. let url = `/my-resource/registered-dropdown?matchmakerId=${matchmakerId}`
  995. if (gender) {
  996. url += `&gender=${gender}`
  997. }
  998. return request({ url })
  999. },
  1000. // 搜索已注册用户的资源(user_id不为空)
  1001. searchRegistered: (matchmakerId, keyword, gender) => {
  1002. let url = `/my-resource/registered-search?matchmakerId=${matchmakerId}`
  1003. if (keyword) {
  1004. url += `&keyword=${encodeURIComponent(keyword)}`
  1005. }
  1006. if (gender) {
  1007. url += `&gender=${gender}`
  1008. }
  1009. return request({ url })
  1010. }
  1011. },
  1012. // 撮合成功案例上传相关(通过网关访问1004服务)
  1013. successCaseUpload: {
  1014. // 提交成功案例
  1015. submit: (data) => request({
  1016. url: '/success-case-upload/submit',
  1017. method: 'POST',
  1018. data
  1019. }),
  1020. // 获取成功案例列表
  1021. getList: (matchmakerId, pageNum = 1, pageSize = 10) => request({
  1022. url: `/success-case-upload/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  1023. }),
  1024. // 获取审核记录列表
  1025. getAuditRecords: (matchmakerId, auditStatus, pageNum = 1, pageSize = 20) => {
  1026. let url = `/success-case-upload/audit-records?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  1027. if (auditStatus !== null && auditStatus !== undefined) {
  1028. url += `&auditStatus=${auditStatus}`
  1029. }
  1030. return request({ url })
  1031. },
  1032. // 获取审核记录详情
  1033. getAuditRecordDetail: (id) => request({
  1034. url: `/success-case-upload/audit-records/${id}`
  1035. }),
  1036. // 标记审核记录为已读
  1037. markAsRead: (id) => request({
  1038. url: `/success-case-upload/audit-records/${id}/read`,
  1039. method: 'POST'
  1040. }),
  1041. // 获取未读审核记录数量
  1042. getUnreadCount: (matchmakerId) => request({
  1043. url: `/success-case-upload/audit-records/unread-count?matchmakerId=${matchmakerId}`
  1044. })
  1045. }
  1046. }
  1047. // 导出 request 函数供其他模块使用
  1048. export { request }