api.js 31 KB

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