api.js 28 KB

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