From 07cf8e884e249d3ce35fd141b3a87b807beed995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Sat, 7 Feb 2026 20:24:45 +0800 Subject: [PATCH] 1 --- src/config/env.ts | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/config/env.ts diff --git a/src/config/env.ts b/src/config/env.ts new file mode 100644 index 0000000..5fd7f75 --- /dev/null +++ b/src/config/env.ts @@ -0,0 +1,135 @@ +import Taro from '@tarojs/taro' + +// 环境类型 +export type EnvType = 'development' | 'production' + +// 环境配置接口 +export interface EnvConfig { + name: string + apiBaseURL: string + ossBaseURL: 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', + ossBaseURL: 'https://bimwe.oss-cn-shanghai.aliyuncs.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', + ossBaseURL: 'https://bimwe.oss-cn-shanghai.aliyuncs.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', + // ossBaseURL: 'https://youchang2026.oss-cn-shanghai.aliyuncs.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() \ No newline at end of file