Mr.shen 2 年之前
父節點
當前提交
ede564f05f
共有 4 個文件被更改,包括 64 次插入135 次删除
  1. 5 58
      src/main.js
  2. 1 3
      src/view/statistics.vue
  3. 0 74
      until/httpRequest.js
  4. 58 0
      until/request.js

+ 5 - 58
src/main.js

@@ -5,76 +5,23 @@ import router from './router'
 import ElementUI from 'element-ui'
 import 'element-ui/lib/theme-chalk/index.css'
 import dd from 'gdt-jsapi' //是腾讯广点通提供的模块
-import axiosInit from "../until/httpRequest.js"
 import base from "../until/base.js"
+import http from '../until/request'
+
+import axios from "axios";
 import store from './store/store.js';
 import VConsole from 'vconsole'
 const vConsole = new VConsole()
 Vue.use(vConsole)
 Vue.use(ElementUI);
 Vue.config.productionTip = false
+
+
 Vue.prototype.$dd = dd
-window.axios = axiosInit();
 Vue.prototype.$store = store;
-// Vue.prototype.$http = window.axios;
 Vue.prototype.$url = base.url;
-// Vue.prototype.$httpUrl = base.httpUrl;
-Vue.prototype.$geoUrl = base.geoserverUrl;
 Vue.prototype.$appId = base.appId;
-
-import axios from "axios";
-axios.defaults.baseURL = 'http://192.168.1.88:8081/anzhi/'        //王宇浩的本地端口
-const http = axios.create({
-  timeout: 1000 * 300,
-  withCredentials: true,
-  headers: {
-    'Content-Type': 'application/json; charset=utf-8'
-  }
-})
-
-/**
- * 请求拦截
- */
-http.interceptors.request.use(config => {
-  console.log("请求拦截--------",config);
-  config.headers['token'] = window.localStorage.getItem('token') // 请求头带上token
-
-  return config
-}, error => {
-  return Promise.reject(error)
-})
-
-/**
- * 响应拦截
- */
-http.interceptors.response.use(response => {
-  console.log("response---响应拦截------",response);
-  if (response.data && response.data.code === 401) { // 401, token失效
-    // ElementUI.Message.error("请重新登录");
-    // router.push({ name: 'login' })
-    dd.openSchemeUrl({
-      url: "taurus://taurusclient/action/open_app?appId=" + appId + "&type=1&offline=false&url=" + encodeURIComponent(url)
-    }).then(res => { })
-  } else if (response.data.code < 0) {
-    if (response.data.code == -2) {
-      return response
-    } else {
-      // ElementUI.Message.error(response.data.msg);
-      // 没有返回值会报错
-      return "错误"
-    }
-  } else {
-    return response
-  }
-}, error => {
-  console.log("error----------",error);
-})
-
-http.adornUrl = (s) => {
-  return 'proxyApi'
-}
 Vue.prototype.$http = http
-
 Vue.prototype.$axios = axios
 
 

+ 1 - 3
src/view/statistics.vue

@@ -130,12 +130,10 @@ export default {
       personnelData: {}
     };
   },
-  beforeMount() {
+  mounted() {
     this.$dd.setTitle({
       title: "统计"
     });
-  },
-  mounted() {
     console.log(
       "this.$router----statistics---",
       this.$router.history.current.name

+ 0 - 74
until/httpRequest.js

@@ -1,74 +0,0 @@
-import axios from 'axios';
-import dd from 'gdt-jsapi';
-import base from "./base.js"
-
-export default () => {
-  axios.defaults.baseURL = base.httpUrl; // 配置axios请求的地址
-  console.log("axios.defaults.baseURL-------", axios.defaults.baseURL);
-  axios.defaults.headers.post['Content-Type'] = 'application/json; charset=UTF-8';
-  axios.defaults.crossDomain = true;
-  axios.defaults.withCredentials = true;  //设置cross跨域 并设置访问权限 允许跨域携带cookie信息
-
-  //配置发送请求前的拦截器 可以设置token信息
-  axios.interceptors.request.use(config => {
-    console.log("config---------",config);
-    dd.showLoading({ text: "加载中" });
-    if (config.url.indexOf('geoserver/PH_DEMO') == '-1' && config.url.indexOf('/ding/authLogin') == '-1' && config.url.indexOf('/pub/ding/login') == '-1') {
-      // var token = localStorage.getItem('token');
-      // console.log('token--------',token);
-      // if (token) {
-      //   config.headers['token'] = token;
-      // }
-    } else {
-      config.withCredentials = false;
-    }
-    return config;
-  }, error => {
-    return Promise.reject(error);
-  });
-  // 配置响应拦截器
-  axios.interceptors.response.use(res => {
-    const code = res.data.code;
-    console.log('配置响应拦截器----', code);
-    dd.hideLoading();
-    //这里面写所需要的代码
-    if (res.data.code == '401') {
-      //全局登陆过滤,当判读token失效或者没有登录时 返回登陆页面
-      dd.toast({
-        text: '登录失效请重新登录'
-      });
-      var url = base.url + '/statistics';  //http://192.168.1.221:9081/api +  '/login?isLogin=1'
-      var appId = base.appId;
-      dd.openSchemeUrl({
-        url: "taurus://taurusclient/action/open_app?appId=" + appId + "&type=1&offline=false&url=" + encodeURIComponent(url)
-      }).then(res => { })  //"taurus://taurusclient/action/open_app?appId=" +  'phwj_h5-IYwQFALfovb3Jh27vAz2qe' + "&type=1&offline=false&url=" + encodeURIComponent('http://192.168.1.221:9081/api +  '/login?isLogin=1'')
-      return false;
-    } else if (code == 500) {
-      dd.toast({
-        text: res.data.msg
-      });
-      return Promise.reject(new Error(res.data.msg))
-    } else {
-      return Promise.resolve(res.data);
-    };
-  }, error => {
-    let { message } = error;
-    if (message == "Network Error") {
-      message = "网络异常,请稍后重试";
-    } else if (message.includes("timeout")) {
-      message = "系统接口请求超时";
-    } else {
-      message = "未知异常,请联系管理员";
-    }
-    dd.toast({
-      text: message
-    });
-    dd.hideLoading();
-    return Promise.reject(error);
-  })
-  axios.imgUrl = (actionName) => {
-    // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
-    return (axios.defaults.baseURL) + `/auth/file/manage/show/${localStorage.getItem('token')}?url=${encodeURIComponent('/' + actionName)}`;
-  }
-  return axios
-}

+ 58 - 0
until/request.js

@@ -0,0 +1,58 @@
+import axios from 'axios'
+import base from './base'
+
+
+axios.defaults.baseURL = 'http://192.168.1.88:8081/anzhi/'        //王宇浩的本地端口
+const http = axios.create({
+  timeout: 1000 * 300,
+  withCredentials: true,
+  headers: {
+    'Content-Type': 'application/json; charset=utf-8'
+  }
+})
+
+/**
+ * 请求拦截
+ */
+http.interceptors.request.use(config => {
+  console.log("请求拦截--------", config);
+  config.headers['token'] = window.localStorage.getItem('token') // 请求头带上token
+
+  return config
+}, error => {
+  return Promise.reject(error)
+})
+
+/**
+ * 响应拦截
+ */
+http.interceptors.response.use(response => {
+  console.log("response---响应拦截------", response);
+  if (response.data && response.data.code === 401) { // 401, token失效
+    ElementUI.Message.error("tooken失效,请重新登录");
+    let url = base.url + '/login'
+    let appId = base.appId
+    dd.openSchemeUrl({
+      url: "taurus://taurusclient/action/open_app?appId=" + appId + "&type=1&offline=false&url=" + encodeURIComponent(url)
+    }).then(res => { })
+  } else if (response.data.code < 0) {
+    if (response.data.code == -2) {
+      return response
+    } else {
+      ElementUI.Message.error(response.data.msg);
+      // 没有返回值会报错
+      return "错误"
+    }
+  } else {
+    return response
+  }
+}, error => {
+  console.log("error----------", error);
+})
+
+http.adornUrl = (s) => {
+  return 'proxyApi'
+}
+
+
+export default http;