flat: 添加替换字符串
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
VUE_APP_SITE='default'
|
VUE_APP_SITE='default'
|
||||||
VUE_APP_LOGIN_ERROR = 'http://10.160.7.216:9920/casserver/login'
|
VUE_APP_LOGIN_ERROR = http://10.160.7.216:9920/casserver/login
|
||||||
|
VUE_APP_REPLACE_STR = {"{oss_file_url}": "https://dy12333.org.cn/api"}
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
VUE_APP_SITE='default'
|
VUE_APP_SITE='default'
|
||||||
VUE_APP_LOGIN_ERROR = 'http://10.160.7.216:9920/casserver/login'
|
VUE_APP_LOGIN_ERROR = http://10.160.7.216:9920/casserver/login
|
||||||
|
VUE_APP_REPLACE_STR = {"{oss_file_url}": "https://dy12333.org.cn/api"}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {Message} from 'element-ui';
|
|||||||
import {Base64} from 'js-base64';
|
import {Base64} from 'js-base64';
|
||||||
import NProgress from 'nprogress';
|
import NProgress from 'nprogress';
|
||||||
|
|
||||||
|
const replaceStr = JSON.parse(process.env.VUE_APP_REPLACE_STR)
|
||||||
//默认超时时间
|
//默认超时时间
|
||||||
axios.defaults.timeout = 60000;
|
axios.defaults.timeout = 60000;
|
||||||
//返回其他状态码
|
//返回其他状态码
|
||||||
@@ -44,7 +45,9 @@ axios.interceptors.request.use(config => {
|
|||||||
config.data = serialize(config.data);
|
config.data = serialize(config.data);
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}, error => {return Promise.reject(error)});
|
}, error => {
|
||||||
|
return Promise.reject(error)
|
||||||
|
});
|
||||||
// http response 拦截
|
// http response 拦截
|
||||||
axios.interceptors.response.use(
|
axios.interceptors.response.use(
|
||||||
res => {
|
res => {
|
||||||
@@ -72,7 +75,7 @@ axios.interceptors.response.use(
|
|||||||
Message({message: message, type: 'error'});
|
Message({message: message, type: 'error'});
|
||||||
return Promise.reject(err, res)
|
return Promise.reject(err, res)
|
||||||
}
|
}
|
||||||
return res;
|
return transformReplaceStr(res);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
NProgress.done();
|
NProgress.done();
|
||||||
@@ -82,4 +85,28 @@ axios.interceptors.response.use(
|
|||||||
return Promise.reject(new Error(error), error);
|
return Promise.reject(new Error(error), error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 递归替换 url
|
||||||
|
function transformReplaceStr(props) {
|
||||||
|
if (typeof props !== 'object' || props === null) {
|
||||||
|
for (const key in replaceStr) {
|
||||||
|
if (typeof props === 'string') {
|
||||||
|
props = props.replace(key, replaceStr[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
let result;
|
||||||
|
if (props instanceof Array) {
|
||||||
|
result = [];
|
||||||
|
} else {
|
||||||
|
result = {};
|
||||||
|
}
|
||||||
|
for (let key in props) {
|
||||||
|
if (props.hasOwnProperty(key)) {
|
||||||
|
result[key] = transformReplaceStr(props[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
export default axios;
|
export default axios;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ module.exports = {
|
|||||||
port: 1888,
|
port: 1888,
|
||||||
proxy: {
|
proxy: {
|
||||||
"/api": {
|
"/api": {
|
||||||
target: 'http://10.165.0.173 :8000',
|
target: 'http://192.168.1.108:8000',
|
||||||
ws: true,
|
ws: true,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: {
|
pathRewrite: {
|
||||||
|
|||||||
Reference in New Issue
Block a user