api.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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, currentUserId) => request({
  116. url: `/user/info?userId=${userId}${currentUserId ? `&currentUserId=${currentUserId}` : ''}`
  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. getBrowseHistory: (userId, pageNum = 1, pageSize = 20) => request({
  137. url: `/user/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  138. }),
  139. // 清空用户的所有浏览记录
  140. clearBrowseHistory: (userId) => request({
  141. url: `/user/browse-history?userId=${userId}`,
  142. method: 'DELETE'
  143. }),
  144. // 删除用户对某个特定用户的浏览记录
  145. deleteBrowseHistory: (userId, visitedUserId) => request({
  146. url: `/user/browse-history/one?userId=${userId}&visitedUserId=${visitedUserId}`,
  147. method: 'DELETE'
  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. checkinList: (makerId, year, month) => request({
  454. url: `/matchmaker/checkin/list?makerId=${makerId}&year=${year}&month=${month}`
  455. })
  456. },
  457. // 推荐相关
  458. recommend: {
  459. // 获取推荐用户列表(网关转发到推荐服务)
  460. getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
  461. let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
  462. if (excludeIds) {
  463. url += `&excludeIds=${excludeIds}`;
  464. }
  465. return request({ url });
  466. },
  467. // 行为反馈:like/dislike
  468. feedback: ({ userId, targetUserId, type }) => request({
  469. url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
  470. }),
  471. // 曝光上报
  472. exposure: ({ userId, shownUserIds }) => request({
  473. url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
  474. }),
  475. // 规则检索
  476. search: (query) => request({
  477. url: '/recommend/search',
  478. method: 'POST',
  479. data: query
  480. }),
  481. // 获取今日推荐
  482. getTodayRecommend: () => request({
  483. url: '/recommend/today'
  484. }),
  485. // 获取用户喜欢的列表
  486. getLikedUsers: (userId, limit, offset) => request({
  487. url: `/recommend/liked-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  488. }),
  489. // 获取用户喜欢的用户数量
  490. getLikedUsersCount: (userId) => request({
  491. url: `/recommend/liked-users-count?userId=${userId}`
  492. }),
  493. // 获取喜欢我的用户列表
  494. getLikedMeUsers: (userId, limit, offset) => request({
  495. url: `/recommend/liked-me-users?userId=${userId}${limit ? `&limit=${limit}` : ''}${offset ? `&offset=${offset}` : ''}`
  496. }),
  497. // 获取喜欢我的用户数量
  498. getLikedMeUsersCount: (userId) => request({
  499. url: `/recommend/liked-me-users-count?userId=${userId}`
  500. })
  501. },
  502. // 消息相关
  503. message: {
  504. // 获取消息列表
  505. getList: (params) => request({
  506. url: '/message/list',
  507. data: params
  508. }),
  509. // 获取会话列表
  510. getConversations: () => request({
  511. url: '/message/conversations'
  512. }),
  513. // 发送消息
  514. send: (data) => request({
  515. url: '/message/send',
  516. method: 'POST',
  517. data
  518. }),
  519. // ===== 系统消息 =====
  520. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  521. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  522. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  523. return res.data || res
  524. },
  525. getSystemUnreadCount: async (userId) => {
  526. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  527. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  528. },
  529. markSystemRead: (id) => request({
  530. url: `/message/system/read/${id}`,
  531. method: 'POST'
  532. }),
  533. getSystemDetail: async (id) => {
  534. const res = await request({ url: `/message/system/detail/${id}` })
  535. return res.data || res
  536. },
  537. markAllSystemRead: (userId) => request({
  538. url: `/message/system/read-all?userId=${userId}`,
  539. method: 'POST'
  540. })
  541. },
  542. // 动态相关
  543. dynamic: {
  544. // 获取推荐动态列表(广场)
  545. getRecommendList: (params) => request({
  546. url: '/dynamic/recommend',
  547. data: params
  548. }),
  549. // 获取动态列表
  550. getList: (params) => request({
  551. url: '/dynamic/list',
  552. data: params
  553. }),
  554. // 获取动态详情
  555. getDetail: (dynamicId, userId) => request({
  556. url: `/dynamic/detail/${dynamicId}`,
  557. data: { userId }
  558. }),
  559. // 发表评论
  560. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  561. url: `/dynamic/comment`,
  562. method: 'POST',
  563. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  564. header: { 'Content-Type': 'application/json' }
  565. }),
  566. // 评论列表
  567. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  568. url: `/dynamic/comment/list/${dynamicId}`,
  569. data: { pageNum, pageSize }
  570. }),
  571. // 评论点赞/取消
  572. likeComment: (commentId, userId) => {
  573. // 如果没有传入userId,从本地存储获取
  574. if (!userId) {
  575. const userInfo = uni.getStorageSync('userInfo');
  576. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  577. }
  578. if (!userId) {
  579. return Promise.reject(new Error('用户未登录'));
  580. }
  581. return request({
  582. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  583. method: 'POST'
  584. });
  585. },
  586. unlikeComment: (commentId, userId) => {
  587. // 如果没有传入userId,从本地存储获取
  588. if (!userId) {
  589. const userInfo = uni.getStorageSync('userInfo');
  590. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  591. }
  592. if (!userId) {
  593. return Promise.reject(new Error('用户未登录'));
  594. }
  595. return request({
  596. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  597. method: 'DELETE'
  598. });
  599. },
  600. // 获取用户动态列表
  601. getUserDynamics: (userId, params) => {
  602. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  603. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  604. if (currentUserId) {
  605. url += `&currentUserId=${currentUserId}`
  606. }
  607. return request({
  608. url: url,
  609. method: 'GET'
  610. })
  611. },
  612. // 点赞动态
  613. like: (dynamicId, userId) => {
  614. // 如果没有传入userId,从本地存储获取
  615. if (!userId) {
  616. const userInfo = uni.getStorageSync('userInfo');
  617. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  618. }
  619. if (!userId) {
  620. return Promise.reject(new Error('用户未登录'));
  621. }
  622. return request({
  623. url: `/dynamic/like?dynamicId=${dynamicId}&userId=${userId}`,
  624. method: 'POST'
  625. });
  626. },
  627. // 取消点赞
  628. unlike: (dynamicId, userId) => {
  629. // 如果没有传入userId,从本地存储获取
  630. if (!userId) {
  631. const userInfo = uni.getStorageSync('userInfo');
  632. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  633. }
  634. if (!userId) {
  635. return Promise.reject(new Error('用户未登录'));
  636. }
  637. return request({
  638. url: `/dynamic/like/${dynamicId}?userId=${userId}`,
  639. method: 'DELETE'
  640. });
  641. },
  642. // 收藏动态
  643. favorite: (dynamicId, userId) => {
  644. // 如果没有传入userId,从本地存储获取
  645. if (!userId) {
  646. const userInfo = uni.getStorageSync('userInfo');
  647. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  648. }
  649. if (!userId) {
  650. return Promise.reject(new Error('用户未登录'));
  651. }
  652. return request({
  653. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  654. method: 'POST'
  655. });
  656. },
  657. // 取消收藏
  658. unfavorite: (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/favorite/${dynamicId}?userId=${userId}`,
  669. method: 'DELETE'
  670. });
  671. },
  672. // 创建个人动态
  673. createUserDynamic: (payload) => request({
  674. url: '/dynamic/user',
  675. method: 'POST',
  676. data: payload,
  677. header: { 'Content-Type': 'application/json' }
  678. }),
  679. // 更新个人动态
  680. updateUserDynamic: (dynamicId, userId, payload) => request({
  681. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  682. method: 'PUT',
  683. data: payload,
  684. header: { 'Content-Type': 'application/json' }
  685. }),
  686. // 删除个人动态
  687. deleteUserDynamic: (dynamicId, userId) => request({
  688. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  689. method: 'DELETE'
  690. }),
  691. // 删除动态(旧接口,保留兼容)
  692. delete: (dynamicId) => request({
  693. url: `/dynamic/${dynamicId}`,
  694. method: 'DELETE'
  695. }),
  696. // 发布动态(文本或已存在的媒体URL列表)
  697. publish: (payload) => request({
  698. url: '/dynamic/publish',
  699. method: 'POST',
  700. data: payload,
  701. header: { 'Content-Type': 'application/json' }
  702. }),
  703. // 单个文件上传方法
  704. uploadSingle: (filePath) => {
  705. return new Promise((resolve, reject) => {
  706. uni.uploadFile({
  707. url: BASE_URL + '/dynamic/publish/upload',
  708. filePath: filePath,
  709. name: 'file',
  710. success: (res) => {
  711. try {
  712. const data = JSON.parse(res.data)
  713. if (data.code === 200 || data.code === 0 || data.success) {
  714. resolve(data.data)
  715. } else {
  716. console.error('上传失败,服务器返回错误:', data)
  717. reject(new Error(data.message || '上传失败'))
  718. }
  719. } catch (e) {
  720. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  721. reject(new Error('解析响应数据失败'))
  722. }
  723. },
  724. fail: (error) => {
  725. console.error('上传请求失败:', error)
  726. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  727. }
  728. })
  729. })
  730. },
  731. // 批量上传多个文件(遍历调用单个上传)
  732. uploadBatch: (filePaths) => {
  733. return new Promise(async (resolve, reject) => {
  734. const urls = []
  735. try {
  736. for (let filePath of filePaths) {
  737. const url = await new Promise((resolveUpload, rejectUpload) => {
  738. uni.uploadFile({
  739. url: BASE_URL + '/dynamic/publish/upload',
  740. filePath: filePath,
  741. name: 'file',
  742. success: (res) => {
  743. try {
  744. const data = JSON.parse(res.data)
  745. if (data.code === 200 || data.code === 0 || data.success) {
  746. resolveUpload(data.data)
  747. } else {
  748. rejectUpload(data)
  749. }
  750. } catch (e) {
  751. rejectUpload(e)
  752. }
  753. },
  754. fail: rejectUpload
  755. })
  756. })
  757. urls.push(url)
  758. }
  759. resolve(urls)
  760. } catch (e) {
  761. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  762. }
  763. })
  764. },
  765. // 提交举报
  766. submitReport: (data) => request({
  767. url: '/dynamic/report',
  768. method: 'POST',
  769. data
  770. }),
  771. // 获取用户收藏列表
  772. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  773. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  774. }),
  775. // 获取用户点赞列表
  776. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  777. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  778. }),
  779. // 获取用户浏览记录列表
  780. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  781. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  782. }),
  783. // 清空用户浏览记录
  784. clearBrowseHistory: (userId) => request({
  785. url: `/dynamic/browse-history?userId=${userId}`,
  786. method: 'DELETE'
  787. })
  788. },
  789. // VIP相关
  790. vip: {
  791. // 获取VIP信息(状态、套餐等)
  792. getInfo: (userId) => request({
  793. url: `/vip/info?userId=${userId}`
  794. }),
  795. // 获取VIP套餐列表
  796. getPackages: () => request({
  797. url: '/vip/packages'
  798. }),
  799. // 购买VIP套餐(获取支付参数)
  800. purchase: (userId, packageId) => request({
  801. url: '/vip/purchase',
  802. method: 'POST',
  803. data: { userId, packageId }
  804. }),
  805. // 查询订单状态
  806. getOrderStatus: (orderNo) => request({
  807. url: `/vip/order/status?orderNo=${orderNo}`
  808. }),
  809. // 新增:查询支付状态(userId + packageId)
  810. checkPayStatus: (userId, packageId) => request({
  811. url: '/vip/checkPayStatus',
  812. method: 'GET',
  813. data: { userId, packageId }
  814. })
  815. },
  816. // 用户反馈
  817. feedback: {
  818. // 提交用户反馈
  819. submit: (data) => request({
  820. url: '/feedback/submit',
  821. method: 'POST',
  822. data
  823. }),
  824. // 上传反馈图片
  825. uploadImage: (filePath) => {
  826. return new Promise((resolve, reject) => {
  827. uni.uploadFile({
  828. url: BASE_URL + '/feedback/upload',
  829. filePath: filePath,
  830. name: 'file',
  831. success: (res) => {
  832. try {
  833. const data = JSON.parse(res.data)
  834. if (data.code === 200 || data.code === 0 || data.success) {
  835. resolve(data.data)
  836. } else {
  837. reject(new Error(data.message || '上传失败'))
  838. }
  839. } catch (e) {
  840. reject(new Error('解析响应数据失败'))
  841. }
  842. },
  843. fail: (error) => {
  844. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  845. }
  846. })
  847. })
  848. }
  849. },
  850. // 积分商城相关
  851. pointsMall: {
  852. // 获取商品列表
  853. getProducts: (params) => request({
  854. url: '/points/products',
  855. method: 'GET',
  856. data: params
  857. }),
  858. // 获取推荐商品
  859. getRecommendProducts: (limit = 10) => request({
  860. url: `/points/products/recommend?limit=${limit}`,
  861. method: 'GET'
  862. }),
  863. // 获取商品详情
  864. getProductDetail: (id) => request({
  865. url: `/points/products/${id}`,
  866. method: 'GET'
  867. }),
  868. // 获取积分余额
  869. getBalance: (makerId) => request({
  870. url: `/points/balance?makerId=${makerId}`,
  871. method: 'GET'
  872. }),
  873. // 获取积分明细
  874. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  875. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  876. method: 'GET'
  877. }),
  878. // 获取积分规则
  879. getRules: () => request({
  880. url: '/points/rules',
  881. method: 'GET'
  882. }),
  883. // 兑换商品
  884. exchange: (data) => request({
  885. url: '/points/exchange',
  886. method: 'POST',
  887. data
  888. }),
  889. // 获取订单列表
  890. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  891. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  892. if (status !== undefined && status !== null) {
  893. url += `&status=${status}`
  894. }
  895. return request({ url, method: 'GET' })
  896. },
  897. // 获取订单详情
  898. getOrderDetail: (orderNo) => request({
  899. url: `/points/orders/${orderNo}`,
  900. method: 'GET'
  901. }),
  902. // 增加积分(签到等)
  903. addPoints: (makerId, ruleType, reason) => request({
  904. url: '/points/add',
  905. method: 'POST',
  906. data: { makerId, ruleType, reason }
  907. })
  908. },
  909. // 我的资源相关(通过网关访问8081服务)
  910. myResource: {
  911. // 获取资源列表
  912. getList: (matchmakerId, keyword, pageNum = 1, pageSize = 10) => {
  913. let url = `/my-resource/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  914. if (keyword) {
  915. url += `&keyword=${encodeURIComponent(keyword)}`
  916. }
  917. return request({ url })
  918. },
  919. // 搜索资源(按姓名或手机号)
  920. search: (matchmakerId, keyword, gender) => {
  921. let url = `/my-resource/search?matchmakerId=${matchmakerId}`
  922. if (keyword) {
  923. url += `&keyword=${encodeURIComponent(keyword)}`
  924. }
  925. if (gender) {
  926. url += `&gender=${gender}`
  927. }
  928. return request({ url })
  929. },
  930. // 获取资源下拉列表
  931. getDropdown: (matchmakerId, gender) => {
  932. let url = `/my-resource/dropdown?matchmakerId=${matchmakerId}`
  933. if (gender) {
  934. url += `&gender=${gender}`
  935. }
  936. return request({ url })
  937. },
  938. // 获取已注册用户的资源下拉列表(user_id不为空)
  939. getRegisteredDropdown: (matchmakerId, gender) => {
  940. let url = `/my-resource/registered-dropdown?matchmakerId=${matchmakerId}`
  941. if (gender) {
  942. url += `&gender=${gender}`
  943. }
  944. return request({ url })
  945. },
  946. // 搜索已注册用户的资源(user_id不为空)
  947. searchRegistered: (matchmakerId, keyword, gender) => {
  948. let url = `/my-resource/registered-search?matchmakerId=${matchmakerId}`
  949. if (keyword) {
  950. url += `&keyword=${encodeURIComponent(keyword)}`
  951. }
  952. if (gender) {
  953. url += `&gender=${gender}`
  954. }
  955. return request({ url })
  956. }
  957. },
  958. // 撮合成功案例上传相关(通过网关访问1004服务)
  959. successCaseUpload: {
  960. // 提交成功案例
  961. submit: (data) => request({
  962. url: '/success-case-upload/submit',
  963. method: 'POST',
  964. data
  965. }),
  966. // 获取成功案例列表
  967. getList: (matchmakerId, pageNum = 1, pageSize = 10) => request({
  968. url: `/success-case-upload/list?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  969. }),
  970. // 获取审核记录列表
  971. getAuditRecords: (matchmakerId, auditStatus, pageNum = 1, pageSize = 20) => {
  972. let url = `/success-case-upload/audit-records?matchmakerId=${matchmakerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  973. if (auditStatus !== null && auditStatus !== undefined) {
  974. url += `&auditStatus=${auditStatus}`
  975. }
  976. return request({ url })
  977. },
  978. // 获取审核记录详情
  979. getAuditRecordDetail: (id) => request({
  980. url: `/success-case-upload/audit-records/${id}`
  981. }),
  982. // 标记审核记录为已读
  983. markAsRead: (id) => request({
  984. url: `/success-case-upload/audit-records/${id}/read`,
  985. method: 'POST'
  986. }),
  987. // 获取未读审核记录数量
  988. getUnreadCount: (matchmakerId) => request({
  989. url: `/success-case-upload/audit-records/unread-count?matchmakerId=${matchmakerId}`
  990. })
  991. }
  992. }
  993. // 导出 request 函数供其他模块使用
  994. export { request }