根据环境变量控制重定向跳转地址
This commit is contained in:
parent
49c3a8fb50
commit
d1e35d9352
|
|
@ -8,8 +8,8 @@ VITE_API_URL = '/proxyApi'
|
|||
# VITE_proxyTarget = 'http://10.40.92.74:8080' #盛旭
|
||||
|
||||
# VITE_proxyTarget = 'http://192.168.2.246:28080' # 马帅
|
||||
VITE_proxyTarget = 'http://192.168.2.122:28080' # 梁超
|
||||
# VITE_proxyTarget = 'http://36.33.26.201:17788/proxyApi' # 测试服务
|
||||
# VITE_proxyTarget = 'http://192.168.2.122:28080' # 梁超
|
||||
VITE_proxyTarget = 'http://36.33.26.201:17788/proxyApi' # 测试服务
|
||||
# VITE_proxyTarget = 'http://192.168.0.244:28580' # 测试服务
|
||||
# VITE_proxyTarget = 'http://192.168.2.75:28080' # 盛旭
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ const handlerLogout = () => {
|
|||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
// router.push('/login') // 公司-重定向登录
|
||||
store.cleanUpToken('')
|
||||
store.clearUserInfo('')
|
||||
localStorage.clear()
|
||||
|
|
@ -65,12 +64,16 @@ const handlerLogout = () => {
|
|||
message: '已退出登录',
|
||||
duration: 1000,
|
||||
})
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
router.push('/login') // 公司-重定向登录
|
||||
} else {
|
||||
// 宏源-重定向登录
|
||||
setTimeout(() => {
|
||||
window.location.replace(
|
||||
'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
|
||||
)
|
||||
}, 500)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage({
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
import axios from 'axios'
|
||||
import NProgress from 'nprogress'
|
||||
// import { mainStore } from 'store/main'
|
||||
import { ElMessage } from "element-plus";
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { saveAs } from 'file-saver'
|
||||
import router from "@/router"
|
||||
import router from '@/router'
|
||||
// const store = mainStore()
|
||||
|
||||
// const CancelToken = axios.CancelToken
|
||||
|
|
@ -19,10 +19,9 @@ const iwsData: any = sessionStorage.getItem('data') || null
|
|||
|
||||
const service = axios.create({
|
||||
baseURL: baseUrl,
|
||||
timeout: 60000
|
||||
timeout: 60000,
|
||||
})
|
||||
|
||||
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
config.headers['Authorization'] = localStorage.getItem('tokenNew')
|
||||
|
|
@ -30,7 +29,7 @@ service.interceptors.request.use(
|
|||
},
|
||||
(error) => {
|
||||
return error
|
||||
}
|
||||
},
|
||||
)
|
||||
// 响应拦截
|
||||
service.interceptors.response.use(
|
||||
|
|
@ -41,40 +40,55 @@ service.interceptors.response.use(
|
|||
return data
|
||||
} else if (data.code == '403') {
|
||||
ElMessage.error('请重新登录')
|
||||
// 根据环境变量 VITE_API_URL 判断是否是本地开发环境
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
router.push('/login')
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
|
||||
window.location.replace(
|
||||
'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
|
||||
)
|
||||
}, 500)
|
||||
// router.push('/login')
|
||||
|
||||
}
|
||||
} else if (data.code == '401') {
|
||||
ElMessage.error('请登录')
|
||||
// router.push('/login')
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
router.push('/login')
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
|
||||
window.location.replace(
|
||||
'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
|
||||
)
|
||||
}, 500)
|
||||
}
|
||||
} else if (data.code == '500') {
|
||||
ElMessage({
|
||||
type: 'error',
|
||||
message: data.msg,
|
||||
duration: 1000,
|
||||
})
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
// ElMessage.error('请求失败')
|
||||
// console.log('error-异常', error)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
export function get(url: string, params: any) {
|
||||
if (iwsData) {
|
||||
service.get(`http://sgwpdm.ah.sgcc.com.cn/iws/cas/api/validate/sk?sessionKey=${iwsData.sessionKey}`).then((res: any) => {
|
||||
service
|
||||
.get(
|
||||
`http://sgwpdm.ah.sgcc.com.cn/iws/cas/api/validate/sk?sessionKey=${iwsData.sessionKey}`,
|
||||
)
|
||||
.then((res: any) => {
|
||||
console.log(res, '请求结果')
|
||||
if (res.code != 200) {
|
||||
window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
|
||||
window.location.replace(
|
||||
'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
|
||||
)
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
@ -100,14 +114,19 @@ export function get(url: string, params: any) {
|
|||
}
|
||||
export function post(url: string, params: any) {
|
||||
if (iwsData) {
|
||||
service.get(`http://sgwpdm.ah.sgcc.com.cn/iws/cas/api/validate/sk?sessionKey=${iwsData.sessionKey}`).then((res: any) => {
|
||||
service
|
||||
.get(
|
||||
`http://sgwpdm.ah.sgcc.com.cn/iws/cas/api/validate/sk?sessionKey=${iwsData.sessionKey}`,
|
||||
)
|
||||
.then((res: any) => {
|
||||
console.log(res, '请求结果')
|
||||
|
||||
if (res.code != 200) {
|
||||
window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
|
||||
window.location.replace(
|
||||
'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
|
@ -115,7 +134,7 @@ export function post(url: string, params: any) {
|
|||
// NProgress.start()
|
||||
service
|
||||
.post(url, params, {
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' }
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
||||
})
|
||||
.then((res: any) => {
|
||||
NProgress.done()
|
||||
|
|
@ -142,7 +161,7 @@ export function upload(url: string, params: any) {
|
|||
NProgress.start()
|
||||
service
|
||||
.post(url, formData, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
headers: { 'Content-Type': 'multipart/form-data' },
|
||||
})
|
||||
.then((res: any) => {
|
||||
NProgress.done()
|
||||
|
|
@ -160,38 +179,41 @@ export function upload(url: string, params: any) {
|
|||
}
|
||||
export function download(url: string, params: any, fileName: string = 'downloaded_file') {
|
||||
return new Promise((resolve, reject) => {
|
||||
NProgress.start(); // 开始进度条
|
||||
NProgress.start() // 开始进度条
|
||||
|
||||
service
|
||||
.post(url, params, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
responseType: 'blob' // 请求返回数据类型为 Blob(二进制流)
|
||||
responseType: 'blob', // 请求返回数据类型为 Blob(二进制流)
|
||||
})
|
||||
.then((res: any) => {
|
||||
NProgress.done(); // 结束进度条
|
||||
NProgress.done() // 结束进度条
|
||||
|
||||
// 判断返回的内容类型是否是 Blob
|
||||
const contentType = res.headers['content-type'] || '';
|
||||
if (!contentType.includes('application/octet-stream') && !contentType.includes('application/pdf')) {
|
||||
reject('文件类型不正确');
|
||||
return;
|
||||
const contentType = res.headers['content-type'] || ''
|
||||
if (
|
||||
!contentType.includes('application/octet-stream') &&
|
||||
!contentType.includes('application/pdf')
|
||||
) {
|
||||
reject('文件类型不正确')
|
||||
return
|
||||
}
|
||||
|
||||
// 处理文件下载
|
||||
const blob = new Blob([res.data], { type: contentType });
|
||||
const blob = new Blob([res.data], { type: contentType })
|
||||
|
||||
// 使用 file-saver 保存文件
|
||||
saveAs(blob, fileName);
|
||||
saveAs(blob, fileName)
|
||||
|
||||
resolve('文件下载成功');
|
||||
resolve('文件下载成功')
|
||||
})
|
||||
.catch((err) => {
|
||||
NProgress.done(); // 结束进度条
|
||||
reject(err?.data || '下载失败');
|
||||
});
|
||||
});
|
||||
NProgress.done() // 结束进度条
|
||||
reject(err?.data || '下载失败')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function put(url: string, params: any) {
|
||||
|
|
@ -199,7 +221,7 @@ export function put(url: string, params: any) {
|
|||
NProgress.start()
|
||||
service
|
||||
.put(url, params, {
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' }
|
||||
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
||||
})
|
||||
.then((res: any) => {
|
||||
NProgress.done()
|
||||
|
|
|
|||
|
|
@ -83,7 +83,6 @@ const handlerLogout = () => {
|
|||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
// router.push('/login') // 公司-登录
|
||||
store.cleanUpToken('')
|
||||
store.clearUserInfo('')
|
||||
localStorage.clear()
|
||||
|
|
@ -92,10 +91,14 @@ const handlerLogout = () => {
|
|||
type: 'success',
|
||||
message: '已退出登录',
|
||||
})
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
router.push('/login') // 公司-登录
|
||||
} else {
|
||||
// 宏源-登录
|
||||
setTimeout(() => {
|
||||
window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
|
||||
}, 500)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage({
|
||||
|
|
|
|||
|
|
@ -1103,12 +1103,15 @@ const onMainFileChange = (fileList: any) => {
|
|||
const isProd = origin.indexOf('sgwpdm.ah.sgcc.com.cn') > -1
|
||||
|
||||
const fileListTemp = fileList.map((e: any) => {
|
||||
let testUrl = ''
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
testUrl = e.url // 公司-测试环境
|
||||
} else {
|
||||
testUrl = origin + '/ahbns/' + e.url // 宏源-测试环境
|
||||
}
|
||||
return {
|
||||
fileName: e.name,
|
||||
fileUrl: isProd
|
||||
? 'http://sgwpdm.ah.sgcc.com.cn/iws/ahbns/' + e.url
|
||||
: origin + '/ahbns/' + e.url, // 宏源-测试环境
|
||||
// : e.url, // 公司-测试环境
|
||||
fileUrl: isProd ? 'http://sgwpdm.ah.sgcc.com.cn/iws/ahbns/' + e.url : testUrl,
|
||||
}
|
||||
})
|
||||
addAndEditFormRef.value.clearValidate('mainFileList')
|
||||
|
|
@ -1119,12 +1122,15 @@ const onDetailsFileChange = (fileList: any) => {
|
|||
const origin = window.location.origin
|
||||
const isProd = origin.indexOf('sgwpdm.ah.sgcc.com.cn') > -1
|
||||
const fileListTemp = fileList.map((e: any) => {
|
||||
let testUrl = ''
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
testUrl = e.url // 公司-测试环境
|
||||
} else {
|
||||
testUrl = origin + '/ahbns/' + e.url // 宏源-测试环境
|
||||
}
|
||||
return {
|
||||
fileName: e.name,
|
||||
fileUrl: isProd
|
||||
? 'http://sgwpdm.ah.sgcc.com.cn/iws/ahbns/' + e.url
|
||||
: origin + '/ahbns/' + e.url, // 宏源-测试环境
|
||||
// : e.url, // 公司-测试环境
|
||||
fileUrl: isProd ? 'http://sgwpdm.ah.sgcc.com.cn/iws/ahbns/' + e.url : testUrl,
|
||||
}
|
||||
})
|
||||
addAndEditFormRef.value.clearValidate('detailsFileList')
|
||||
|
|
@ -1163,12 +1169,15 @@ const onFileChangeEquip = (fileList: any, row: any, index: number, type: number)
|
|||
equipTableList.value[index].examinationPdf = []
|
||||
}
|
||||
const fileListTemp = fileList.map((e: any) => {
|
||||
let testUrl = ''
|
||||
if (import.meta.env.VITE_API_URL == '/proxyApi') {
|
||||
testUrl = e.url // 公司-测试环境
|
||||
} else {
|
||||
testUrl = origin + '/ahbns/' + e.url // 宏源-测试环境
|
||||
}
|
||||
return {
|
||||
fileName: e.name,
|
||||
fileUrl: isProd
|
||||
? 'http://sgwpdm.ah.sgcc.com.cn/iws/ahbns/' + e.url
|
||||
: origin + '/ahbns/' + e.url, // 宏源-测试环境
|
||||
// : e.url, // 公司-测试环境
|
||||
fileUrl: isProd ? 'http://sgwpdm.ah.sgcc.com.cn/iws/ahbns/' + e.url : testUrl,
|
||||
}
|
||||
})
|
||||
console.log('11111', fileListTemp[0].fileUrl)
|
||||
|
|
|
|||
Loading…
Reference in New Issue