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

216 lines
4.1 KiB

6 months ago
4 months ago
6 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
6 months ago
4 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
6 months ago
4 months ago
6 months ago
6 months ago
4 months ago
6 months ago
6 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
6 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. employeeQueryResumeByUserId: {
  92. url: '/api/employee/queryResumeByUserId',
  93. method: 'GET',
  94. auth: true,
  95. },
  96. //联系记录-我看过谁
  97. employeeQueryWatchWho: {
  98. url: '/api/employee/queryWatchWho',
  99. method: 'GET',
  100. auth: true,
  101. },
  102. //电子合同-获取电子合同列表
  103. employeeQueryContractList: {
  104. url: '/api/employee/queryContractList',
  105. method: 'GET',
  106. auth: true,
  107. },
  108. /**
  109. * boss的接口
  110. */
  111. //电子合同-获取电子合同列表
  112. bossQueryContractList: {
  113. url: '/api/boss/queryContractList',
  114. method: 'GET',
  115. auth: true,
  116. },
  117. }
  118. export function api(key, data, callback, loadingTitle) {
  119. let req = config[key]
  120. if (!req) {
  121. console.error('无效key' + key);
  122. return
  123. }
  124. if (typeof callback == 'string') {
  125. loadingTitle = callback
  126. }
  127. if (typeof data == 'function') {
  128. callback = data
  129. data = {}
  130. }
  131. // 接口限流
  132. if (req.limit) {
  133. let storageKey = req.url
  134. let storage = limit[storageKey]
  135. if (storage && new Date().getTime() - storage < req.limit) {
  136. return
  137. }
  138. limit[storageKey] = new Date().getTime()
  139. }
  140. //必须登录
  141. if (req.auth) {
  142. if (!uni.getStorageSync('token')) {
  143. utils.toLogin()
  144. console.error('需要登录')
  145. return
  146. }
  147. }
  148. // 接口防抖
  149. if(req.debounce){
  150. let storageKey = req.url
  151. let storage = debounce[storageKey]
  152. if (storage) {
  153. clearTimeout(storage)
  154. }
  155. debounce[storageKey] = setTimeout(() => {
  156. clearTimeout(storage)
  157. delete debounce[storageKey]
  158. http.http(req.url, data, callback, req.method,
  159. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  160. }, req.debounce)
  161. return
  162. }
  163. http.http(req.url, data, callback, req.method,
  164. loadingTitle || req.showLoading, loadingTitle || req.loadingTitle)
  165. }
  166. function addApiModel(model, key){
  167. for(let k in model){
  168. if(config[`${k}`]){
  169. console.error(`重名api------model=${key},key=${k}`);
  170. uni.showModal({
  171. title: `重名api`,
  172. content: `model=${key},key=${k}`
  173. })
  174. continue
  175. }
  176. config[`${k}`] = model[k]
  177. // config[`${key}_${k}`] = model[k]
  178. }
  179. }
  180. models.forEach(key => {
  181. addApiModel(require(`./model/${key}.js`).default, key)
  182. })
  183. export default api