api.js 31 KB

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