From 7a03cc98a712a08ffe308c84fe69a63434425722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E4=B8=99?= <10604541+sanbing-os@user.noreply.gitee.com> Date: Sat, 13 Sep 2025 23:24:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ui=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=9A=84=E9=83=A8=E7=BD=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jcpp-web-ui/package.json | 3 ++- jcpp-web-ui/pom.xml | 2 +- jcpp-web-ui/src/components/Dashboard.tsx | 10 +++++----- jcpp-web-ui/src/services/api.ts | 23 ++++++++++++++++++++++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/jcpp-web-ui/package.json b/jcpp-web-ui/package.json index dbd9395..2b2ffc6 100644 --- a/jcpp-web-ui/package.json +++ b/jcpp-web-ui/package.json @@ -21,7 +21,8 @@ }, "scripts": { "start": "GENERATE_SOURCEMAP=false react-scripts start", - "build": "GENERATE_SOURCEMAP=false react-scripts build", + "build": "GENERATE_SOURCEMAP=false REACT_APP_ENV=development react-scripts build", + "build:prod": "GENERATE_SOURCEMAP=false REACT_APP_ENV=production react-scripts build", "eject": "react-scripts eject" }, "eslintConfig": { diff --git a/jcpp-web-ui/pom.xml b/jcpp-web-ui/pom.xml index 3b2831f..9e8a6b1 100644 --- a/jcpp-web-ui/pom.xml +++ b/jcpp-web-ui/pom.xml @@ -115,7 +115,7 @@ npm - run build + run build:prod diff --git a/jcpp-web-ui/src/components/Dashboard.tsx b/jcpp-web-ui/src/components/Dashboard.tsx index 9151032..dac5193 100644 --- a/jcpp-web-ui/src/components/Dashboard.tsx +++ b/jcpp-web-ui/src/components/Dashboard.tsx @@ -334,7 +334,7 @@ const Dashboard: React.FC = () => { border: '1px solid #f0f0f0', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)' }} - bodyStyle={{ padding: '20px' }} + styles={{ body: { padding: '20px' } }} > { border: '1px solid #f0f0f0', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)' }} - bodyStyle={{ padding: '20px' }} + styles={{ body: { padding: '20px' } }} > { border: '1px solid #f0f0f0', boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)' }} - bodyStyle={{ padding: '20px' }} + styles={{ body: { padding: '20px' } }} > { boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)', height: '380px' }} - bodyStyle={{ padding: '16px', height: '100%' }} + styles={{ body: { padding: '16px', height: '100%' } }} loading={loading} >
{ boxShadow: '0 1px 3px rgba(0, 0, 0, 0.1)', height: '380px' }} - bodyStyle={{ padding: '16px', height: '100%' }} + styles={{ body: { padding: '16px', height: '100%' } }} loading={loading} >
{ + // 如果设置了环境变量,优先使用环境变量 + if (process.env.REACT_APP_API_BASE_URL) { + return process.env.REACT_APP_API_BASE_URL; + } + + // 根据构建环境决定API基础URL + const env = process.env.REACT_APP_ENV || 'development'; + + if (env === 'production') { + // 生产环境:使用当前页面的协议和域名 + const protocol = window.location.protocol; + const host = window.location.host; + return `${protocol}//${host}`; + } else { + // 开发环境:使用localhost:8080 + return 'http://localhost:8080'; + } +}; + // 创建axios实例 const api = axios.create({ - baseURL: process.env.REACT_APP_API_BASE_URL || 'http://localhost:8080', + baseURL: getApiBaseUrl(), timeout: 10000, headers: { 'Content-Type': 'application/json;charset=UTF-8',