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

184 lines
3.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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: '/api/login/login',
  17. method: 'GET',
  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. commonQueryJobTypeList: {
  44. url: '/api/common/queryJobTypeList',
  45. method: 'GET',
  46. },
  47. //获取banner图列表
  48. commonQueryBannerList: {
  49. url: '/api/common/queryBannerList',
  50. method: 'GET',
  51. },
  52. //获取开放地址列表
  53. commonQueryAddressList: {
  54. url: '/api/common/queryAddressList',
  55. method: 'GET',
  56. },
  57. /**
  58. * 求职者的接口
  59. */
  60. //获取工作信息列表
  61. employeeQueryJobList: {
  62. url: '/api/employee/queryJobList',
  63. method: 'GET',
  64. },
  65. //根据Id查看工作详情
  66. employeeQueryJobById: {
  67. url: '/api/employee/queryJobById',
  68. method: 'GET',
  69. },
  70. //我的收藏
  71. employeeQueryCollectionJobList: {
  72. url: '/api/employee/queryJobCollectionList',
  73. method: 'GET',
  74. },
  75. //联系记录-我看过谁(我的找活)
  76. employeeQueryWatchWho: {
  77. url: '/api/employee/queryWatchWho',
  78. method: 'GET',
  79. },
  80. //联系记录-谁看过我(谁看过我的简历)
  81. employeeQueryWatchMe: {
  82. url: '/api/employee/queryWatchMe',
  83. method: 'GET',
  84. },
  85. /**
  86. * boss的接口
  87. */
  88. //获取简历列表
  89. bossQueryJobList: {
  90. url: '/api/boss/queryJobList',
  91. method: 'GET',
  92. },
  93. //根据Id查看简历详情
  94. bossQueryResumeById: {
  95. url: '/api/boss/queryResumeById',
  96. method: 'GET',
  97. },
  98. }
  99. export function api(key, data, callback, loadingTitle) {
  100. let req = config[key]
  101. if (!req) {
  102. console.error('无效key' + key);
  103. return
  104. }
  105. if (typeof callback == 'string') {
  106. loadingTitle = callback
  107. }
  108. if (typeof data == 'function') {
  109. callback = data
  110. data = {}
  111. }
  112. // 接口限流
  113. if (req.limit) {
  114. let storageKey = req.url
  115. let storage = limit[storageKey]
  116. if (storage && new Date().getTime() - storage < req.limit) {
  117. return
  118. }
  119. limit[storageKey] = new Date().getTime()
  120. }
  121. //必须登录
  122. if (req.auth) {
  123. if (!uni.getStorageSync('token')) {
  124. uni.navigateTo({
  125. url: '/pages_order/auth/wxLogin'
  126. })
  127. console.error('需要登录')
  128. return
  129. }
  130. }
  131. // 接口防抖
  132. if(req.debounce){
  133. let storageKey = req.url
  134. let storage = debounce[storageKey]
  135. if (storage) {
  136. clearTimeout(storage)
  137. }
  138. debounce[storageKey] = setTimeout(() => {
  139. clearTimeout(storage)
  140. delete debounce[storageKey]
  141. http.http(req.url, data, callback, req.method,
  142. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  143. }, req.debounce)
  144. return
  145. }
  146. http.http(req.url, data, callback, req.method,
  147. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  148. }
  149. export default api