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

126 lines
2.3 KiB

5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 months ago
3 months ago
5 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. export function api(key, data, callback, loadingTitle){
  72. let req = config[key]
  73. if (!req) {
  74. console.error('无效key' + key);
  75. return
  76. }
  77. if(typeof callback == 'string'){
  78. loadingTitle = callback
  79. }
  80. if(typeof data == 'function'){
  81. callback = data
  82. data = {}
  83. }
  84. // 接口限流
  85. if(req.limit){
  86. let storageKey = 'limit:' + req.url
  87. let storage = uni.getStorageSync(storageKey)
  88. if(storage && new Date().getTime() - parseInt(storage) < req.limit){
  89. return
  90. }
  91. uni.setStorageSync(storageKey, new Date().getTime())
  92. }
  93. //必须登录
  94. if (req.auth) {
  95. if (!uni.getStorageSync('token')) {
  96. utils.toLogin()
  97. console.error('需要登录')
  98. return
  99. }
  100. }
  101. http.http(req.url, data, callback, req.method,
  102. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  103. }
  104. export default api