import Taro from '@tarojs/taro' // 环境类型 export type EnvType = 'development' | 'production' // 环境配置接口 export interface EnvConfig { name: string apiBaseURL: string timeout: number enableLog: boolean enableMock: boolean // 客服配置 customerService: { corpId: string serviceUrl: string phoneNumber?: string email?: string } } // 各环境配置 const envConfigs: Record = { // 开发环境 development: { name: '开发环境', // apiBaseURL: 'https://tennis.bimwe.com', apiBaseURL: 'http://localhost:9098', timeout: 15000, enableLog: true, enableMock: false, // 客服配置 customerService: { corpId: 'ww51fc969e8b76af82', // 企业ID serviceUrl: 'https://work.weixin.qq.com/kfid/kfc64085b93243c5c91', } }, // 生产环境1 // production: { // name: '生产环境1', // apiBaseURL: 'https://tennis.bimwe.com', // timeout: 10000, // enableLog: false, // enableMock: false, // // 客服配置 // customerService: { // corpId: 'ww51fc969e8b76af82', // 企业ID // serviceUrl: 'https://work.weixin.qq.com/kfid/kfc64085b93243c5c91', // } // }, // 生产环境2 production: { name: '生产环境2', apiBaseURL: 'https://youchang.qiongjingtiyu.com', timeout: 10000, enableLog: false, enableMock: false, // 客服配置 customerService: { corpId: 'ww9a2d9a5d9410c664', // 企业ID serviceUrl: 'https://work.weixin.qq.com/kfid/kfcd355e162e0390684', } } } // 获取当前环境 export const getCurrentEnv = (): EnvType => { // 在小程序环境中,使用默认逻辑判断环境 // 可以根据实际需要配置不同的判断逻辑 // 可以根据实际部署情况添加更多判断逻辑 // 比如通过 Taro.getEnv() 获取当前平台环境 const isProd = process.env.NODE_ENV === 'production' if (isProd) { return 'production' } else { return 'development' } } // 获取当前环境配置 export const getCurrentConfig = (): EnvConfig => { const env = getCurrentEnv() return envConfigs[env] } // 获取指定环境配置 export const getEnvConfig = (env: EnvType): EnvConfig => { return envConfigs[env] } // 是否为开发环境 export const isDevelopment = (): boolean => { return getCurrentEnv() === 'development' } // 是否为生产环境 export const isProduction = (): boolean => { return getCurrentEnv() === 'production' } // 环境配置调试信息 export const getEnvInfo = () => { const config = getCurrentConfig() return { env: getCurrentEnv(), config, taroEnv: Taro.getEnv(), platform: Taro.getEnv() === Taro.ENV_TYPE.WEAPP ? '微信小程序' : Taro.getEnv() === Taro.ENV_TYPE.WEB ? 'Web' : Taro.getEnv() === Taro.ENV_TYPE.RN ? 'React Native' : '未知' } } // 导出当前环境配置(方便直接使用) export default getCurrentConfig()