diff --git a/fund-mobile/.env.development b/fund-mobile/.env.development new file mode 100644 index 0000000..68e9a47 --- /dev/null +++ b/fund-mobile/.env.development @@ -0,0 +1,6 @@ +# 开发环境配置 +# 开发模式无部署前缀 +VITE_BASE=/ + +# API基础路径(开发模式使用代理) +VITE_API_BASE_URL= diff --git a/fund-mobile/.env.production b/fund-mobile/.env.production new file mode 100644 index 0000000..c530c4a --- /dev/null +++ b/fund-mobile/.env.production @@ -0,0 +1,6 @@ +# 生产环境配置 +# 部署路径前缀(Nginx路由使用) +VITE_BASE=/fmobile/ + +# API基础路径 +VITE_API_BASE_URL=/fund diff --git a/fund-mobile/src/api/request.ts b/fund-mobile/src/api/request.ts index 7b9b96c..29a4181 100644 --- a/fund-mobile/src/api/request.ts +++ b/fund-mobile/src/api/request.ts @@ -1,7 +1,7 @@ import axios from 'axios' const request = axios.create({ - baseURL: '/fund', + baseURL: import.meta.env.VITE_API_BASE_URL || '/fund', timeout: 15000, headers: { 'Content-Type': 'application/json' diff --git a/fund-mobile/src/router/index.ts b/fund-mobile/src/router/index.ts index 8a8ecc1..a3a3958 100644 --- a/fund-mobile/src/router/index.ts +++ b/fund-mobile/src/router/index.ts @@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router' import { useTenantStore } from '@/stores/tenant' const router = createRouter({ - history: createWebHistory(), + history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/', diff --git a/fund-mobile/src/vite-env.d.ts b/fund-mobile/src/vite-env.d.ts new file mode 100644 index 0000000..04f1a77 --- /dev/null +++ b/fund-mobile/src/vite-env.d.ts @@ -0,0 +1,10 @@ +/// + +interface ImportMetaEnv { + readonly VITE_BASE: string + readonly VITE_API_BASE_URL: string +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} diff --git a/fund-mobile/vite.config.ts b/fund-mobile/vite.config.ts index 00576e6..557c401 100644 --- a/fund-mobile/vite.config.ts +++ b/fund-mobile/vite.config.ts @@ -1,47 +1,55 @@ -import { defineConfig } from 'vite' +import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import Components from 'unplugin-vue-components/vite' import { VantResolver } from '@vant/auto-import-resolver' import { fileURLToPath, URL } from 'node:url' -export default defineConfig({ - plugins: [ - vue(), - Components({ - resolvers: [VantResolver()] - }) - ], - resolve: { - alias: { - '@': fileURLToPath(new URL('./src', import.meta.url)) - } - }, - server: { - port: 8080, - proxy: { - '/sys': { - target: 'http://localhost:8000', - changeOrigin: true - }, - '/cust': { - target: 'http://localhost:8000', - changeOrigin: true - }, - '/proj': { - target: 'http://localhost:8000', - changeOrigin: true - }, - '/exp': { - target: 'http://localhost:8000', - changeOrigin: true - }, - '/receipt': { - target: 'http://localhost:8000', - changeOrigin: true - }, - '/file': { - target: 'http://localhost:8000', - changeOrigin: true +export default defineConfig(({ mode }) => { + // 加载环境变量 + const env = loadEnv(mode, process.cwd()) + const base = env.VITE_BASE || '/' + + return { + // 部署路径前缀 + base, + plugins: [ + vue(), + Components({ + resolvers: [VantResolver()] + }) + ], + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + }, + server: { + port: 8080, + proxy: { + '/sys': { + target: 'http://localhost:8000', + changeOrigin: true + }, + '/cust': { + target: 'http://localhost:8000', + changeOrigin: true + }, + '/proj': { + target: 'http://localhost:8000', + changeOrigin: true + }, + '/exp': { + target: 'http://localhost:8000', + changeOrigin: true + }, + '/receipt': { + target: 'http://localhost:8000', + changeOrigin: true + }, + '/file': { + target: 'http://localhost:8000', + changeOrigin: true + } } } }