Files
2026-09-04 15:22:20 +08:00

28 lines
1.1 KiB
Dart

/// ============================================================
/// 【ImgUrl】图片地址工具 —— 对标 UniApp utils/image.js 的 $img
///
/// 规则(与原 $img 完全一致):
/// 1. 空值 / 纯空白 → 返回空串
/// 2. 以 http 开头 → 原样返回(已是完整 URL)
/// 3. 以 /static/ 开头 → 原样返回(小程序本地资源;Flutter 端此类
/// 资源应改用 Image.asset / Material Icon,不能直接加载网络)
/// 4. 其余 → 拼 CDN 域名返回完整 URL
/// ============================================================
class ImgUrl {
ImgUrl._();
/// 图片 CDN 域名(对标 image.js 的 IMG_URL;旧域名 hx.23544.com 已弃用)。
/// TODO(业务逻辑): 如需按环境切换,可迁移进 AppEnv 的 _envTable。
static const String _cdn = 'https://hx.cnzhyx.cn';
/// 等价 Vue 的 $img(path)
static String build(String? path) {
if (path == null) return '';
final s = path.trim();
if (s.isEmpty) return '';
if (s.startsWith('http')) return s;
if (s.startsWith('/static/')) return s;
return '$_cdn$s';
}
}