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

199 lines
3.8 KiB

1 year ago
10 months ago
1 year ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
1 year ago
10 months 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
10 months ago
1 year ago
10 months ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
10 months ago
1 year ago
8 months ago
1 year ago
8 months ago
1 year ago
10 months ago
8 months ago
8 months ago
1 year ago
8 months ago
1 year ago
8 months ago
1 year ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
1 year ago
  1. import http from './http.js'
  2. import utils from '../utils/utils.js'
  3. let limit = {}
  4. let debounce = {}
  5. const models = [
  6. 'score', 'boss', 'login', 'vip', 'company', 'work','index-lzx', 'resume',
  7. 'config',
  8. 'examination',
  9. 'collect',
  10. 'contact',
  11. 'workEntryInfo',
  12. ]
  13. const config = {
  14. // 示例
  15. // wxLogin : {url : '/api/wxLogin', method : 'POST',
  16. // auth : false, showLoading : true, loadingTitle : '加载中...',
  17. // limit : 1000
  18. // },
  19. // getConfig : {url : '/api/getConfig', method : 'GET', limit : 500},
  20. /**
  21. * 公共的接口
  22. */
  23. //关于本程序
  24. commonAboutUs: {
  25. url: '/api/common/aboutUs',
  26. method: 'GET',
  27. },
  28. // 我的服务-兑换码
  29. commonAddExchange: {
  30. url: '/api/common/addExchange',
  31. method: 'POST',
  32. auth: true,
  33. limit : 500,
  34. showLoading : true,
  35. },
  36. // 我的服务-会员充值(开通VIP)
  37. commonAddRecharge: {
  38. url: '/api/common/addRecharge',
  39. method: 'POST',
  40. auth: true,
  41. limit : 500,
  42. showLoading : true,
  43. },
  44. // 我的服务-获取积分-充值积分
  45. commonAddScoreByRecharge: {
  46. url: '/api/common/addScoreByRecharge',
  47. method: 'POST',
  48. auth: true,
  49. limit : 500,
  50. showLoading : true,
  51. },
  52. //获取工作性质列表
  53. commonQueryJobNatureList: {
  54. url: '/api/common/queryJobNatureList',
  55. method: 'GET',
  56. },
  57. //获取banner图列表
  58. commonQueryBannerList: {
  59. url: '/api/common/queryBannerList',
  60. method: 'GET',
  61. },
  62. //获取开放地址列表
  63. commonQueryAddressList: {
  64. url: '/api/common/queryAddressList',
  65. method: 'GET',
  66. },
  67. //会员中心-正式积分||临时积分
  68. commonQueryScore: {
  69. url: '/api/common/queryScore',
  70. method: 'GET',
  71. },
  72. //积分记录
  73. commonQueryScoreRecord: {
  74. url: '/api/common/queryScoreRecord',
  75. method: 'GET',
  76. },
  77. //我的服务-获取VIP配置信息
  78. commonQueryVipType: {
  79. url: '/api/common/queryVipType',
  80. method: 'GET',
  81. },
  82. /**
  83. * 求职者的接口
  84. */
  85. //电子合同-获取电子合同列表
  86. employeeQueryContractList: {
  87. url: '/api/employee/queryContractList',
  88. method: 'GET',
  89. auth: true,
  90. },
  91. /**
  92. * boss的接口
  93. */
  94. //电子合同-获取电子合同列表
  95. bossQueryContractList: {
  96. url: '/api/boss/queryContractList',
  97. method: 'GET',
  98. auth: true,
  99. },
  100. }
  101. export function api(key, data, callback, loadingTitle) {
  102. let req = config[key]
  103. if (!req) {
  104. console.error('无效key' + key);
  105. return Promise.reject()
  106. }
  107. if (typeof callback == 'string') {
  108. loadingTitle = callback
  109. }
  110. if (typeof data == 'function') {
  111. callback = data
  112. data = {}
  113. }
  114. // 接口限流
  115. if (req.limit) {
  116. let storageKey = req.url
  117. let storage = limit[storageKey]
  118. if (storage && new Date().getTime() - storage < req.limit) {
  119. return Promise.reject()
  120. }
  121. limit[storageKey] = new Date().getTime()
  122. }
  123. //必须登录
  124. if (req.auth) {
  125. if (!uni.getStorageSync('token')) {
  126. utils.toLogin()
  127. console.error('需要登录', req.url)
  128. return Promise.reject()
  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 Promise.reject()
  145. }
  146. return http.http(req.url, data, callback, req.method,
  147. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  148. }
  149. function addApiModel(model, key){
  150. for(let k in model){
  151. if(config[`${k}`]){
  152. console.error(`重名api------model=${key},key=${k}`);
  153. uni.showModal({
  154. title: `重名api`,
  155. content: `model=${key},key=${k}`
  156. })
  157. continue
  158. }
  159. config[`${k}`] = model[k]
  160. // config[`${key}_${k}`] = model[k]
  161. }
  162. }
  163. models.forEach(key => {
  164. addApiModel(require(`./model/${key}.js`).default, key)
  165. })
  166. export default api