百富门答题小程序
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.

151 lines
2.8 KiB

10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
8 months ago
7 months ago
8 months ago
10 months ago
8 months ago
10 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. bannerList: {
  44. url: '/applet_index/bannerList',
  45. method: 'GET',
  46. },
  47. //提交问答记录
  48. submitLog: {
  49. url: '/applet_post/submitLog',
  50. method: 'POST',
  51. limit : 1000,
  52. showLoading : true,
  53. auth: true,
  54. },
  55. //提交问答记录
  56. submit: {
  57. url: '/applet_post/submit',
  58. method: 'POST',
  59. limit : 1000,
  60. showLoading : true,
  61. auth: true,
  62. },
  63. //查询我的问答记录
  64. queryMyLog: {
  65. url: '/applet_post/queryMyLog',
  66. method: 'GET',
  67. auth: true,
  68. showLoading : true,
  69. },
  70. //查询预约记录
  71. queryReservation: {
  72. url: '/applet_post/queryReservation',
  73. method: 'GET',
  74. auth: true,
  75. },
  76. //查询预约详情
  77. queryReservationDetail: {
  78. url: '/applet_post/queryReservationDetail',
  79. method: 'GET',
  80. auth: true,
  81. },
  82. //查询预约详情
  83. queryReservationDetail: {
  84. url: '/applet_post/queryReservationDetail',
  85. method: 'GET',
  86. auth: true,
  87. },
  88. //取消预约
  89. cancelReservation: {
  90. url: '/applet_post/cancelReservation',
  91. method: 'GET',
  92. auth: true,
  93. showLoading : true,
  94. },
  95. }
  96. export function api(key, data, callback, loadingTitle){
  97. let req = config[key]
  98. if (!req) {
  99. console.error('无效key' + key);
  100. return
  101. }
  102. if(typeof callback == 'string'){
  103. loadingTitle = callback
  104. }
  105. if(typeof data == 'function'){
  106. callback = data
  107. data = {}
  108. }
  109. // 接口限流
  110. if(req.limit){
  111. let storageKey = 'limit:' + req.url
  112. let storage = uni.getStorageSync(storageKey)
  113. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  114. return
  115. }
  116. uni.setStorageSync(storageKey, new Date().getTime())
  117. }
  118. //必须登录
  119. if (req.auth) {
  120. if (!uni.getStorageSync('token')) {
  121. utils.toLogin()
  122. console.error('需要登录')
  123. return
  124. }
  125. }
  126. http.http(req.url, data, callback, req.method,
  127. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  128. }
  129. export default api