更新
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
# 测试环境配置
|
||||
VITE_APP_TITLE=情绪博物馆
|
||||
VITE_API_BASE_URL=http://test-api.example.com/api
|
||||
VITE_WS_URL=ws://test-api.example.com/ws
|
||||
+19
-12
@@ -1,13 +1,20 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>mini-program</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<script>
|
||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||
CSS.supports('top: constant(a)'))
|
||||
document.write(
|
||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
<title></title>
|
||||
<!--preload-links-->
|
||||
<!--app-context-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"><!--app-html--></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 环境配置工具
|
||||
* 用于统一管理不同环境的配置
|
||||
*/
|
||||
|
||||
// 环境标识
|
||||
export const ENV = import.meta.env.MODE
|
||||
|
||||
// API 基础地址
|
||||
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
|
||||
|
||||
// WebSocket 地址
|
||||
export const WS_URL = import.meta.env.VITE_WS_URL
|
||||
|
||||
// 是否开启调试模式
|
||||
export const DEBUG = import.meta.env.VITE_DEBUG === 'true'
|
||||
|
||||
/**
|
||||
* 获取完整的 API 请求地址
|
||||
* @param path 接口路径,例如 '/user/login'
|
||||
* @returns 完整的请求地址
|
||||
*/
|
||||
export function getApiUrl(path: string): string {
|
||||
// 确保 path 以 / 开头
|
||||
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
||||
return `${API_BASE_URL}${normalizedPath}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为开发环境
|
||||
*/
|
||||
export function isDev(): boolean {
|
||||
return ENV === 'development'
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为生产环境
|
||||
*/
|
||||
export function isProd(): boolean {
|
||||
return ENV === 'production'
|
||||
}
|
||||
|
||||
export default {
|
||||
ENV,
|
||||
API_BASE_URL,
|
||||
WS_URL,
|
||||
DEBUG,
|
||||
getApiUrl,
|
||||
isDev,
|
||||
isProd
|
||||
}
|
||||
Reference in New Issue
Block a user