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

188 lines
3.0 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
6 months ago
7 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 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 : 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. clockTime: {
  70. url: '/clock/time',
  71. method: 'POST',
  72. showLoading : true,
  73. auth : true,
  74. },
  75. // 人脸识别
  76. clockVerifyFace: {
  77. url: '/clock/verify/face',
  78. method: 'POST',
  79. showLoading : true,
  80. auth : true,
  81. limit : 2000,
  82. loadingTitle : '核验中',
  83. },
  84. // 打卡
  85. clock: {
  86. url: '/clock/in',
  87. method: 'POST',
  88. showLoading : true,
  89. auth: true,
  90. limit : 800,
  91. },
  92. // 打卡详情列表
  93. clockList: {
  94. url: '/clock/in/log',
  95. method: 'GET',
  96. },
  97. // 打卡统计
  98. clockTotal: {
  99. url: '/clock/in/total',
  100. method: 'GET',
  101. showLoading : true,
  102. debounce : 400,
  103. },
  104. }
  105. export function api(key, data, callback, loadingTitle) {
  106. let req = config[key]
  107. if (!req) {
  108. console.error('无效key' + key);
  109. return
  110. }
  111. if (typeof callback == 'string') {
  112. loadingTitle = callback
  113. }
  114. if (typeof data == 'function') {
  115. callback = data
  116. data = {}
  117. }
  118. // 接口限流
  119. if (req.limit) {
  120. let storageKey = req.url
  121. let storage = limit[storageKey]
  122. if (storage && new Date().getTime() - storage < req.limit) {
  123. return
  124. }
  125. limit[storageKey] = new Date().getTime()
  126. }
  127. //必须登录
  128. if (req.auth) {
  129. if (!uni.getStorageSync('token')) {
  130. uni.navigateTo({
  131. url: '/pages/login/login'
  132. })
  133. console.error('需要登录')
  134. return
  135. }
  136. }
  137. // 接口防抖
  138. if(req.debounce){
  139. let storageKey = req.url
  140. let storage = debounce[storageKey]
  141. if (storage) {
  142. clearTimeout(storage)
  143. }
  144. debounce[storageKey] = setTimeout(() => {
  145. clearTimeout(storage)
  146. delete debounce[storageKey]
  147. http.http(req.url, data, callback, req.method,
  148. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  149. }, req.debounce)
  150. return
  151. }
  152. http.http(req.url, data, callback, req.method,
  153. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  154. }
  155. export default api