api.js 32 KB

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