时空网前端
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.

46 lines
1.0 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. return true;
  19. };
  20. // 响应拦截
  21. Vue.prototype.$u.http.interceptor.response = res => {
  22. if(res.code == 0) {
  23. return res;
  24. } else if(res.code == 201) {
  25. console.log("其他状态:", res.code)
  26. return false;
  27. } else if (res.code == 9999) {
  28. uni.navigateTo({
  29. url: '/pages/login/index?type=userinfo'
  30. })
  31. return false;
  32. } else if (res.code == 9998) {
  33. uni.navigateTo({
  34. url: '/pages/login/index?type=phone'
  35. })
  36. return false;
  37. } else {
  38. return false;
  39. }
  40. }
  41. }
  42. export default {
  43. install
  44. }