diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..b2799fa 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,6 @@ + \ No newline at end of file diff --git a/mini-program/.env.test b/mini-program/.env.test deleted file mode 100644 index 6153875..0000000 --- a/mini-program/.env.test +++ /dev/null @@ -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 diff --git a/mini-program/index.html b/mini-program/index.html index d754fc8..0c02329 100644 --- a/mini-program/index.html +++ b/mini-program/index.html @@ -1,13 +1,20 @@ - - - - - - - mini-program - - -
- - + + + + + + + + + + +
+ + diff --git a/mini-program/src/utils/env.ts b/mini-program/src/utils/env.ts new file mode 100644 index 0000000..555d8f1 --- /dev/null +++ b/mini-program/src/utils/env.ts @@ -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 +}