APIClient.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. const request = require('./WXHttpRequest.js');
  2. const url = require('./const.js');
  3. const loginSchedule = require('./loginSchedule.js');
  4. const HOST = url.apiUrl;
  5. const HOSTTwo = url.apiUrlTwo;
  6. function genAPIUrl(action) {
  7. return HOST + action;
  8. }
  9. function genAPIUrlTwo(action) {
  10. return HOSTTwo + action;
  11. }
  12. // function genData(data) {
  13. // debugger;
  14. // let commonData = {
  15. // platform_type: PLATFORM
  16. // }
  17. // for (let key in commonData) {
  18. // data[key] = commonData[key];
  19. // }
  20. // return data;
  21. // }
  22. //没有登录的提示
  23. function showModal() {
  24. wx.showModal({
  25. title: '提示',
  26. content: '需要获取您的公开信息(昵称、头像等),请从小程序列表删除快乐学堂小助手后再次扫码进入,允许授权后可正常使用',
  27. showCancel: false,
  28. success: function (res) {
  29. if (res.confirm) {
  30. console.log('用户点击确定')
  31. } else if (res.cancel) {
  32. console.log('用户点击取消')
  33. }
  34. }
  35. })
  36. }
  37. module.exports = {
  38. // 获取我的data
  39. getMySchedule(header) {
  40. let url = genAPIUrl('wx/ucenter');
  41. return request.getInstance().url(url).header(header).send();
  42. },
  43. //获取推荐课程
  44. getRecommendSchedule(header) {
  45. let url = genAPIUrl('wx/course/recommend');
  46. return request.getInstance().url(url).header(header).send();
  47. },
  48. //发送上传图片
  49. getSendSchedule(header, data) {
  50. let url = genAPIUrl('wx/posts');
  51. return request.getInstance().url(url).header(header).data(data).method('POST').send();
  52. },
  53. //获取分享作品list
  54. getProductionSchedule(header, data) {
  55. let url = genAPIUrl('wx/posts/reply');
  56. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  57. },
  58. //保存评论
  59. getDiscussSchedule(header, data) {
  60. let url = genAPIUrl('wx/reply');
  61. return request.getInstance().url(url).header(header).data(data).method('POST').send();
  62. },
  63. //分享查询单条
  64. getOneSchedule(header, data) {
  65. let url = genAPIUrl('wx/posts/one');
  66. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  67. },
  68. //各个科目信息
  69. getEachSchedule(header, data) {
  70. let url = genAPIUrl('wx/course');
  71. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  72. },
  73. //各个排名
  74. getFriendSchedule(urls, header) {
  75. let url = genAPIUrl(urls);
  76. return request.getInstance().url(url).header(header).method('GET').send();
  77. },
  78. //更改昵称
  79. getSetNameSchedule(header, data) {
  80. let url = genAPIUrl('wx/ucenter/user/update');
  81. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  82. },
  83. //分享后点赞
  84. getLikeSchedule(header, data) {
  85. let url = genAPIUrl('wx/posts/attribute');
  86. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  87. },
  88. //取消小点
  89. cancelDian(header, data) {
  90. let url = genAPIUrl('wx/posts/readCount');
  91. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  92. },
  93. //获取错题本
  94. getErrorsSchedule(header, data) {
  95. let url = genAPIUrl('wx/question/wrong');
  96. return request.getInstance().url(url).header(header).data(data).method('GET').send();
  97. },
  98. //记录用户操作
  99. getStatisticsOpt (header, data) {
  100. let url = genAPIUrl('wx/statistics/opt');
  101. return request.getInstance().url(url).header(header).data(data).method('POST').send();
  102. },
  103. //获取用户答题指数
  104. getExponentSchedule(header) {
  105. let url = genAPIUrl('wx/question/exponent');
  106. return request.getInstance().url(url).header(header).method('GET').send();
  107. },
  108. //获取二维码
  109. getqrCode(data) {
  110. let url = genAPIUrl('wx/qrCode/postsCache');
  111. return request.getInstance().url(url).header({
  112. uid: wx.getStorageSync('uid')
  113. }).data(data).method('GET').send();
  114. },
  115. //操作留言
  116. setMessage(data) {
  117. let url = genAPIUrl('wx/posts');
  118. return request.getInstance().url(url).header({
  119. uid: wx.getStorageSync('uid')
  120. }).data(data).method('PUT').send();
  121. },
  122. /**另一个小程序接口调用从此处开始 */
  123. // 获取课程表列表
  124. getClassSchedule() {
  125. let url = genAPIUrlTwo('wx/classSchedule/list');
  126. return request.getInstance().url(url).send();
  127. },
  128. // 课程表详情列表
  129. getClassScheduleWeekly(itemId, userId) {
  130. if (!userId) {
  131. loginSchedule.getOpenidSessionKeyTwo(function (res) {
  132. wx.navigateBack();
  133. wx.navigateTo({
  134. url: `/pages/schedule/scheduleSubject/scheduleSubject?scene=sc&id=${itemId}`
  135. })
  136. }, function (res) {
  137. wx.navigateBack()
  138. });
  139. }
  140. let url = genAPIUrlTwo(`wx/classSchedule/weekly/${itemId}`);
  141. //let data = genData({ userId })
  142. return request.getInstance().data({ userId }).url(url).send();
  143. },
  144. // 课程表详情列表二维码
  145. getClassScheduleWeeklyQR(itemId, userId, showId) {
  146. if (!userId) {
  147. loginSchedule.getOpenidSessionKeyTwo(function (res) {
  148. wx.navigateBack()
  149. wx.navigateTo({
  150. url: `/pages/schedule/scheduleSubject/scheduleSubject?scene=sc&id=${itemId}&showId=${showId}`
  151. })
  152. }, function (res) {
  153. wx.navigateBack()
  154. showModal()
  155. });
  156. }
  157. let url = genAPIUrlTwo(`wx/classSchedule/weekly/${itemId}`);
  158. //let data = genData({ userId, showId })
  159. return request.getInstance().data({ userId, showId }).url(url).send();
  160. },
  161. // 课程表详情问答列表
  162. getQAList(userId, columnId, columnType, pageNo, pageSize) {
  163. let url = genAPIUrlTwo(`wx/posts`);
  164. let data = {
  165. userId,
  166. columnId,
  167. columnType,
  168. pageNo,
  169. pageSize
  170. }
  171. return request.getInstance().url(url).data(data).send();
  172. },
  173. // 添加问题
  174. addQuestion(userId, columnId, columnType, title, columnNames) {
  175. let url = genAPIUrlTwo(`wx/posts`);
  176. let header = {'content-type': 'application/x-www-form-urlencoded'}
  177. let data = {
  178. userId,
  179. columnId,
  180. columnType,
  181. title,
  182. columnNames
  183. }
  184. return request.getInstance().url(url).header(header).method('POST').data(data).send();
  185. },
  186. // 添加问题回复
  187. addReply(userId, postsId, content, columnNames) {
  188. let url = genAPIUrlTwo(`wx/posts/addReply`);
  189. let header = {'content-type': 'application/x-www-form-urlencoded'}
  190. let data = {
  191. userId,
  192. postsId,
  193. content,
  194. columnNames
  195. }
  196. return request.getInstance().url(url).header(header).method('POST').data(data).send();
  197. },
  198. // 问题点赞
  199. addPraise(userId, id) {
  200. let url = genAPIUrlTwo(`wx/posts/like`);
  201. let header = {'content-type': 'application/x-www-form-urlencoded'}
  202. let data = {
  203. userId,
  204. id
  205. }
  206. return request.getInstance().url(url).header(header).method('POST').data(data).send();
  207. },
  208. // 问题取消点赞
  209. cancelPraise(userId, id) {
  210. let url = genAPIUrlTwo(`wx/posts/unlike`);
  211. let header = {'content-type': 'application/x-www-form-urlencoded'}
  212. let data = {
  213. userId,
  214. id
  215. }
  216. return request.getInstance().url(url).header(header).method('POST').data(data).send();
  217. },
  218. // 直播课资料列表
  219. getMaterials(columnId) {
  220. let url = genAPIUrlTwo(`wx/classSchedule/courseware/${columnId}`);
  221. return request.getInstance().url(url).send();
  222. },
  223. // 课程表资料列表
  224. getScheduleMaterials(userId, itemId) {
  225. let url = genAPIUrlTwo(`wx/classSchedule/courseware/${itemId}`);
  226. let data = { userId }
  227. return request.getInstance().url(url).data(data).send();
  228. },
  229. // 添加收藏
  230. toggleCollection(userId, favoritesCode, favoritesType, name) {
  231. let url = genAPIUrlTwo('wx/favorites')
  232. let header = {'content-type': 'application/x-www-form-urlencoded'}
  233. let data = { userId, favoritesCode, favoritesType, name }
  234. return request.getInstance().url(url).method('POST').header(header).data(data).send()
  235. },
  236. // 获取teacherID title goal
  237. getScheduleGoal(itemId) {
  238. let url = genAPIUrlTwo(`wx/classSchedule/goal/${itemId}`);
  239. return request.getInstance().url(url).send();
  240. },
  241. // 课程表详情中的课程表和学习目标
  242. getScheduleDetailGoalSchedule(itemId, type, userId) {
  243. let url = genAPIUrlTwo(`wx/classSchedule/info/${itemId}`);
  244. let data = { type, userId }
  245. return request.getInstance().url(url).data(data).send();
  246. },
  247. //6.5错题
  248. getScheduleErr(qid) {
  249. let data = {
  250. qid
  251. }
  252. return request.getInstance().url('https://schedule.api.ai160.com/customer/question/getAnalysis').data(data).send();
  253. },
  254. }