api.js 25 KB

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