|
@@ -1,6 +1,19 @@
|
|
|
import Vue from 'vue';
|
|
|
import axios from 'axios';
|
|
|
import VueAxios from 'vue-axios';
|
|
|
+import getConfig from '../config/dev.js'
|
|
|
+let list = getConfig()
|
|
|
+const status = (res) => {
|
|
|
+ let regexp = /\d+\/api\//
|
|
|
+ let r = regexp.test(res)
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+// const Rstatus = (res) => {
|
|
|
+// let regexps = /8000/
|
|
|
+// let qr = regexps.test(res)
|
|
|
+// return qr;
|
|
|
+// }
|
|
|
// axios.defaults.headers.post['Content-Type'] = 'application/json';
|
|
|
axios.defaults.transformRequest = [function (data) {
|
|
|
if (data instanceof Object && !(data instanceof FormData)) {
|
|
@@ -8,36 +21,49 @@ axios.defaults.transformRequest = [function (data) {
|
|
|
}
|
|
|
return data;
|
|
|
}],
|
|
|
- // 添加请求拦截器
|
|
|
- axios.interceptors.request.use(function (config) {
|
|
|
- if (config.url.startsWith("http")) {
|
|
|
- return config;
|
|
|
- }
|
|
|
- let localhost = ''
|
|
|
- if (process.env.NODE_ENV == "production") {
|
|
|
- localhost = window.staticHost ? window.staticHost : "/spfm/"
|
|
|
- }
|
|
|
- config.url = localhost + config.url
|
|
|
- let url = localhost + config.url
|
|
|
- if (url.indexOf('/sysmgr/sys/login/auth/captcha') == -1 && url.indexOf('/sysmgr/sys/login/auth/token') == -1) {
|
|
|
- let token = window.sessionStorage.agileauthtoken;
|
|
|
- if (token != undefined && token != 'undefined') {
|
|
|
- token = JSON.parse(token);
|
|
|
+
|
|
|
+ axios.defaults.baseURL = list.BASE_URL
|
|
|
+// 添加请求拦截器
|
|
|
+axios.interceptors.request.use(function (config) {
|
|
|
+
|
|
|
+ var n = status(config.url)
|
|
|
+ // var s = Rstatus(config.url)
|
|
|
+
|
|
|
+ // console.log('[ axios.config ] >', config)
|
|
|
+ // if (config.url.startsWith("http")) {
|
|
|
+ // return config;
|
|
|
+ // }
|
|
|
+ // let localhost = ''
|
|
|
+ // if (process.env.NODE_ENV == "production") {
|
|
|
+ // localhost = window.staticHost ? window.staticHost : "/spfm/"
|
|
|
+ // }
|
|
|
+ // console.log('[ axios.localhost ] >', localhost)
|
|
|
+ // config.url = localhost + config.url
|
|
|
+ // let url = localhost + config.url
|
|
|
+ // console.log('[ axios.url ] >', url)
|
|
|
+
|
|
|
+ if (list.BASE_URL.indexOf('/sysmgr/sys/login/auth/captcha') == -1 && list.BASE_URL.indexOf('/sysmgr/sys/login/auth/token') == -1) {
|
|
|
+ let token = window.sessionStorage.agileauthtoken;
|
|
|
+ if (token != undefined && token != 'undefined') {
|
|
|
+ token = JSON.parse(token);
|
|
|
+ if (n === false) {
|
|
|
config.headers['agileauthtoken'] = token
|
|
|
- } else {
|
|
|
- global.$vm.$notify.error({
|
|
|
- title: '提示',
|
|
|
- message: '登录超时'
|
|
|
- })
|
|
|
- global.$vm.$router.push('/login')
|
|
|
}
|
|
|
+
|
|
|
+ } else {
|
|
|
+ global.$vm.$notify.error({
|
|
|
+ title: '提示',
|
|
|
+ message: '登录超时'
|
|
|
+ })
|
|
|
+ global.$vm.$router.push('/login')
|
|
|
}
|
|
|
- // 在发送请求之前做些什么
|
|
|
- return config;
|
|
|
- }, function (error) {
|
|
|
- // 对请求错误做些什么
|
|
|
- return Promise.reject(error);
|
|
|
- });
|
|
|
+ }
|
|
|
+ // 在发送请求之前做些什么
|
|
|
+ return config;
|
|
|
+}, function (error) {
|
|
|
+ // 对请求错误做些什么
|
|
|
+ return Promise.reject(error);
|
|
|
+});
|
|
|
|
|
|
|
|
|
// // 添加响应拦截器
|