Blame view

html/config.js 2.34 KB
96009bc9   hexiaodong   hxd
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  /**
   * 绿纤协同平台配置文件
   * 用于管理不同环境的API地址配置
   */
  
  // 环境配置
  const ENV_CONFIG = {
    // 本地开发环境
    development: {
      name: '本地开发环境',
      apiBaseUrl: 'http://localhost:2011',
      description: '本地开发服务器'
    },
    
    // 正式环境
    production: {
      name: '正式环境',
      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 getEnvDescription() {
    return getCurrentConfig().description;
  }
  
  // 切换环境(用于开发调试)
  function switchEnvironment(env) {
    if (ENV_CONFIG[env]) {
      CURRENT_ENV = env;
      console.log(`已切换到${getEnvName()}: ${getApiBaseUrl()}`);
      
      // 触发环境切换事件
      window.dispatchEvent(new CustomEvent('envChanged', {
        detail: { environment: env, config: getCurrentConfig() }
      }));
      
      return true;
    } else {
      console.error(`未知环境: ${env}`);
      return false;
    }
  }
  
  // 获取所有可用环境
  function getAvailableEnvironments() {
    return Object.keys(ENV_CONFIG);
  }
  
  // 检查是否为开发环境
  function isDevelopment() {
    return CURRENT_ENV === 'development';
  }
  
  // 检查是否为生产环境
  function isProduction() {
    return CURRENT_ENV === 'production';
  }
  
  // 导出配置对象和函数
  window.APP_CONFIG = {
    // 配置对象
    ENV_CONFIG,
    
    // 当前环境
    CURRENT_ENV,
    
    // 函数
    getCurrentConfig,
    getApiBaseUrl,
    getEnvName,
    getEnvDescription,
    switchEnvironment,
    getAvailableEnvironments,
    isDevelopment,
    isProduction
  };
  
  // 在控制台输出当前配置信息
  console.log('🌱 绿纤协同平台配置已加载');
  console.log('=== 配置信息 ===');
  console.log('CURRENT_ENV 变量值:', CURRENT_ENV);
  console.log('当前环境名称:', getEnvName());
  console.log('当前API地址:', getApiBaseUrl());
  console.log('可用环境:', getAvailableEnvironments());
  console.log('=== 配置信息结束 ===');