api.js 30 KB

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