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,47 +1,55 @@
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 }) => {
plugins: [ // 加载环境变量
vue(), const env = loadEnv(mode, process.cwd())
Components({ const base = env.VITE_BASE || '/'
resolvers: [VantResolver()]
}) return {
], // 部署路径前缀
resolve: { base,
alias: { plugins: [
'@': fileURLToPath(new URL('./src', import.meta.url)) vue(),
} Components({
}, resolvers: [VantResolver()]
server: { })
port: 8080, ],
proxy: { resolve: {
'/sys': { alias: {
target: 'http://localhost:8000', '@': fileURLToPath(new URL('./src', import.meta.url))
changeOrigin: true }
}, },
'/cust': { server: {
target: 'http://localhost:8000', port: 8080,
changeOrigin: true proxy: {
}, '/sys': {
'/proj': { target: 'http://localhost:8000',
target: 'http://localhost:8000', changeOrigin: true
changeOrigin: true },
}, '/cust': {
'/exp': { target: 'http://localhost:8000',
target: 'http://localhost:8000', changeOrigin: true
changeOrigin: true },
}, '/proj': {
'/receipt': { target: 'http://localhost:8000',
target: 'http://localhost:8000', changeOrigin: true
changeOrigin: true },
}, '/exp': {
'/file': { target: 'http://localhost:8000',
target: 'http://localhost:8000', changeOrigin: true
changeOrigin: true },
'/receipt': {
target: 'http://localhost:8000',
changeOrigin: true
},
'/file': {
target: 'http://localhost:8000',
changeOrigin: true
}
} }
} }
} }