自主产品,供应链食堂系统。将两个端拆开了。
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.

45 lines
1.1 KiB

5 years ago
  1. const install = (Vue, vm) => {
  2. // 请求地址
  3. let baseUrl = vm.API.PRODURL;
  4. if(vm.API.DEV == 'dev'){
  5. baseUrl = vm.API.DEVURL;
  6. };
  7. // 请求全局配置
  8. Vue.prototype.$u.http.setConfig({
  9. baseUrl: baseUrl,
  10. method: 'POST',
  11. dataType: 'json', // 返回数据时自动 JSON.parse()
  12. showLoading: true, // 是否显示请求中的loading
  13. loadingText: '正在加载',
  14. loadingTime: 800 // 延迟800毫秒时显示加载框
  15. });
  16. // 请求前拦截
  17. Vue.prototype.$u.http.interceptor.request = config => {
  18. // console.log("config", config, config.url)
  19. let release_apis = [
  20. '/api/canteen/login'
  21. ];
  22. if(!config.header.token && !release_apis.includes(config.url)){
  23. return false; // 拦截,拦截没有token的页面,但不包括登录页的api
  24. }else{
  25. return true; // 放行
  26. }
  27. };
  28. // 响应拦截
  29. Vue.prototype.$u.http.interceptor.response = res => {
  30. if(res.code == 0) {
  31. return res;
  32. } else if (res.code == 9999) {
  33. vm.$redirectToLogin('登录超时, 请重新登录');
  34. return false;
  35. } else {
  36. vm.$msg(res.msg);
  37. return false;
  38. }
  39. }
  40. }
  41. export default {
  42. install
  43. }