Files
2026-09-15 15:44:13 +07:00

64 lines
2.6 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:get/get.dart';
/// 付费引导场景(ping 下发 paymentGuide.scenes 的 key
enum GuideScene {
homeNewUser('HOME_NEW_USER'), //首页新用户引导(吸底)
homeOldUser('HOME_OLD_USER'), //首页老用户引导(吸底)
//新用户免费次数将尽引导(GuideFreeTrialSheet)。key 是 HOME_ 开头,但实际触发在播放页:
//newUnpay 用免费次数看视频且停留满5分钟
homeNewUserFreeTrial('HOME_NEW_USER_FREE_TRIAL'),
//文档叫「试看结束引导」,实际是需付费视频起播3秒的前置引导(真试看结束是 BuyVipAlert 硬拦截,不受开关管)
videoPreviewEnd('VIDEO_PREVIEW_END'),
videoBack('VIDEO_BACK'), //退出视频挽留
vipCenter('VIP_CENTER'), //会员中心引导
//会员内容上新:前端不读这个开关,横幅按分层 + 独立接口判断(见 GuidePushBanner),此项只为枚举完整
vipContentUpdate('VIP_CONTENT_UPDATE');
final String value;
const GuideScene(this.value);
/// 后端 key → 枚举,不认识的返回 null
static GuideScene? from(String? value) => values.firstWhereOrNull((e) => e.value == value);
}
/// 付费引导配置(/ping/domain 的 paymentGuide 字段)
/// 场景弹不弹全看这里的开关,触发时不再另发查询请求
class GuideConfig {
bool enabled = false; //全局开关,false 时所有场景都不展示
final scenes = <GuideScene, GuideSceneConfig>{};
GuideConfig.fromJson(Map<String, dynamic>? json) {
json ??= {};
enabled = json['enabled'] ?? false;
final map = json['scenes'];
if (map is! Map) return;
map.forEach((key, value) {
final scene = GuideScene.from('$key'); //前端不认识的场景直接丢
if (scene != null && value is Map) {
scenes[scene] = GuideSceneConfig.fromJson(Map<String, dynamic>.from(value));
}
});
}
}
/// 单场景配置:enabled && show 都为 true 才弹,触发几次弹几次,前端不改这两个值。
/// 后端另下发的 configId / style / durationSeconds 前端用不上,没解析
class GuideSceneConfig {
bool enabled = false;
bool show = false;
String? title;
String? description;
String? cover; //弹窗主图(设计稿那张「限时永久卡」),不是会员卡图
String? productId; //会员商品 id:按它取卡,跳会员页也选中它
GuideSceneConfig.fromJson(Map<String, dynamic>? json) {
json ??= {};
enabled = json['enabled'] ?? false;
show = json['show'] ?? false;
title = json['title'];
description = json['description'];
cover = json['cover'];
productId = json['productId'];
}
}