初始化
This commit is contained in:
1 parent
34474bd5fc
commit
b638b541d0
3008 files changed
+837699
No files matched your search
@@ -0,0 +1,86 @@
|
||||
import axios from 'axios'
|
||||
import {
|
||||
matchTaskBoardMock,
|
||||
taskBoardMockAdapter,
|
||||
matchCopTaskDetailMock,
|
||||
copTaskDetailMockAdapter,
|
||||
} from '@/strategy-components/components/task-components/task-mock-data'
|
||||
import {
|
||||
matchSqReportMock,
|
||||
sqReportMockAdapter,
|
||||
} from '@/strategy-components/components/task-components/sq-report-mock-data'
|
||||
import { readRuntimeFlag } from '@/env'
|
||||
|
||||
// 任务看板(任务分析 / 三情分析)数据源开关:
|
||||
// VITE_USE_REAL_DATA=true → 走真实接口;其它(含未设置)→ 这两个接口走本地假数据。
|
||||
// 提交的 .env.development/.env.production/.env.network/.env.sit 默认 true(真实数据),
|
||||
// 仅本机 .env 默认 false(假数据)。改 env 后需重启 dev server 生效。
|
||||
const USE_REAL_DATA = readRuntimeFlag('VITE_USE_REAL_DATA')
|
||||
|
||||
// 任务详情(cop-task-detail,登录深链用)数据源开关:
|
||||
// 默认真实数据;仅当 VITE_MOCK_COP_TASK_DETAIL=true 时走本地假数据(consumer 外网不可达时调试用)。
|
||||
// 与 USE_REAL_DATA 独立。改 env 后需重启 dev server 生效。
|
||||
const MOCK_COP_TASK_DETAIL = readRuntimeFlag('VITE_MOCK_COP_TASK_DETAIL')
|
||||
|
||||
// 大屏绘制(selectSqReport)数据源开关:仅当开启时拦截为本地样例数据。
|
||||
const MOCK_SQ_REPORT = readRuntimeFlag('VITE_MOCK_SQ_REPORT')
|
||||
|
||||
// axios.interceptors
|
||||
const service = axios.create({
|
||||
// baseURL: '', // url = base url + request url
|
||||
// baseURL: '/api',
|
||||
// withCredentials: true, // send cookies when cross-domain requests
|
||||
timeout: 500000000*1000 // request timeout
|
||||
})
|
||||
|
||||
service.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
// if(!sessionStorage.getItem('userName')){
|
||||
// // window.location = '/#/lagchain-login'
|
||||
// }
|
||||
if (res.code !== 0) {
|
||||
return res
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
},
|
||||
error => {
|
||||
if(!error.response) return Promise.reject(error)
|
||||
if (error.response.status == 401) {
|
||||
// window.location = sessionStorage.getItem('mhUrl');
|
||||
} else {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
// 假数据模式:任务看板两个接口直接走本地 mock,不发真实请求(VITE_USE_REAL_DATA=true 时跳过)。
|
||||
if (!USE_REAL_DATA && matchTaskBoardMock(config.url)) {
|
||||
config.adapter = taskBoardMockAdapter as any;
|
||||
}
|
||||
// 任务详情(登录深链):默认真实接口;仅 VITE_MOCK_COP_TASK_DETAIL=true 时走本地假数据。
|
||||
if (MOCK_COP_TASK_DETAIL && matchCopTaskDetailMock(config.url)) {
|
||||
config.adapter = copTaskDetailMockAdapter as any;
|
||||
}
|
||||
// 大屏绘制:mock 模式下返回与真实 selectSqReport 完全相同的响应结构。
|
||||
if (MOCK_SQ_REPORT && matchSqReportMock(config.url)) {
|
||||
config.adapter = sqReportMockAdapter as any;
|
||||
}
|
||||
// let token: any = localStorage.getItem('token');
|
||||
config.headers['Authorization'] = `Bearer admin`;
|
||||
// if (token) {
|
||||
// token = JSON.parse(token);
|
||||
// // 在请求头中添加 token
|
||||
// config.headers['Authorization'] = `Bearer ${token.token}`;
|
||||
// }
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default service
|
||||
@@ -0,0 +1,46 @@
|
||||
import axios from 'axios'
|
||||
// axios.interceptors
|
||||
const toolsService = axios.create({
|
||||
// baseURL: '', // url = base url + request url
|
||||
// baseURL: '/api',
|
||||
// withCredentials: true, // send cookies when cross-domain requests
|
||||
timeout: 500000000*1000 // request timeout
|
||||
})
|
||||
|
||||
toolsService.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data
|
||||
// if(!sessionStorage.getItem('userName')){
|
||||
// // window.location = '/#/lagchain-login'
|
||||
// }
|
||||
if (res.code !== 0) {
|
||||
return res
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
},
|
||||
error => {
|
||||
if(!error.response) return Promise.reject(error)
|
||||
if (error.response.status == 401) {
|
||||
// window.location = sessionStorage.getItem('mhUrl');
|
||||
} else {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
toolsService.interceptors.request.use(
|
||||
config => {
|
||||
const token: any = localStorage.getItem('toolToken');
|
||||
if (token) {
|
||||
// 在请求头中添加 token
|
||||
config.headers['Authorization'] = `Bearer ${token}`;
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default toolsService
|
||||
Reference in new issue
Block a user