特易招,招聘小程序
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.

143 lines
2.3 KiB

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. * 登录的接口
  13. */
  14. // 微信登录接口
  15. wxLogin: {
  16. url: '/login/login',
  17. method: 'POST',
  18. limit : 500,
  19. showLoading : true,
  20. },
  21. // 修改个人信息接口
  22. updateInfo: {
  23. url: '/info/updateInfo',
  24. method: 'POST',
  25. auth: true,
  26. limit : 500,
  27. showLoading : true,
  28. },
  29. //隐私政策
  30. getPrivacyPolicy: {
  31. url: '/login/getPrivacyPolicy',
  32. method: 'GET',
  33. },
  34. //用户协议
  35. getUserAgreement: {
  36. url: '/login/getUserAgreement',
  37. method: 'GET',
  38. },
  39. /**
  40. * 公共的接口
  41. */
  42. /**
  43. * 求职者的接口
  44. */
  45. //获取工作信息列表
  46. employeeQueryJobList: {
  47. url: '/api/employee/queryJobList',
  48. method: 'GET',
  49. },
  50. //根据Id查看工作详情
  51. employeeQueryJobById: {
  52. url: '/api/employee/queryJobById',
  53. method: 'GET',
  54. },
  55. /**
  56. * boss的接口
  57. */
  58. }
  59. export function api(key, data, callback, loadingTitle) {
  60. let req = config[key]
  61. if (!req) {
  62. console.error('无效key' + key);
  63. return
  64. }
  65. if (typeof callback == 'string') {
  66. loadingTitle = callback
  67. }
  68. if (typeof data == 'function') {
  69. callback = data
  70. data = {}
  71. }
  72. // 接口限流
  73. if (req.limit) {
  74. let storageKey = req.url
  75. let storage = limit[storageKey]
  76. if (storage && new Date().getTime() - storage < req.limit) {
  77. return
  78. }
  79. limit[storageKey] = new Date().getTime()
  80. }
  81. //必须登录
  82. if (req.auth) {
  83. if (!uni.getStorageSync('token')) {
  84. uni.navigateTo({
  85. url: '/pages_order/auth/wxLogin'
  86. })
  87. console.error('需要登录')
  88. return
  89. }
  90. }
  91. // 接口防抖
  92. if(req.debounce){
  93. let storageKey = req.url
  94. let storage = debounce[storageKey]
  95. if (storage) {
  96. clearTimeout(storage)
  97. }
  98. debounce[storageKey] = setTimeout(() => {
  99. clearTimeout(storage)
  100. delete debounce[storageKey]
  101. http.http(req.url, data, callback, req.method,
  102. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  103. }, req.debounce)
  104. return
  105. }
  106. http.http(req.url, data, callback, req.method,
  107. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  108. }
  109. export default api