From 750875be74cfab91a433322c3a58a51091101736 Mon Sep 17 00:00:00 2001 From: Agent Date: Sun, 29 Mar 2026 08:40:09 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E6=96=B9=E6=A1=88=E7=AE=A1=E7=90=86API=E5=92=8CH5=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone.yml | 4 ++-- .env.development | 3 +++ .env.production | 3 +++ .gitignore | 16 ++++++++++++++++ src/api/index.js | 2 +- src/pages/order/detail.vue | 2 +- vite.config.js | 28 +++++++++++++++++++--------- 7 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 .env.development create mode 100644 .env.production create mode 100644 .gitignore diff --git a/.drone.yml b/.drone.yml index 568739a..1cb1624 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,7 +28,7 @@ steps: - name: dev-build image: ccr.ccs.tencentyun.com/violin/node:22-bookworm commands: - - npm run build:h5 + - npm run build:h5 -- --mode development volumes: - name: node-cache path: /root/.npm @@ -85,7 +85,7 @@ steps: - name: prod-build image: ccr.ccs.tencentyun.com/violin/node:22-bookworm commands: - - npm run build:h5 + - npm run build:h5 -- --mode production volumes: - name: node-cache path: /root/.npm diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..bf04d81 --- /dev/null +++ b/.env.development @@ -0,0 +1,3 @@ +# 开发环境 +VITE_API_BASE_URL=http://localhost:8080/api/v1 +VITE_H5_BASE_URL=http://localhost:8080 \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..1d7e24a --- /dev/null +++ b/.env.production @@ -0,0 +1,3 @@ +# 生产环境 +VITE_API_BASE_URL=https://sales.violin-work.online/api/v1 +VITE_H5_BASE_URL=https://sales.violin-work.online \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2bed60 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# 本地环境变量覆盖(不提交) +.env.local +.env.*.local + +# 构建输出 +dist/ +unpackage/ + +# IDE +.idea/ +.vscode/ +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? \ No newline at end of file diff --git a/src/api/index.js b/src/api/index.js index e5a648a..00e7767 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -1,5 +1,5 @@ // API基础配置 -const BASE_URL = 'https://sales.violin-work.online/api/v1' +const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1' // 请求拦截器 const request = (url, method, query = {}, data = {}) => { diff --git a/src/pages/order/detail.vue b/src/pages/order/detail.vue index a59790a..a1140ec 100644 --- a/src/pages/order/detail.vue +++ b/src/pages/order/detail.vue @@ -217,7 +217,7 @@ export default { }, shareOrder() { // 构建分享链接(包含订单号和客户ID) - const h5BaseUrl = 'https://sales.violin-work.online/h5' + const h5BaseUrl = import.meta.env.VITE_H5_BASE_URL const customerId = this.order.customerId || '' const shareUrl = `${h5BaseUrl}/#/pages/share/order?orderNo=${this.order.orderNo}&customerId=${customerId}` diff --git a/vite.config.js b/vite.config.js index 0177f64..0b15f9a 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,14 +1,24 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import uni from '@dcloudio/vite-plugin-uni' -export default defineConfig({ - plugins: [ - uni() - ], - root: '.', - build: { - rollupOptions: { - input: './index.html' +export default defineConfig(({ mode }) => { + // 加载当前环境的环境变量 + const env = loadEnv(mode, process.cwd()) + + return { + plugins: [ + uni() + ], + root: '.', + build: { + rollupOptions: { + input: './index.html' + } + }, + define: { + // 注入环境变量到代码中 + 'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL || 'https://sales.violin-work.online/api/v1'), + 'import.meta.env.VITE_H5_BASE_URL': JSON.stringify(env.VITE_H5_BASE_URL || 'https://sales.violin-work.online') } } })