【PT.SCC实名制管理系统】24.10.01 -30天,考勤打卡小程序
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.

171 lines
2.8 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import http from './http.js'
  2. let limit = {}
  3. let debounce = {}
  4. const config = {
  5. // 示例
  6. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  7. // auth : false, showLoading : true, loadingTitle : '加载中...',
  8. // limit : 1000
  9. // },
  10. getConfig : {url : '/api/getConfig', method : 'GET', limit : 500},
  11. // 微信登录接口
  12. wxLogin: {
  13. url: '/login/login',
  14. method: 'POST',
  15. limit : 500,
  16. showLoading : true,
  17. },
  18. // 修改个人信息接口
  19. updateInfo: {
  20. url: '/user/edit',
  21. method: 'POST',
  22. auth: true,
  23. limit : 800,
  24. showLoading : true,
  25. },
  26. // 获取用户信息
  27. getInfo: {
  28. url: '/user/info',
  29. method: 'GET',
  30. auth: true,
  31. limit : 200,
  32. },
  33. //隐私政策
  34. getPrivacyPolicy: {
  35. url: '/login/getPrivacyPolicy',
  36. method: 'GET',
  37. },
  38. //用户协议
  39. getUserAgreement: {
  40. url: '/login/getUserAgreement',
  41. method: 'GET',
  42. },
  43. // 获取团队
  44. teamList: {
  45. url: '/team/list',
  46. method: 'GET',
  47. },
  48. // 申请加入团队
  49. teamApply: {
  50. url: '/team/apply',
  51. method: 'POST',
  52. auth: true,
  53. limit : 800,
  54. },
  55. // 实名认证
  56. authApply: {
  57. url: '/auth/apply',
  58. method: 'POST',
  59. auth: true,
  60. limit : 800,
  61. showLoading : true,
  62. },
  63. // 实名认证详情
  64. authInfo: {
  65. url: '/auth/info',
  66. method: 'GET',
  67. },
  68. // 打卡
  69. clock: {
  70. url: '/clock/in',
  71. method: 'POST',
  72. showLoading : true,
  73. auth: true,
  74. limit : 800,
  75. },
  76. // 打卡详情列表
  77. clockList: {
  78. url: '/clock/in/log',
  79. method: 'GET',
  80. },
  81. // 打卡统计
  82. clockTotal: {
  83. url: '/clock/in/total',
  84. method: 'GET',
  85. showLoading : true,
  86. debounce : 400,
  87. },
  88. }
  89. export function api(key, data, callback, loadingTitle) {
  90. let req = config[key]
  91. if (!req) {
  92. console.error('无效key' + key);
  93. return
  94. }
  95. if (typeof callback == 'string') {
  96. loadingTitle = callback
  97. }
  98. if (typeof data == 'function') {
  99. callback = data
  100. data = {}
  101. }
  102. // 接口限流
  103. if (req.limit) {
  104. let storageKey = req.url
  105. let storage = limit[storageKey]
  106. if (storage && new Date().getTime() - storage < req.limit) {
  107. return
  108. }
  109. limit[storageKey] = new Date().getTime()
  110. }
  111. //必须登录
  112. if (req.auth) {
  113. if (!uni.getStorageSync('token')) {
  114. uni.navigateTo({
  115. url: '/pages/login/login'
  116. })
  117. console.error('需要登录')
  118. return
  119. }
  120. }
  121. // 接口防抖
  122. if(req.debounce){
  123. let storageKey = req.url
  124. let storage = debounce[storageKey]
  125. if (storage) {
  126. clearTimeout(storage)
  127. }
  128. debounce[storageKey] = setTimeout(() => {
  129. clearTimeout(storage)
  130. delete debounce[storageKey]
  131. http.http(req.url, data, callback, req.method,
  132. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  133. }, req.debounce)
  134. return
  135. }
  136. http.http(req.url, data, callback, req.method,
  137. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  138. }
  139. export default api