From 729bc3c70eeaa4d99193028e1ead100270d4377d Mon Sep 17 00:00:00 2001 From: kk <875203880@qq.com> Date: Wed, 15 Jul 2026 10:46:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=A2=84=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yaml | 4 ++++ src/config/env.js | 18 ++++++++++++++++-- src/config/staging.js | 20 ++++++++++++++++++++ vite.config.js | 4 ++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/config/staging.js diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 2d5abe9..74feb24 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -92,11 +92,15 @@ jobs: # 3. 安装依赖 & 构建 Uni-app (H5) ############################################### - name: Install dependencies and Build H5 + env: + DEPLOY_ENV: ${{ steps.detect.outputs.env }} run: | set -e # pnpm真实路径 PNPM_PATH="/root/.nvm/versions/node/v20.20.2/bin/pnpm" + echo "构建环境: DEPLOY_ENV=$DEPLOY_ENV" + # 1. 配置镜像并安装依赖 $PNPM_PATH config set registry https://registry.npmmirror.com $PNPM_PATH install --frozen-lockfile diff --git a/src/config/env.js b/src/config/env.js index 5cbe679..6303bf9 100644 --- a/src/config/env.js +++ b/src/config/env.js @@ -1,16 +1,30 @@ /** * 环境配置入口 - * 根据编译模式自动选择 dev / prod 配置 + * 根据编译模式自动选择 dev / staging / prod 配置 + * + * DEPLOY_ENV 环境变量: + * - 'staging' → 预发布环境 + * - 'production' → 生产环境(默认) + * - 未设置且 NODE_ENV !== 'production' → 开发环境 */ import common from './index.js'; import dev from './dev.js'; +import staging from './staging.js'; import prod from './prod.js'; // uni-app 编译时通过 define 注译 __UNI_PLATFORM__ // H5 开发模式下 process.env.NODE_ENV === 'development' const isProd = process.env.NODE_ENV === 'production'; +const deployEnv = process.env.DEPLOY_ENV; -const envConfig = isProd ? prod : dev; +let envConfig; +if (!isProd) { + envConfig = dev; +} else if (deployEnv === 'staging') { + envConfig = staging; +} else { + envConfig = prod; +} const config = { ...common, diff --git a/src/config/staging.js b/src/config/staging.js new file mode 100644 index 0000000..ec65909 --- /dev/null +++ b/src/config/staging.js @@ -0,0 +1,20 @@ +/** + * 预发布环境配置 + */ +const staging = { + // 业务 API 地址(vms-api) + apiBaseUrl: 'https://vmsapi.arklinksmart.cn', + + // 网关地址(vms-gateway)— 用户授权、短信等接口走网关 + apiGatewayUrl: 'https://gateway.arklinksmart.cn', + + // 授权回调地址(微信 OAuth redirect_uri,必须 HTTPS,指向前端页面) + authRedirectUri: 'https://pre-m.arklinksmart.cn/pages/auth/loading', + + // 生产环境 Token 从登录流程获取,此处为空 + bearerToken: '', + + enableRequestLog: false, +}; + +export default staging; diff --git a/vite.config.js b/vite.config.js index 33d370a..13a0cd4 100644 --- a/vite.config.js +++ b/vite.config.js @@ -26,6 +26,10 @@ function servePublicFiles() { export default defineConfig({ plugins: [servePublicFiles(), uni()], + // 将构建时的 DEPLOY_ENV 环境变量注入到客户端代码中 + define: { + 'process.env.DEPLOY_ENV': JSON.stringify(process.env.DEPLOY_ENV || ''), + }, css: { preprocessorOptions: { scss: {