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

156 lines
2.5 KiB

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