api.js 31 KB

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