api.js 33 KB

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