feat: fund-mobile支持Nginx子路径/fmobile部署

- 新增.env.development/.env.production环境配置
- vite.config.ts支持VITE_BASE动态base路径
- router使用import.meta.env.BASE_URL
- API baseURL使用环境变量
- 新增vite-env.d.ts类型声明
This commit is contained in:
zhangjf 2026-02-23 10:28:51 +08:00
parent bd5f8ab468
commit 1a5b583c2f
6 changed files with 71 additions and 41 deletions

View File

@ -0,0 +1,6 @@
# 开发环境配置
# 开发模式无部署前缀
VITE_BASE=/
# API基础路径开发模式使用代理
VITE_API_BASE_URL=

View File

@ -0,0 +1,6 @@
# 生产环境配置
# 部署路径前缀Nginx路由使用
VITE_BASE=/fmobile/
# API基础路径
VITE_API_BASE_URL=/fund

View File

@ -1,7 +1,7 @@
import axios from 'axios' import axios from 'axios'
const request = axios.create({ const request = axios.create({
baseURL: '/fund', baseURL: import.meta.env.VITE_API_BASE_URL || '/fund',
timeout: 15000, timeout: 15000,
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'

View File

@ -2,7 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
import { useTenantStore } from '@/stores/tenant' import { useTenantStore } from '@/stores/tenant'
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(import.meta.env.BASE_URL),
routes: [ routes: [
{ {
path: '/', path: '/',

10
fund-mobile/src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_BASE: string
readonly VITE_API_BASE_URL: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}

View File

@ -1,10 +1,17 @@
import { defineConfig } from 'vite' import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite' import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver' import { VantResolver } from '@vant/auto-import-resolver'
import { fileURLToPath, URL } from 'node:url' import { fileURLToPath, URL } from 'node:url'
export default defineConfig({ export default defineConfig(({ mode }) => {
// 加载环境变量
const env = loadEnv(mode, process.cwd())
const base = env.VITE_BASE || '/'
return {
// 部署路径前缀
base,
plugins: [ plugins: [
vue(), vue(),
Components({ Components({
@ -45,4 +52,5 @@ export default defineConfig({
} }
} }
} }
}
}) })