config.js
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// 环境配置
const ENV_CONFIG = {
// 本地开发环境
development: {
name: '本地开发环境',
apiBaseUrl: 'http://erp_test.lvqianmeiye.com',
description: '本地开发服务器'
},
// 正式环境
production: {
name: '正式环境',
apiBaseUrl: 'http://erp_test.lvqianmeiye.com',
// apiBaseUrl: 'https://erp.lvqianmeiye.com',
// apiBaseUrl: 'http://lvqian.antissoft.com',
description: '生产环境服务器'
}
};
// 当前环境(可通过修改这里来切换环境)
let CURRENT_ENV = 'production'; // 默认使用正式环境
// 获取当前环境配置
function getCurrentConfig() {
return ENV_CONFIG[CURRENT_ENV] || ENV_CONFIG.production;
}
// 获取API基础地址
function getApiBaseUrl() {
return getCurrentConfig().apiBaseUrl;
}
// 获取环境名称
function getEnvName() {
return getCurrentConfig().name;
}
// 切换环境(用于开发调试)
function switchEnvironment(env) {
if (ENV_CONFIG[env]) {
CURRENT_ENV = env;
console.log(`已切换到${getEnvName()}: ${getApiBaseUrl()}`);
return true;
} else {
console.error(`未知环境: ${env}`);
return false;
}
}
// 获取图片基础地址
function getImgBaseUrl() {
return '';
}
// 导出配置
export default {
ENV_CONFIG,
CURRENT_ENV,
getCurrentConfig,
getApiBaseUrl,
getEnvName,
switchEnvironment,
getImgBaseUrl
};
// 兼容旧版本
export const BASE_URL = getApiBaseUrl();