diff --git a/src/services/http.ts b/src/services/http.ts index d8aafe3..f4934a4 100644 --- a/src/services/http.ts +++ b/src/services/http.ts @@ -1,3 +1,4 @@ + import { message } from 'ant-design-vue'; import axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios'; @@ -27,15 +28,25 @@ http.interceptors.request.use( async (config) => { try { let token = ''; - let tenantId = ''; - + + let tenantId = import.meta.env.ENV_DEV_TENANT_ID; // 开发环境处理逻辑 if (import.meta.env.DEV) { try { - token = import.meta.env.ENV_DEV_TOKEN; - tenantId = import.meta.env.ENV_DEV_TENANT_ID; + // 先尝试从本地服务获取token + const response = await axios.get('http://localhost:9000/api/token', { timeout: 3000 }); + if (response.data.success) { + console.log('使用中间服务获取的token ing'); + token = response.data.token; + } } catch (error) { - console.error('获取开发环境token失败:', error); + console.warn(error+'本地token服务不可用,使用环境变量token'); + } + + // 如果本地服务失败,使用环境变量 + if (!token) { + token = import.meta.env.ENV_DEV_TOKEN; + } } else { // 生产环境直接从localStorage获取