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

204 lines
3.9 KiB

4 months ago
2 months ago
4 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
4 months ago
2 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
4 months ago
4 months ago
2 months ago
4 months ago
2 months ago
4 months ago
3 weeks ago
4 months ago
3 weeks ago
4 months ago
2 months ago
6 days ago
3 weeks ago
4 months ago
3 weeks ago
4 months ago
3 weeks ago
4 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
4 months 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. commonQueryJobTypeList: {
  54. url: '/api/common/queryJobTypeList',
  55. method: 'GET',
  56. },
  57. //获取工作性质列表
  58. commonQueryJobNatureList: {
  59. url: '/api/common/queryJobNatureList',
  60. method: 'GET',
  61. },
  62. //获取banner图列表
  63. commonQueryBannerList: {
  64. url: '/api/common/queryBannerList',
  65. method: 'GET',
  66. },
  67. //获取开放地址列表
  68. commonQueryAddressList: {
  69. url: '/api/common/queryAddressList',
  70. method: 'GET',
  71. },
  72. //会员中心-正式积分||临时积分
  73. commonQueryScore: {
  74. url: '/api/common/queryScore',
  75. method: 'GET',
  76. },
  77. //积分记录
  78. commonQueryScoreRecord: {
  79. url: '/api/common/queryScoreRecord',
  80. method: 'GET',
  81. },
  82. //我的服务-获取VIP配置信息
  83. commonQueryVipType: {
  84. url: '/api/common/queryVipType',
  85. method: 'GET',
  86. },
  87. /**
  88. * 求职者的接口
  89. */
  90. //电子合同-获取电子合同列表
  91. employeeQueryContractList: {
  92. url: '/api/employee/queryContractList',
  93. method: 'GET',
  94. auth: true,
  95. },
  96. /**
  97. * boss的接口
  98. */
  99. //电子合同-获取电子合同列表
  100. bossQueryContractList: {
  101. url: '/api/boss/queryContractList',
  102. method: 'GET',
  103. auth: true,
  104. },
  105. }
  106. export function api(key, data, callback, loadingTitle) {
  107. let req = config[key]
  108. if (!req) {
  109. console.error('无效key' + key);
  110. return Promise.reject()
  111. }
  112. if (typeof callback == 'string') {
  113. loadingTitle = callback
  114. }
  115. if (typeof data == 'function') {
  116. callback = data
  117. data = {}
  118. }
  119. // 接口限流
  120. if (req.limit) {
  121. let storageKey = req.url
  122. let storage = limit[storageKey]
  123. if (storage && new Date().getTime() - storage < req.limit) {
  124. return Promise.reject()
  125. }
  126. limit[storageKey] = new Date().getTime()
  127. }
  128. //必须登录
  129. if (req.auth) {
  130. if (!uni.getStorageSync('token')) {
  131. utils.toLogin()
  132. console.error('需要登录', req.url)
  133. return Promise.reject()
  134. }
  135. }
  136. // 接口防抖
  137. if(req.debounce){
  138. let storageKey = req.url
  139. let storage = debounce[storageKey]
  140. if (storage) {
  141. clearTimeout(storage)
  142. }
  143. debounce[storageKey] = setTimeout(() => {
  144. clearTimeout(storage)
  145. delete debounce[storageKey]
  146. http.http(req.url, data, callback, req.method,
  147. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  148. }, req.debounce)
  149. return Promise.reject()
  150. }
  151. return http.http(req.url, data, callback, req.method,
  152. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  153. }
  154. function addApiModel(model, key){
  155. for(let k in model){
  156. if(config[`${k}`]){
  157. console.error(`重名api------model=${key},key=${k}`);
  158. uni.showModal({
  159. title: `重名api`,
  160. content: `model=${key},key=${k}`
  161. })
  162. continue
  163. }
  164. config[`${k}`] = model[k]
  165. // config[`${key}_${k}`] = model[k]
  166. }
  167. }
  168. models.forEach(key => {
  169. addApiModel(require(`./model/${key}.js`).default, key)
  170. })
  171. export default api