百富门答题小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
4.0 KiB

7 months ago
4 months ago
7 months ago
4 months ago
7 months ago
4 months ago
7 months ago
4 months ago
7 months ago
4 months ago
7 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
7 months ago
2 months ago
7 months ago
4 months ago
7 months ago
  1. import http from './http.js'
  2. import utils from '../utils/utils.js'
  3. const config = {
  4. // 示例
  5. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  6. // auth : false, showLoading : true, loadingTitle : '加载中...',
  7. // limit : 1000
  8. // },
  9. getConfig : {url : '/applet_index/commonConfig', method : 'GET', limit : 500},
  10. // 微信登录接口
  11. wxLogin: {
  12. url: '/login_common/appletLogin',
  13. method: 'GET',
  14. limit : 500,
  15. showLoading : true,
  16. },
  17. // 获取个人信息接口
  18. getInfo: {
  19. url: '/info_common/getInfo',
  20. method: 'GET',
  21. limit : 500,
  22. showLoading : true,
  23. },
  24. // 修改个人信息接口
  25. updateInfo: {
  26. url: '/info_common/updateInfo',
  27. method: 'POST',
  28. auth: true,
  29. limit : 500,
  30. showLoading : true,
  31. },
  32. // //首页-出现问题列表接口
  33. // problemList: {
  34. // url: '/applet_index/problemList',
  35. // method: 'GET',
  36. // },
  37. // //首页-文章列表接口
  38. // articleList: {
  39. // url: '/applet_index/articleList',
  40. // method: 'GET',
  41. // },
  42. //首页-品牌介绍接口
  43. getBrand: {
  44. url: '/applet_index/getBrand',
  45. method: 'GET',
  46. },
  47. //首页-轮播图接口
  48. // bannerList: {
  49. // url: '/applet_index/bannerList',
  50. // method: 'GET',
  51. // },
  52. //提交问答记录
  53. // submitLog: {
  54. // url: '/applet_post/submitLog',
  55. // method: 'POST',
  56. // limit : 1000,
  57. // showLoading : true,
  58. // auth: true,
  59. // },
  60. //提交预约信息
  61. // submit: {
  62. // url: '/applet_post/submit',
  63. // method: 'POST',
  64. // limit : 1000,
  65. // showLoading : true,
  66. // auth: true,
  67. // },
  68. // //查询我的问答记录
  69. // queryMyLog: {
  70. // url: '/applet_post/queryMyLog',
  71. // method: 'GET',
  72. // auth: true,
  73. // showLoading : true,
  74. // },
  75. // //查询预约记录
  76. // queryReservation: {
  77. // url: '/applet_post/queryReservation',
  78. // method: 'GET',
  79. // auth: true,
  80. // },
  81. // //查询预约详情
  82. // queryReservationDetail: {
  83. // url: '/applet_post/queryReservationDetail',
  84. // method: 'GET',
  85. // auth: true,
  86. // },
  87. // //查询预约详情
  88. // queryReservationDetail: {
  89. // url: '/applet_post/queryReservationDetail',
  90. // method: 'GET',
  91. // auth: true,
  92. // },
  93. // //取消预约
  94. // cancelReservation: {
  95. // url: '/applet_post/cancelReservation',
  96. // method: 'GET',
  97. // auth: true,
  98. // showLoading : true,
  99. // },
  100. // //我的-评论题目列表接口
  101. // queryAnswerList: {
  102. // url: '/applet_post/queryAnswerList',
  103. // method: 'GET',
  104. // },
  105. // //我的-回答评论接口
  106. // answerComment: {
  107. // url: '/applet_post/answerComment',
  108. // method: 'POST',
  109. // auth : true,
  110. // },
  111. // =======================================================
  112. // 第二版本
  113. // =======================================================
  114. // 1、查询第一个题目接口(返回一个题目和答案列表)
  115. firstQuestion: {
  116. url: '/applet_index/firstQuestion',
  117. method: 'GET',
  118. },
  119. // 2、根据题目id查询题目接口(返回一个题目和答案列表)
  120. getProblemById: {
  121. url: '/applet_index/getProblemById',
  122. method: 'GET',
  123. limit : 500,
  124. },
  125. // 3、根据用户选择的答案id列表查询出获得的称号接口(返回称号图片、文章列表)
  126. getTitleByIds: {
  127. url: '/applet_index/getTitleByIds',
  128. method: 'GET',
  129. limit : 500,
  130. },
  131. }
  132. export function api(key, data, callback, loadingTitle){
  133. let req = config[key]
  134. if (!req) {
  135. console.error('无效key' + key);
  136. return
  137. }
  138. if(typeof callback == 'string'){
  139. loadingTitle = callback
  140. }
  141. if(typeof data == 'function'){
  142. callback = data
  143. data = {}
  144. }
  145. // 接口限流
  146. if(req.limit){
  147. let storageKey = 'limit:' + req.url
  148. let storage = uni.getStorageSync(storageKey)
  149. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  150. // uni.showToast({
  151. // title: '请勿点击过快',
  152. // icon: 'none',
  153. // })
  154. return
  155. }
  156. uni.setStorageSync(storageKey, new Date().getTime())
  157. }
  158. //必须登录
  159. if (req.auth) {
  160. if (!uni.getStorageSync('token')) {
  161. utils.toLogin()
  162. console.error('需要登录')
  163. return
  164. }
  165. }
  166. http.http(req.url, data, callback, req.method,
  167. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  168. }
  169. export default api