Files
harmony-client/entry/src/main/ets/data/repository/HomeRepository.ets
2026-09-11 20:47:51 +08:00

94 lines
2.9 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 { HomeData, HomeModule, IntroCard } from '../../model/HomeModels';
import { mockDelay } from './MockUtil';
/**
* 首页数据仓库契约。
*/
export abstract class HomeRepository {
abstract observeHome(): Promise<HomeData>;
abstract observeGuestHome(): Promise<HomeData>;
}
/**
* 本地 mock 实现:登录态与游客态两套 seed。
*/
export class FakeHomeRepository extends HomeRepository {
async observeHome(): Promise<HomeData> {
await mockDelay(250);
return FakeHomeRepository.seed(true);
}
async observeGuestHome(): Promise<HomeData> {
await mockDelay(250);
return FakeHomeRepository.seed(false);
}
private static seed(loggedIn: boolean): HomeData {
const data = new HomeData();
if (loggedIn) {
data.greeting = '晚上好';
data.displayName = '张三';
data.encouragement = '每日精进,持续成长';
} else {
data.greeting = '欢迎来到明缘云道场';
data.displayName = '游客';
data.encouragement = '登录后即可打卡、提交计划';
}
data.modules = FakeHomeRepository.buildModules();
data.intros = FakeHomeRepository.buildIntros();
return data;
}
private static buildModules(): HomeModule[] {
const checkin = new HomeModule();
checkin.id = 'checkin';
checkin.emoji = '📋';
checkin.title = '打卡介绍';
checkin.description = '每日打卡记录';
const plan = new HomeModule();
plan.id = 'plan';
plan.emoji = '📝';
plan.title = '计划介绍';
plan.description = '周/月/年计划';
const about = new HomeModule();
about.id = 'about';
about.emoji = 'ℹ️';
about.title = '关于我们';
about.description = '了解明缘云道场';
return [checkin, plan, about];
}
private static buildIntros(): IntroCard[] {
const list: IntroCard[] = [];
const learn = new IntroCard();
learn.emoji = '📚';
learn.heading = '学习成长工具';
learn.body = '明缘云道场是一款专注于个人成长的效率工具,通过每周打卡与计划管理,帮助你养成良好的学习习惯。';
list.push(learn);
const checkin = new IntroCard();
checkin.emoji = '✅';
checkin.heading = '周打卡';
checkin.body = '每周打卡,支持多种状态记录。查看小组打卡情况,与同学们互相监督、共同进步。';
list.push(checkin);
const plan = new IntroCard();
plan.emoji = '📝';
plan.heading = '计划管理';
plan.body = '提供周计划、月计划、年计划三级管理,支持文字与图片上传,让成长有迹可循。';
list.push(plan);
const group = new IntroCard();
group.emoji = '👥';
group.heading = '小组共学';
group.body = '加入学习小组,查看组员的打卡与计划完成情况,与志同道合的伙伴一起成长。';
list.push(group);
return list;
}
}