feat: 拆分路由

This commit is contained in:
old burden 2026-04-17 14:20:54 +08:00
parent 162e57e80d
commit f9e5a33590
6 changed files with 66 additions and 31 deletions

View File

@ -1,7 +1,7 @@
# 接口地址
VITE_AMAP_KEY = 6888d721d30981b479ecdabd85f286fe
VITE_AMAP_SAFE_KEY = 23d3fdbc6b4eaf65d4a82a16510938c9
VITE_REGISTER_SOURCE = ALL
#VITE_REGISTER_SOURCE = XM001
VITE_SHOW_PAY = SUCCESS
VITE_API_URL = http://47.86.170.114:8011/api
VITE_AMAP_KEY=6888d721d30981b479ecdabd85f286fe
VITE_AMAP_SAFE_KEY=23d3fdbc6b4eaf65d4a82a16510938c9
VITE_REGISTER_SOURCE=ALL
#VITE_REGISTER_SOURCE=XM001
VITE_SHOW_PAY=SUCCESS
VITE_API_URL=http://111.230.37.169:10004/api

View File

@ -1,3 +1,4 @@
# 端口
VITE_PORT = 8887
VITE_API_URL = http://47.86.170.114:8011/api
# 端口(等号两侧不要空格,避免解析出带空格的 target
VITE_PORT=8887
# 仅 dev 时给 vite 代理用;若与 .env.development.local 冲突,以 .local 为准
VITE_API_URL=http://47.86.170.114:8011/api

View File

@ -1,3 +0,0 @@
# 是否生成打包分析图表
VITE_VISUALIZER = false
VITE_API_URL = https://api.undressing.name/api

View File

@ -20,8 +20,13 @@ const messages = i18n.global.messages[lang];
* @constant
* @desc 创建axios实例
*/
// Vite 仅注入 import.meta.envVITE_*);勿用 process.env.VUE_APP_BASE_APIVue CLI
// 开发:走相对路径 + vite 代理 /dev-api生产直连 .env 中的 VITE_API_URL与后端同域时可留空并在构建里写死路径
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
baseURL:
import.meta.env.MODE === 'development'
? ''
: (import.meta.env.VITE_API_URL || ''),
withCredentials: import.meta.env.MODE === 'development',
timeout: 600 * 1000
})

View File

@ -26,7 +26,8 @@ export default defineConfig({
less: {
modifyVars: {
'@size-9': '40px',
'arcoblue-6': '#e6217a'
// 主色:青霓虹(替代原品红),与暗色壳层搭配
'arcoblue-6': '#22d3ee'
}
}
}

View File

@ -1,24 +1,55 @@
import { defineConfig, mergeConfig, loadEnv } from 'vite'
import { dirname, resolve } from 'path'
import { fileURLToPath } from 'url'
import baseViteConfig from './vite.config'
const env = loadEnv('development', process.cwd())
const __dirname = dirname(fileURLToPath(import.meta.url))
/** 代理只能用「协议+主机+端口」,不能带 path否则转发路径容易错 */
function devProxyTarget(apiBaseUrl) {
if (!apiBaseUrl || typeof apiBaseUrl !== 'string') {
return ''
}
try {
const u = new URL(apiBaseUrl)
return `${u.protocol}//${u.host}`
} catch {
return ''
}
}
// 与 portal-ui 根目录一致加载 .env*ESM 下必须用 import.meta.url不能依赖未定义的 __dirname
const env = loadEnv('development', resolve(__dirname))
const apiBase = env.VITE_API_URL?.trim() || ''
const proxyTarget = devProxyTarget(apiBase)
if (!proxyTarget) {
console.warn(
'[vite] VITE_API_URL 未配置或无效,/dev-api 代理未启用。请在 .env.development 中设置例如VITE_API_URL=http://47.86.170.114:8011/api'
)
}
const devConfig = defineConfig({
server: {
host: env.VITE_HOST || 'localhost',
port: env.VITE_PORT || 8081,
port: Number(env.VITE_PORT) || 8081,
open: true,
watch: {
ignored: [/node_modules/, /dist/, /deploy/]
},
...(proxyTarget
? {
proxy: {
'/dev-api': {
target: env.VITE_API_URL,
target: proxyTarget,
ws: false,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev-api/, '')
}
}
}
: {})
}
})
export default mergeConfig(baseViteConfig, devConfig)