【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.

170 lines
2.7 KiB

6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
5 months ago
6 months 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 : 800,
  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. },
  62. // 实名认证详情
  63. authInfo: {
  64. url: '/auth/info',
  65. method: 'GET',
  66. },
  67. // 打卡
  68. clock: {
  69. url: '/clock/in',
  70. method: 'POST',
  71. showLoading : true,
  72. auth: true,
  73. limit : 800,
  74. },
  75. // 打卡详情列表
  76. clockList: {
  77. url: '/clock/in/log',
  78. method: 'GET',
  79. },
  80. // 打卡统计
  81. clockTotal: {
  82. url: '/clock/in/total',
  83. method: 'GET',
  84. showLoading : true,
  85. debounce : 400,
  86. },
  87. }
  88. export function api(key, data, callback, loadingTitle) {
  89. let req = config[key]
  90. if (!req) {
  91. console.error('无效key' + key);
  92. return
  93. }
  94. if (typeof callback == 'string') {
  95. loadingTitle = callback
  96. }
  97. if (typeof data == 'function') {
  98. callback = data
  99. data = {}
  100. }
  101. // 接口限流
  102. if (req.limit) {
  103. let storageKey = req.url
  104. let storage = limit[storageKey]
  105. if (storage && new Date().getTime() - storage < req.limit) {
  106. return
  107. }
  108. limit[storageKey] = new Date().getTime()
  109. }
  110. //必须登录
  111. if (req.auth) {
  112. if (!uni.getStorageSync('token')) {
  113. uni.navigateTo({
  114. url: '/pages/login/login'
  115. })
  116. console.error('需要登录')
  117. return
  118. }
  119. }
  120. // 接口防抖
  121. if(req.debounce){
  122. let storageKey = req.url
  123. let storage = debounce[storageKey]
  124. if (storage) {
  125. clearTimeout(storage)
  126. }
  127. debounce[storageKey] = setTimeout(() => {
  128. clearTimeout(storage)
  129. delete debounce[storageKey]
  130. http.http(req.url, data, callback, req.method,
  131. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  132. }, req.debounce)
  133. return
  134. }
  135. http.http(req.url, data, callback, req.method,
  136. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  137. }
  138. export default api