修改打包配置 为后续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 = '' // var testUrl = ''
module.exports = merge(prodEnv, { module.exports = merge(prodEnv, {
NODE_ENV: '"development"', NODE_ENV: '"development"',
// API_ROOT: '/screen' API_ROOT: '"/screen"',
//API调用地址 //API调用地址
// API_ROOT: '"http://' + testUrl + '"', // API_ROOT: '"http://' + testUrl + '"',
// BASE_URL: '/cockpit-screen/' // 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.14:21624/'
// var testUrl = '192.168.0.166:8080' // var testUrl = '192.168.0.166:8080'
module.exports = { module.exports = {
NODE_ENV: 'production', NODE_ENV: '"production"',
API_ROOT: '"/screen"',
//post用当前域名 //post用当前域名
// API_ROOT: '"http://' + testUrl + '/iot"' // API_ROOT: '"http://' + testUrl + '/iot"'
// API_ROOT: '/', // API_ROOT: '/',

View File

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