flat: 添加替换字符串
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
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_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,10 +17,11 @@ import {Message} from 'element-ui';
|
||||
import {Base64} from 'js-base64';
|
||||
import NProgress from 'nprogress';
|
||||
|
||||
const replaceStr = JSON.parse(process.env.VUE_APP_REPLACE_STR)
|
||||
//默认超时时间
|
||||
axios.defaults.timeout = 60000;
|
||||
//返回其他状态码
|
||||
axios.defaults.validateStatus = function(status) {
|
||||
axios.defaults.validateStatus = function (status) {
|
||||
return status >= 200 && status <= 500;
|
||||
};
|
||||
//跨域请求,允许保存cookie
|
||||
@@ -44,7 +45,9 @@ axios.interceptors.request.use(config => {
|
||||
config.data = serialize(config.data);
|
||||
}
|
||||
return config
|
||||
}, error => {return Promise.reject(error)});
|
||||
}, error => {
|
||||
return Promise.reject(error)
|
||||
});
|
||||
// http response 拦截
|
||||
axios.interceptors.response.use(
|
||||
res => {
|
||||
@@ -72,7 +75,7 @@ axios.interceptors.response.use(
|
||||
Message({message: message, type: 'error'});
|
||||
return Promise.reject(err, res)
|
||||
}
|
||||
return res;
|
||||
return transformReplaceStr(res);
|
||||
},
|
||||
error => {
|
||||
NProgress.done();
|
||||
@@ -82,4 +85,28 @@ axios.interceptors.response.use(
|
||||
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;
|
||||
|
||||
@@ -23,7 +23,7 @@ module.exports = {
|
||||
port: 1888,
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: 'http://10.165.0.173 :8000',
|
||||
target: 'http://192.168.1.108:8000',
|
||||
ws: true,
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
|
||||
Reference in New Issue
Block a user