APIRequest.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import {
  2. getInstance
  3. } from './httpRequest';
  4. import {
  5. apiUrl
  6. } from './const.js';
  7. //console.log(getInstance().url)
  8. const httpApiUrl = (str) => {
  9. return apiUrl + str;
  10. }
  11. class httpRequestApi {
  12. //课程表首页
  13. static getCourse(data) {
  14. const url = httpApiUrl('wx/course');
  15. return getInstance().header({
  16. uid: wx.getStorageSync('uid'),
  17. }).url(url).data(data).send();
  18. }
  19. //获取看nav切换
  20. static getCategory() {
  21. const url = httpApiUrl('wx/category');
  22. return getInstance().header({
  23. uid: wx.getStorageSync('uid'),
  24. }).url(url).send();
  25. }
  26. //获取推荐课程
  27. static getCategoryRecommend() {
  28. const url = httpApiUrl('wx/course/recommend/top');
  29. return getInstance().header({
  30. uid: wx.getStorageSync('uid'),
  31. }).url(url).send();
  32. }
  33. //获取课程详情
  34. static getCourseDetails(id) {
  35. const url = httpApiUrl(`wx/course/${id}`);
  36. return getInstance().header({
  37. uid: wx.getStorageSync('uid'),
  38. }).url(url).data().send();
  39. }
  40. //添加播放记录
  41. static addPlayLogList(data) {
  42. const url = httpApiUrl('wx/playLog');
  43. return getInstance().header({
  44. uid: wx.getStorageSync('uid'),
  45. }).url(url).data(data).method('POST').send();
  46. }
  47. //收藏或者取消
  48. static getDetailsFavorites(data) {
  49. const url = httpApiUrl('wx/favorites');
  50. return getInstance().header({
  51. uid: wx.getStorageSync('uid'),
  52. }).url(url).data(data).method('POST').send();
  53. }
  54. //获取收藏列表
  55. static getFavoritesList(data) {
  56. const url = httpApiUrl('wx/favorites');
  57. return getInstance().header({
  58. uid: wx.getStorageSync('uid'),
  59. }).url(url).data(data).send();
  60. }
  61. //添加评论
  62. static getDetailsPosts(data) {
  63. const url = httpApiUrl('wx/posts');
  64. return getInstance().header({
  65. uid: wx.getStorageSync('uid'),
  66. }).url(url).data(data).method('POST').send();
  67. }
  68. //获取评论列表
  69. static getPostsList(data) {
  70. const url = httpApiUrl('wx/posts');
  71. return getInstance().header({
  72. uid: wx.getStorageSync('uid'),
  73. }).url(url).data(data).send();
  74. }
  75. //获取播放记录
  76. static getPlayLogList(data) {
  77. const url = httpApiUrl('wx/playLog');
  78. return getInstance().header({
  79. uid: wx.getStorageSync('uid'),
  80. }).url(url).data(data).send();
  81. }
  82. //上传图片到相册
  83. static addPhotoList(data) {
  84. const url = httpApiUrl('wx/photoBox');
  85. return getInstance().header({
  86. uid: wx.getStorageSync('uid'),
  87. }).url(url).data(data).method('POST').send();
  88. }
  89. //获取相册列表
  90. static getPhotoList(data) {
  91. const url = httpApiUrl('wx/photoBox');
  92. return getInstance().header({
  93. uid: wx.getStorageSync('uid'),
  94. }).url(url).data(data).send();
  95. }
  96. //删除相册
  97. static removePhotoList(id) {
  98. const url = httpApiUrl(`wx/photoBox/${ id }`);
  99. return getInstance().header({
  100. uid: wx.getStorageSync('uid'),
  101. }).url(url).method('DELETE').send();
  102. }
  103. //相册设置
  104. static setPhoto(photoBox) {
  105. const url = httpApiUrl(`wx/user/photoBox`);
  106. return getInstance().header({
  107. uid: wx.getStorageSync('uid'),
  108. }).url(url).data({
  109. photoBox,
  110. }).method('PUT').send();
  111. }
  112. //萌娃相册列表
  113. static getPhotoBoxList(data) {
  114. const url = httpApiUrl('wx/photoBox/cuteBaby/list');
  115. return getInstance().header({
  116. uid: wx.getStorageSync('uid'),
  117. }).url(url).data(data).send();
  118. }
  119. //根据用户id获取用户相册信息
  120. static getPhotoBoxInfoById(data) {
  121. const url = httpApiUrl('wx/photoBox/cuteBaby/info');
  122. return getInstance().header({
  123. uid: wx.getStorageSync('uid'),
  124. }).url(url).data(data).send();
  125. }
  126. //点赞
  127. static setPhotoBoxLike(data) {
  128. const url = httpApiUrl(`wx/user/like/${data.target}`);
  129. return getInstance().header({
  130. uid: wx.getStorageSync('uid'),
  131. }).url(url).method('POST').send();
  132. }
  133. //获取用户信息
  134. static getUserInfo() {
  135. const url = httpApiUrl(`wx/user`);
  136. console.log('===============================', wx.getStorageSync('uid'));
  137. return getInstance().header({
  138. uid: wx.getStorageSync('uid'),
  139. }).url(url).send();
  140. }
  141. //修改用户信息
  142. static setUserInfo(data) {
  143. const url = httpApiUrl(`wx/user`);
  144. return getInstance().header({
  145. uid: wx.getStorageSync('uid'),
  146. }).url(url).data(data).method('PUT').send();
  147. }
  148. }
  149. export default httpRequestApi;