api.js 32 KB

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