api.js 4.8 KB

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