api.js 25 KB

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