50 lines
2.1 KiB
Dart
50 lines
2.1 KiB
Dart
import 'package:new_learn/core/config/app_brand.dart';
|
||
import 'package:new_learn/core/config/app_env.dart';
|
||
import 'package:new_learn/core/theme/brand_theme.dart';
|
||
|
||
/// ============================================================
|
||
/// 【AppConfig】配置聚合层 —— 全项目唯一取配置入口
|
||
///
|
||
/// 组合规则(复刻 uni-app:appList × envList):
|
||
/// baseUrl = 品牌专属正式地址(prod 时覆盖) ?? 环境通用地址
|
||
/// appName = 品牌的名字(桌面图标名 / title)
|
||
/// theme = 按品牌的 themeId 查主题注册表(现有 BrandTheme 体系)
|
||
///
|
||
/// 消费方(Dio / TabApp / 页面)只 import 这里,不碰 AppEnv/AppBrand:
|
||
/// 1. ApiConfig.baseUrl → AppConfig.baseUrl
|
||
/// 2. TabApp theme/title → AppConfig.theme / AppConfig.appName
|
||
///
|
||
/// 三层解耦:
|
||
/// 环境 = 接口在哪(编译期定死) 品牌 = 这是谁家的 App(发布期定死)
|
||
/// 主题 = 长什么样(运行时可切换,与上面两层互不依赖)
|
||
/// ============================================================
|
||
class AppConfig {
|
||
AppConfig._();
|
||
|
||
/// 当前品牌(--dart-define=BRAND 指定;未知标识兜底回 aixue 防崩)
|
||
static AppBrand get currentBrand =>
|
||
appBrands[AppEnv.brand] ?? appBrands['aixue']!;
|
||
|
||
/// App 显示名(桌面图标名 / MaterialApp.title)
|
||
static String get appName => currentBrand.appName;
|
||
|
||
/// 接口地址:prod 用品牌专属地址(同 uni-app 按 appType 覆盖),
|
||
/// 其他环境用环境通用地址。
|
||
static String get baseUrl =>
|
||
AppEnv.isProd ? (currentBrand.baseUrl ?? AppEnv.baseUrl) : AppEnv.baseUrl;
|
||
|
||
/// 当前品牌对应的主题(查现有 BrandTheme 注册表)
|
||
static BrandTheme get theme {
|
||
for (final t in brandThemes) {
|
||
if (t.name == currentBrand.themeId) return t;
|
||
}
|
||
return brandThemes.first; // 未知 themeId 兜底第一个主题,防崩
|
||
}
|
||
|
||
/// 小游戏地址(预留,对标 envList.gameUrl)
|
||
static String get gameUrl => AppEnv.gameUrl;
|
||
|
||
/// 学习报告地址(预留,对标 envList.reportUrl)
|
||
static String get reportUrl => AppEnv.reportUrl;
|
||
}
|