api.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. // 课程订单相关(微信支付)
  263. courseOrder: {
  264. // 购买课程(获取微信支付参数)
  265. purchase: (data) => request({
  266. url: '/course-order/purchase',
  267. method: 'POST',
  268. data
  269. }),
  270. // 检查是否已购买课程
  271. checkPurchased: (userId, courseId) => request({
  272. url: `/course-order/check?userId=${userId}&courseId=${courseId}`,
  273. method: 'GET'
  274. }),
  275. // 获取已购买的课程列表
  276. getPurchasedCourses: (userId) => request({
  277. url: `/course-order/purchased?userId=${userId}`,
  278. method: 'GET'
  279. })
  280. },
  281. // 红娘相关
  282. matchmaker: {
  283. // 获取红娘列表
  284. getList: (params) => request({
  285. url: '/matchmaker/list',
  286. method: 'POST',
  287. data: params
  288. }),
  289. // 获取全职红娘列表
  290. getFormalList: (pageNum, pageSize) => request({
  291. url: `/matchmaker/formal?pageNum=${pageNum}&pageSize=${pageSize}`
  292. }),
  293. // 获取红娘详情
  294. getDetail: (id) => request({
  295. url: `/matchmaker/detail/${id}`
  296. }),
  297. // 根据userId查询红娘信息
  298. getByUserId: (userId) => request({
  299. url: `/matchmaker/by-user/${userId}`
  300. }),
  301. // 预约红娘
  302. book: (matchmakerId, data) => request({
  303. url: `/matchmaker/book/${matchmakerId}`,
  304. method: 'POST',
  305. data
  306. }),
  307. // 提交红娘申请
  308. submitApply: (data) => request({
  309. url: '/matchmaker-apply/submit',
  310. method: 'POST',
  311. data
  312. }),
  313. // 工作台相关
  314. getWorkbenchData: () => request({ url: '/matchmaker/workbench/data' }),
  315. // 获取我的资源
  316. getMyResources: (params) => request({
  317. url: '/matchmaker/resources',
  318. method: 'GET',
  319. data: params
  320. }),
  321. // 获取排行榜数据(总排行榜)
  322. getRankingData: (params) => request({
  323. url: '/matchmaker/ranking',
  324. method: 'GET',
  325. data: params
  326. }),
  327. // 获取本周排行榜(按点赞数和成功人数平均数排名)
  328. getWeeklyRanking: (params) => request({
  329. url: '/matchmaker/weekly-ranking',
  330. method: 'GET',
  331. data: params
  332. }),
  333. // 给红娘点赞(一周只能给同一红娘点赞一次)
  334. likeMatchmaker: (userId, matchmakerId) => request({
  335. url: `/matchmaker/like?userId=${userId}&matchmakerId=${matchmakerId}`,
  336. method: 'POST'
  337. }),
  338. // 检查是否已点赞
  339. checkLikeStatus: (userId, matchmakerId) => request({
  340. url: `/matchmaker/check-like?userId=${userId}&matchmakerId=${matchmakerId}`,
  341. method: 'GET'
  342. }),
  343. // 签到相关
  344. checkinStatus: (makerId) => request({
  345. url: `/matchmaker/checkin/status?makerId=${makerId}`
  346. }),
  347. checkinStats: (makerId) => request({
  348. url: `/matchmaker/checkin/stats?makerId=${makerId}`
  349. }),
  350. doCheckin: (makerId) => request({
  351. url: `/matchmaker/checkin/do?makerId=${makerId}`,
  352. method: 'POST'
  353. }),
  354. // 更新红娘资料(编辑资料页使用)
  355. updateProfile: (matchmakerId, data) => request({
  356. url: `/matchmaker/update/${matchmakerId}`,
  357. method: 'PUT',
  358. data
  359. }),
  360. // 获取本月签到记录
  361. checkinList: (makerId, year, month) => request({
  362. url: `/matchmaker/checkin/list?makerId=${makerId}&year=${year}&month=${month}`
  363. })
  364. },
  365. // 推荐相关
  366. recommend: {
  367. // 获取推荐用户列表(网关转发到推荐服务)
  368. getUsers: ({ userId, oppoOnly = 1, limit = 20, excludeIds }) => {
  369. let url = `/recommend/users?userId=${userId}&oppoOnly=${oppoOnly}&limit=${limit}`;
  370. if (excludeIds) {
  371. url += `&excludeIds=${excludeIds}`;
  372. }
  373. return request({ url });
  374. },
  375. // 行为反馈:like/dislike
  376. feedback: ({ userId, targetUserId, type }) => request({
  377. url: `/recommend/feedback?userId=${userId}&targetUserId=${targetUserId}&type=${type}`
  378. }),
  379. // 曝光上报
  380. exposure: ({ userId, shownUserIds }) => request({
  381. url: `/recommend/exposure?userId=${userId}&shownUserIds=${encodeURIComponent(shownUserIds)}`
  382. }),
  383. // 规则检索
  384. search: (query) => request({
  385. url: '/recommend/search',
  386. method: 'POST',
  387. data: query
  388. }),
  389. // 获取今日推荐
  390. getTodayRecommend: () => request({
  391. url: '/recommend/today'
  392. })
  393. },
  394. // 消息相关
  395. message: {
  396. // 获取消息列表
  397. getList: (params) => request({
  398. url: '/message/list',
  399. data: params
  400. }),
  401. // 获取会话列表
  402. getConversations: () => request({
  403. url: '/message/conversations'
  404. }),
  405. // 发送消息
  406. send: (data) => request({
  407. url: '/message/send',
  408. method: 'POST',
  409. data
  410. }),
  411. // ===== 系统消息 =====
  412. getSystemList: async (userId, pageNum = 1, pageSize = 20) => {
  413. const res = await request({ url: `/message/system/list?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}` })
  414. // 后端Result包装:{ code, data:{ list,total,page,pageSize } }
  415. return res.data || res
  416. },
  417. getSystemUnreadCount: async (userId) => {
  418. const res = await request({ url: `/message/system/unread-count?userId=${userId}` })
  419. return (typeof res.data === 'number') ? res.data : (res.data?.count || 0)
  420. },
  421. markSystemRead: (id) => request({
  422. url: `/message/system/read/${id}`,
  423. method: 'POST'
  424. }),
  425. getSystemDetail: async (id) => {
  426. const res = await request({ url: `/message/system/detail/${id}` })
  427. return res.data || res
  428. },
  429. markAllSystemRead: (userId) => request({
  430. url: `/message/system/read-all?userId=${userId}`,
  431. method: 'POST'
  432. })
  433. },
  434. // 动态相关
  435. dynamic: {
  436. // 获取推荐动态列表(广场)
  437. getRecommendList: (params) => request({
  438. url: '/dynamic/recommend',
  439. data: params
  440. }),
  441. // 获取动态列表
  442. getList: (params) => request({
  443. url: '/dynamic/list',
  444. data: params
  445. }),
  446. // 获取动态详情
  447. getDetail: (dynamicId, userId) => request({
  448. url: `/dynamic/detail/${dynamicId}`,
  449. data: { userId }
  450. }),
  451. // 发表评论
  452. addComment: (dynamicId, content, images, parentCommentId = 0) => request({
  453. url: `/dynamic/comment`,
  454. method: 'POST',
  455. data: { dynamicId, content, images, parentCommentId, userId: 1 },
  456. header: { 'Content-Type': 'application/json' }
  457. }),
  458. // 评论列表
  459. getComments: (dynamicId, pageNum = 1, pageSize = 10) => request({
  460. url: `/dynamic/comment/list/${dynamicId}`,
  461. data: { pageNum, pageSize }
  462. }),
  463. // 评论点赞/取消
  464. likeComment: (commentId, userId) => {
  465. // 如果没有传入userId,从本地存储获取
  466. if (!userId) {
  467. const userInfo = uni.getStorageSync('userInfo');
  468. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  469. }
  470. if (!userId) {
  471. return Promise.reject(new Error('用户未登录'));
  472. }
  473. return request({
  474. url: `/dynamic/comment/like?commentId=${commentId}&userId=${userId}`,
  475. method: 'POST'
  476. });
  477. },
  478. unlikeComment: (commentId, userId) => {
  479. // 如果没有传入userId,从本地存储获取
  480. if (!userId) {
  481. const userInfo = uni.getStorageSync('userInfo');
  482. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  483. }
  484. if (!userId) {
  485. return Promise.reject(new Error('用户未登录'));
  486. }
  487. return request({
  488. url: `/dynamic/comment/like/${commentId}?userId=${userId}`,
  489. method: 'DELETE'
  490. });
  491. },
  492. // 获取用户动态列表
  493. getUserDynamics: (userId, params) => {
  494. const { pageNum = 1, pageSize = 10, currentUserId = null } = params || {}
  495. let url = `/dynamic/user/${userId}?pageNum=${pageNum}&pageSize=${pageSize}`
  496. if (currentUserId) {
  497. url += `&currentUserId=${currentUserId}`
  498. }
  499. return request({
  500. url: url,
  501. method: 'GET'
  502. })
  503. },
  504. // 点赞动态
  505. like: (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/like?dynamicId=${dynamicId}&userId=${userId}`,
  516. method: 'POST'
  517. });
  518. },
  519. // 取消点赞
  520. unlike: (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/like/${dynamicId}?userId=${userId}`,
  531. method: 'DELETE'
  532. });
  533. },
  534. // 收藏动态
  535. favorite: (dynamicId, userId) => {
  536. // 如果没有传入userId,从本地存储获取
  537. if (!userId) {
  538. const userInfo = uni.getStorageSync('userInfo');
  539. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  540. }
  541. if (!userId) {
  542. return Promise.reject(new Error('用户未登录'));
  543. }
  544. return request({
  545. url: `/dynamic/favorite?dynamicId=${dynamicId}&userId=${userId}`,
  546. method: 'POST'
  547. });
  548. },
  549. // 取消收藏
  550. unfavorite: (dynamicId, userId) => {
  551. // 如果没有传入userId,从本地存储获取
  552. if (!userId) {
  553. const userInfo = uni.getStorageSync('userInfo');
  554. userId = userInfo ? (userInfo.userId || userInfo.id) : null;
  555. }
  556. if (!userId) {
  557. return Promise.reject(new Error('用户未登录'));
  558. }
  559. return request({
  560. url: `/dynamic/favorite/${dynamicId}?userId=${userId}`,
  561. method: 'DELETE'
  562. });
  563. },
  564. // 创建个人动态
  565. createUserDynamic: (payload) => request({
  566. url: '/dynamic/user',
  567. method: 'POST',
  568. data: payload,
  569. header: { 'Content-Type': 'application/json' }
  570. }),
  571. // 更新个人动态
  572. updateUserDynamic: (dynamicId, userId, payload) => request({
  573. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  574. method: 'PUT',
  575. data: payload,
  576. header: { 'Content-Type': 'application/json' }
  577. }),
  578. // 删除个人动态
  579. deleteUserDynamic: (dynamicId, userId) => request({
  580. url: `/dynamic/user/${dynamicId}?userId=${userId}`,
  581. method: 'DELETE'
  582. }),
  583. // 删除动态(旧接口,保留兼容)
  584. delete: (dynamicId) => request({
  585. url: `/dynamic/${dynamicId}`,
  586. method: 'DELETE'
  587. }),
  588. // 发布动态(文本或已存在的媒体URL列表)
  589. publish: (payload) => request({
  590. url: '/dynamic/publish',
  591. method: 'POST',
  592. data: payload,
  593. header: { 'Content-Type': 'application/json' }
  594. }),
  595. // 单个文件上传方法
  596. uploadSingle: (filePath) => {
  597. return new Promise((resolve, reject) => {
  598. console.log('开始上传文件:', filePath)
  599. console.log('上传URL:', BASE_URL + '/dynamic/publish/upload')
  600. uni.uploadFile({
  601. url: BASE_URL + '/dynamic/publish/upload',
  602. filePath: filePath,
  603. name: 'file',
  604. success: (res) => {
  605. console.log('上传响应:', res)
  606. try {
  607. const data = JSON.parse(res.data)
  608. console.log('解析后的响应数据:', data)
  609. if (data.code === 200 || data.code === 0 || data.success) {
  610. console.log('上传成功,返回URL:', data.data)
  611. resolve(data.data)
  612. } else {
  613. console.error('上传失败,服务器返回错误:', data)
  614. reject(new Error(data.message || '上传失败'))
  615. }
  616. } catch (e) {
  617. console.error('解析响应数据失败:', e, '原始响应:', res.data)
  618. reject(new Error('解析响应数据失败'))
  619. }
  620. },
  621. fail: (error) => {
  622. console.error('上传请求失败:', error)
  623. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  624. }
  625. })
  626. })
  627. },
  628. // 批量上传多个文件(遍历调用单个上传)
  629. uploadBatch: (filePaths) => {
  630. return new Promise(async (resolve, reject) => {
  631. const urls = []
  632. try {
  633. for (let filePath of filePaths) {
  634. const url = await new Promise((resolveUpload, rejectUpload) => {
  635. uni.uploadFile({
  636. url: BASE_URL + '/dynamic/publish/upload',
  637. filePath: filePath,
  638. name: 'file',
  639. success: (res) => {
  640. try {
  641. const data = JSON.parse(res.data)
  642. if (data.code === 200 || data.code === 0 || data.success) {
  643. resolveUpload(data.data)
  644. } else {
  645. rejectUpload(data)
  646. }
  647. } catch (e) {
  648. rejectUpload(e)
  649. }
  650. },
  651. fail: rejectUpload
  652. })
  653. })
  654. urls.push(url)
  655. }
  656. resolve(urls)
  657. } catch (e) {
  658. reject(new Error(`批量上传失败: ${e.message || '未知错误'}`))
  659. }
  660. })
  661. },
  662. // 提交举报
  663. submitReport: (data) => request({
  664. url: '/dynamic/report',
  665. method: 'POST',
  666. data
  667. }),
  668. // 获取用户收藏列表
  669. getFavoritesList: (userId, pageNum = 1, pageSize = 10) => request({
  670. url: `/dynamic/favorites?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  671. }),
  672. // 获取用户点赞列表
  673. getLikedList: (userId, pageNum = 1, pageSize = 10) => request({
  674. url: `/dynamic/likes?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  675. }),
  676. // 获取用户浏览记录列表
  677. getBrowseHistoryList: (userId, pageNum = 1, pageSize = 10) => request({
  678. url: `/dynamic/browse-history?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`
  679. }),
  680. // 清空用户浏览记录
  681. clearBrowseHistory: (userId) => request({
  682. url: `/dynamic/browse-history?userId=${userId}`,
  683. method: 'DELETE'
  684. })
  685. },
  686. // VIP相关
  687. vip: {
  688. // 获取VIP信息(状态、套餐等)
  689. getInfo: (userId) => request({
  690. url: `/vip/info?userId=${userId}`
  691. }),
  692. // 获取VIP套餐列表
  693. getPackages: () => request({
  694. url: '/vip/packages'
  695. }),
  696. // 购买VIP套餐(获取支付参数)
  697. purchase: (userId, packageId) => request({
  698. url: '/vip/purchase',
  699. method: 'POST',
  700. data: { userId, packageId }
  701. }),
  702. // 查询订单状态
  703. getOrderStatus: (orderNo) => request({
  704. url: `/vip/order/status?orderNo=${orderNo}`
  705. }),
  706. // 新增:查询支付状态(userId + packageId)
  707. checkPayStatus: (userId, packageId) => request({
  708. url: '/vip/checkPayStatus',
  709. method: 'GET',
  710. data: { userId, packageId }
  711. })
  712. },
  713. // 用户反馈
  714. feedback: {
  715. // 提交用户反馈
  716. submit: (data) => request({
  717. url: '/feedback/submit',
  718. method: 'POST',
  719. data
  720. }),
  721. // 上传反馈图片
  722. uploadImage: (filePath) => {
  723. return new Promise((resolve, reject) => {
  724. uni.uploadFile({
  725. url: BASE_URL + '/feedback/upload',
  726. filePath: filePath,
  727. name: 'file',
  728. success: (res) => {
  729. try {
  730. const data = JSON.parse(res.data)
  731. if (data.code === 200 || data.code === 0 || data.success) {
  732. resolve(data.data)
  733. } else {
  734. reject(new Error(data.message || '上传失败'))
  735. }
  736. } catch (e) {
  737. reject(new Error('解析响应数据失败'))
  738. }
  739. },
  740. fail: (error) => {
  741. reject(new Error('上传请求失败: ' + (error.errMsg || '未知错误')))
  742. }
  743. })
  744. })
  745. }
  746. },
  747. // 积分商城相关
  748. pointsMall: {
  749. // 获取商品列表
  750. getProducts: (params) => request({
  751. url: '/points/products',
  752. method: 'GET',
  753. data: params
  754. }),
  755. // 获取推荐商品
  756. getRecommendProducts: (limit = 10) => request({
  757. url: `/points/products/recommend?limit=${limit}`,
  758. method: 'GET'
  759. }),
  760. // 获取商品详情
  761. getProductDetail: (id) => request({
  762. url: `/points/products/${id}`,
  763. method: 'GET'
  764. }),
  765. // 获取积分余额
  766. getBalance: (makerId) => request({
  767. url: `/points/balance?makerId=${makerId}`,
  768. method: 'GET'
  769. }),
  770. // 获取积分明细
  771. getRecords: (makerId, pageNum = 1, pageSize = 20) => request({
  772. url: `/points/records?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`,
  773. method: 'GET'
  774. }),
  775. // 获取积分规则
  776. getRules: () => request({
  777. url: '/points/rules',
  778. method: 'GET'
  779. }),
  780. // 兑换商品
  781. exchange: (data) => request({
  782. url: '/points/exchange',
  783. method: 'POST',
  784. data
  785. }),
  786. // 获取订单列表
  787. getOrders: (makerId, status, pageNum = 1, pageSize = 10) => {
  788. let url = `/points/orders?makerId=${makerId}&pageNum=${pageNum}&pageSize=${pageSize}`
  789. if (status !== undefined && status !== null) {
  790. url += `&status=${status}`
  791. }
  792. return request({ url, method: 'GET' })
  793. },
  794. // 获取订单详情
  795. getOrderDetail: (orderNo) => request({
  796. url: `/points/orders/${orderNo}`,
  797. method: 'GET'
  798. }),
  799. // 增加积分(签到等)
  800. addPoints: (makerId, ruleType, reason) => request({
  801. url: '/points/add',
  802. method: 'POST',
  803. data: { makerId, ruleType, reason }
  804. })
  805. }
  806. }
  807. // 导出 request 函数供其他模块使用
  808. export { request }