api.js 32 KB

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