24 lines
625 B
TypeScript
24 lines
625 B
TypeScript
// 环境类型定义
|
|
type EnvVersion = 'develop' | 'trial' | 'release';
|
|
|
|
// 配置类型定义
|
|
interface EnvConfig {
|
|
apiBaseUrl: string;
|
|
}
|
|
|
|
// 获取当前环境
|
|
const accountInfo = wx.getAccountInfoSync();
|
|
const env = accountInfo.miniProgram.envVersion as EnvVersion;
|
|
|
|
// 环境配置映射
|
|
const config: Record<EnvVersion, EnvConfig> = {
|
|
develop: { apiBaseUrl: 'http://localhost:9096' },
|
|
trial: { apiBaseUrl: 'http://www.toutoukan.cn:9096' },
|
|
release: { apiBaseUrl: 'https://api.example.com' }
|
|
};
|
|
|
|
// 处理未知环境(兜底方案)
|
|
const envConfig = config[env] || config.develop;
|
|
|
|
export default envConfig;
|