diff --git a/.env.production b/.env.production index d330703..94051db 100644 --- a/.env.production +++ b/.env.production @@ -6,7 +6,8 @@ VITE_APP_PORT = 80 VITE_BASE_PATH = '/' # 应用模板管理后台/生产环境 -VITE_APP_BASE_API = 'https://xsynergy.gxtech.ltd' +# VITE_APP_BASE_API = 'https://xsynergy.gxtech.ltd' +VITE_APP_BASE_API = '' # 公网为“web” 私有化为不跳转为“private” 私有化跳转为“skip” VITE_APP_COOPERATION_TYPE = 'skip' diff --git a/dist.zip b/dist.zip index 496d99d..0f75221 100644 Binary files a/dist.zip and b/dist.zip differ diff --git a/src/utils/request.js b/src/utils/request.js index 90ab7b0..41af81c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -11,10 +11,27 @@ import router from '@/router'; import { useMeterStore } from '@/stores/modules/meter.js' axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8"; + +// 动态获取 baseURL +const getBaseURL = () => { + // 开发环境使用配置的完整 URL + if (import.meta.env.DEV) { + return import.meta.env.VITE_APP_BASE_API; + } + + // 生产环境使用相对路径 + // 返回空字符串,让浏览器自动使用当前域名 + return ''; + + // 或者如果后端 API 有固定路径前缀,可以这样设置: + // return '/api'; // 这样请求会变成 https://当前域名/api/xxx +}; + // 创建axios实例 const service = axios.create({ // axios中请求配置有baseURL选项,表示请求URL公共部分 - baseURL: import.meta.env.VITE_APP_BASE_API, + // baseURL: import.meta.env.VITE_APP_BASE_API, + baseURL: getBaseURL(), // 超时 // timeout: 10000, }); diff --git a/src/views/conferencingRoom/index.vue b/src/views/conferencingRoom/index.vue index 0b69db1..2bc50b6 100644 --- a/src/views/conferencingRoom/index.vue +++ b/src/views/conferencingRoom/index.vue @@ -11,24 +11,16 @@