fix bugs
This commit is contained in:
70
src/config/env.config.js
Normal file
70
src/config/env.config.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 环境配置文件
|
||||
* 控制应用的数据源模式(Mock数据 或 真实API)
|
||||
*
|
||||
* 使用说明:
|
||||
* 1. Mock模式(UI演示、前端独立开发):设置 dataMode: 'mock'
|
||||
* 2. API模式(真实数据对接):设置 dataMode: 'api'
|
||||
* 3. 可在代码中动态切换模式
|
||||
*/
|
||||
|
||||
const ENV_CONFIG = {
|
||||
// 开发环境配置
|
||||
development: {
|
||||
// 数据模式: 'mock' | 'api'
|
||||
// mock - 使用本地Mock数据(保护UI版本)
|
||||
// api - 调用真实后端接口
|
||||
dataMode: 'api',
|
||||
|
||||
// API基础路径(dataMode为'api'时使用)
|
||||
apiBaseURL: 'http://localhost:8123',
|
||||
|
||||
// 请求超时时间(毫秒)
|
||||
timeout: 30000,
|
||||
|
||||
},
|
||||
|
||||
// 测试环境配置
|
||||
test: {
|
||||
dataMode: 'api',
|
||||
apiBaseURL: 'http://test-api.yourdomain.com',
|
||||
debug: true,
|
||||
timeout: 30000,
|
||||
mockDelay: 0
|
||||
},
|
||||
|
||||
// 生产环境配置
|
||||
production: {
|
||||
dataMode: 'api',
|
||||
apiBaseURL: 'https://api.yourdomain.com',
|
||||
debug: false,
|
||||
timeout: 30000,
|
||||
mockDelay: 0
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前环境(开发/测试/生产)
|
||||
const env = process.env.NODE_ENV || 'development'
|
||||
|
||||
// 导出当前环境的配置
|
||||
export default {
|
||||
...ENV_CONFIG[env],
|
||||
env
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速切换数据模式示例:
|
||||
*
|
||||
* // 在代码中使用
|
||||
* import config from '@/config/env.config.js'
|
||||
*
|
||||
* if (config.dataMode === 'mock') {
|
||||
* console.log('当前使用Mock数据')
|
||||
* } else {
|
||||
* console.log('当前使用真实API')
|
||||
* }
|
||||
*
|
||||
* // 查看当前环境
|
||||
* console.log('当前环境:', config.env)
|
||||
* console.log('数据模式:', config.dataMode)
|
||||
*/
|
||||
Reference in New Issue
Block a user