api.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import { requestAll, requestLogin, post, postWithCommonParams, uploadTrackLog } from '../utils/request'
  2. export const userLogin = (data) => requestLogin(data)
  3. // 获取token
  4. const getToken = () => {
  5. return wx.getStorageSync('accessToken') || ''
  6. }
  7. // 添加token到header
  8. const addTokenToHeader = () => {
  9. return {
  10. token: getToken()
  11. }
  12. }
  13. export const getBannerList = (channel) => {
  14. return requestAll('/novel/banner', {channel}, 'GET', addTokenToHeader())
  15. }
  16. export const getChapterList = (channel) => {
  17. return requestAll('/novel/chapter/list', {channel}, 'GET', addTokenToHeader())
  18. }
  19. // /novel/cardNovels
  20. export const getCardNovels = (channel) => {
  21. return requestAll('/novel/cardNovels', {channel}, 'GET', addTokenToHeader())
  22. }
  23. // /novel/cardNovelsMore
  24. export const getCardNovelsMore = (id) => {
  25. if (!id) {
  26. return Promise.reject(new Error('缺少必要参数: id'));
  27. }
  28. return requestAll('/novel/cardNovelsMore', {id}, 'GET', addTokenToHeader())
  29. }
  30. // /category/list
  31. export const getCategoryList = (category) => {
  32. if (!category) {
  33. return Promise.reject(new Error('缺少必要参数: category'));
  34. }
  35. return requestAll('/category/list', {category}, 'GET', addTokenToHeader())
  36. }
  37. // /novel/detail
  38. export const getNovelDetail = (id) => {
  39. if (!id) {
  40. return Promise.reject(new Error('缺少必要参数: id'));
  41. }
  42. return requestAll('/novel/detail', {id}, 'GET', addTokenToHeader())
  43. }
  44. // /novel/search
  45. export const getNovelSearch = ({
  46. keyword,
  47. page=1,
  48. size=10,
  49. category
  50. }) => {
  51. // 创建基本参数对象
  52. const params = { keyword, page, size };
  53. // 如果category有值,才添加到参数中
  54. if (category) {
  55. params.category = category;
  56. }
  57. return requestAll('/novel/search', params, 'GET', addTokenToHeader());
  58. }
  59. // /user/bookshelf 获取书架列表
  60. export const getBookshelfList = () => {
  61. return requestAll('/user/bookshelf', {}, 'GET', addTokenToHeader())
  62. }
  63. // /user/bookshelf 添加书架
  64. export const addBookshelf = (data) => {
  65. return requestAll('/user/bookshelf', data, 'POST', addTokenToHeader())
  66. }
  67. // /user/bookshelf 移除用户书架
  68. export const removeBookshelf = (data) => {
  69. return requestAll('/user/bookshelf', data, 'DELETE', addTokenToHeader())
  70. }
  71. // /user/chapter/unlock-status 获取章节解锁状态
  72. export const getChapterUnlockStatus = (data) => {
  73. return requestAll('/user/chapter/unlock-status-val', data, 'GET', addTokenToHeader())
  74. }
  75. // /user/browsing-history 新增用户阅读历史
  76. export const addBrowsingHistory = (data) => {
  77. return requestAll('/user/browsing-history', data, 'POST', addTokenToHeader())
  78. }
  79. // /user/chapter/unlock 解锁章节
  80. export const unlockChapter = (data) => {
  81. return requestAll('/user/chapter/unlock', data, 'POST', addTokenToHeader())
  82. }
  83. // 获取阅读记录
  84. export const getBrowsingHistory = () => {
  85. return requestAll('/user/browsing-history', {}, 'GET', addTokenToHeader())
  86. }
  87. // 获取短剧列表
  88. export function getVideoList(params = {}) {
  89. const { page = 1, size = 10, tag_id = 2245, filter_id = "", next_id = "" } = params;
  90. const requestData = {
  91. tag_id: tag_id,
  92. filter_id: filter_id,
  93. next_id: next_id,
  94. count: size,
  95. uuid: getApp().globalData.uuid, // 固定值,实际应用中可能需要动态生成
  96. gh_id: "gh_4e55f615d5dc" // 固定值
  97. };
  98. return postWithCommonParams("https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getvideolist", requestData)
  99. .then(data => {
  100. return data;
  101. // 处理返回数据的格式转换,确保与页面期望的数据结构一致
  102. if (data) {
  103. return data.map(video => ({
  104. id: video.id,
  105. title: video.title,
  106. cover: video.cover_image,
  107. playCount: video.views || '0'
  108. }));
  109. }
  110. return [];
  111. });
  112. }
  113. // 获取视频详情
  114. export function getVideoDetail(params = {}) {
  115. if (!params.id) {
  116. return Promise.reject(new Error('缺少必要参数: id'));
  117. }
  118. return postWithCommonParams('https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getvideoinfo', params);
  119. }
  120. // 获取真实视频播放地址
  121. export function getRealVideoUrl(id, tagId) {
  122. if (!id || !tagId) {
  123. return Promise.reject(new Error('缺少必要参数: id 或 tagId'));
  124. }
  125. const url = `https://applet.xiaoduer.cn/coral/cashvideo/getOasVideoUrl?id=${id}&tagId=${tagId}`;
  126. return postWithCommonParams(url, {}, 'GET');
  127. }
  128. // 获取相关视频列表
  129. export function getRelatedVideos(params = {}) {
  130. const { tag_id = 2250, count = 10, filter_id = "" } = params;
  131. const requestData = {
  132. tag_id,
  133. count,
  134. filter_id,
  135. uuid: getApp().globalData.uuid,
  136. gh_id: "gh_acc9a32b2122"
  137. };
  138. return post("https://applet.xiaoduer.cn/cashvideoapi/cashvideo/getrandvideolistpro", requestData);
  139. }
  140. /**
  141. * 获取 uuid
  142. */
  143. export function getUuid (body){
  144. return postWithCommonParams('https://applet.xiaoduer.cn/api/user/getuuid', body)
  145. }
  146. // https://applet.xiaoduer.cn/coral/template/config
  147. export function getTemplateConfig (body){
  148. return postWithCommonParams('https://applet.xiaoduer.cn/coral/template/config', body)
  149. }
  150. // 导出postWithCommonParams
  151. export { postWithCommonParams };
  152. /**
  153. * 打点
  154. */
  155. export const recordLog = (body) => uploadTrackLog('/track', body)