修改打包配置 为后续ng重新配置作准备

This commit is contained in:
BianLzhaoMin 2024-09-12 10:19:26 +08:00
parent 43aa148f9d
commit ad70d31465
3 changed files with 36 additions and 26 deletions

View File

@ -13,7 +13,7 @@ var testUrl = '10.40.92.8:8080'
// var testUrl = ''
module.exports = merge(prodEnv, {
NODE_ENV: '"development"',
// API_ROOT: '/screen'
API_ROOT: '"/screen"',
//API调用地址
// API_ROOT: '"http://' + testUrl + '"',
// BASE_URL: '/cockpit-screen/'

View File

@ -3,7 +3,8 @@ var testUrl = '112.29.103.165:21624/'
// var testUrl = '192.168.0.14:21624/'
// var testUrl = '192.168.0.166:8080'
module.exports = {
NODE_ENV: 'production',
NODE_ENV: '"production"',
API_ROOT: '"/screen"',
//post用当前域名
// API_ROOT: '"http://' + testUrl + '/iot"'
// API_ROOT: '/',

View File

@ -1,29 +1,32 @@
/**
* axios全局配置
*/
import axios from 'axios';
import axios from 'axios'
axios.defaults.timeout = 30000
// 默认配置
axios.defaults.baseURL = '';
axios.defaults.baseURL = ''
console.log(process.env.NODE_ENV, '当前环境变量-----')
console.log(process.env.API_ROOT, '当前环境代理')
axios.interceptors.request.use(
config => {
(config) => {
let token = localStorage.getItem('token')
if (token) {
config.headers.accessToken = `${token}`;
config.headers.Authorization = `${token}`;
config.headers.accessToken = `${token}`
config.headers.Authorization = `${token}`
}
return config;
return config
},
error => {
return Promise.reject(error);
(error) => {
return Promise.reject(error)
}
);
)
// 添加一个请求拦截器
axios.interceptors.response.use(
response => {
(response) => {
if (response.data) {
if (response.data.code === 401) {
} else if (response.data.code === 200) {
@ -34,30 +37,36 @@ axios.interceptors.response.use(
} else {
return Promise.reject(response.data)
}
},
error => {
if (error.code === 'ECONNABORTED' && error.message.indexOf('timeout') !== -1)
(error) => {
if (
error.code === 'ECONNABORTED' &&
error.message.indexOf('timeout') !== -1
)
console.log('请求超时!')
return Promise.reject(error)
}
);
)
// 通用POST方法
export const POST = (url, params) => {
return axios.post(`${url}`, params).then(response => response);
};
return axios.post(`${url}`, params).then((response) => response)
}
// 通用POST_JSON方法
export const POST_JSON = (url, json, params) => {
return axios.post(`${url}`, json, {
params: params
}).then(response => response);
};
return axios
.post(`${url}`, json, {
params: params,
})
.then((response) => response)
}
// 通用GET方法
export const GET = (url, params) => {
return axios.get(`${url}`, {
params: params
}).then(response => response);
};
return axios
.get(`${url}`, {
params: params,
})
.then((response) => response)
}