api.js 23 KB

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