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

205 lines
3.3 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
8 months ago
9 months ago
10 months ago
10 months ago
10 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. clockProjectList: {
  106. url: '/clock/project/list',
  107. method: 'GET',
  108. auth : true,
  109. showLoading : true,
  110. },
  111. // 设置项目经纬度
  112. clockProjectLocation: {
  113. url: '/clock/project/location',
  114. method: 'POST',
  115. auth : true,
  116. showLoading : true,
  117. },
  118. }
  119. export function api(key, data, callback, loadingTitle) {
  120. let req = config[key]
  121. if (!req) {
  122. console.error('无效key' + key);
  123. return
  124. }
  125. if (typeof callback == 'string') {
  126. loadingTitle = callback
  127. }
  128. if (typeof data == 'function') {
  129. callback = data
  130. data = {}
  131. }
  132. // 接口限流
  133. if (req.limit) {
  134. let storageKey = req.url
  135. let storage = limit[storageKey]
  136. if (storage && new Date().getTime() - storage < req.limit) {
  137. return
  138. }
  139. limit[storageKey] = new Date().getTime()
  140. }
  141. //必须登录
  142. if (req.auth) {
  143. if (!uni.getStorageSync('token')) {
  144. uni.navigateTo({
  145. url: '/pages/login/login'
  146. })
  147. console.error('需要登录')
  148. return
  149. }
  150. }
  151. // 接口防抖
  152. if(req.debounce){
  153. let storageKey = req.url
  154. let storage = debounce[storageKey]
  155. if (storage) {
  156. clearTimeout(storage)
  157. }
  158. debounce[storageKey] = setTimeout(() => {
  159. clearTimeout(storage)
  160. delete debounce[storageKey]
  161. http.http(req.url, data, callback, req.method,
  162. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  163. }, req.debounce)
  164. return
  165. }
  166. http.http(req.url, data, callback, req.method,
  167. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  168. }
  169. export default api