Files
ios-client/IosClientKit/Sources/CoreRepository/FakeHomeRepository.swift

66 lines
2.9 KiB
Swift
Raw Permalink 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 CoreCommon
import CoreDomain
import CoreModel
/// Fake 首页仓库(骨架阶段返回假数据,后续替换为 OfflineFirst 实现)。
public struct FakeHomeRepository: HomeRepository {
public init() {}
public func observeHome() -> AsyncThrowingStream<HomeData, Error> {
stream(Self.loggedInData)
}
public func observeGuestHome() -> AsyncThrowingStream<HomeData, Error> {
stream(Self.guestData)
}
private func stream(_ data: HomeData) -> AsyncThrowingStream<HomeData, Error> {
AsyncThrowingStream { continuation in
let task = Task {
do {
// 模拟网络延迟。
try await Task.sleep(for: .milliseconds(400))
try Task.checkCancellation()
Logger.info("FakeHomeRepository 返回假数据")
continuation.yield(data)
continuation.finish()
} catch {
continuation.finish(throwing: error)
}
}
continuation.onTermination = { _ in
task.cancel()
}
}
}
private static let modules = [
HomeModule(id: "checkin", emoji: "📋", title: "打卡介绍", description: "每日打卡记录", destination: .checkin),
HomeModule(id: "plan", emoji: "📝", title: "计划介绍", description: "周/月/年计划", destination: .plan),
HomeModule(id: "about", emoji: "ℹ️", title: "关于我们", description: "了解明缘云道场", destination: .about),
]
private static let intros = [
IntroCard(title: "📚 学习成长工具", body: "明缘云道场是一款专注于个人成长的效率工具,通过每周打卡与计划管理,帮助你养成良好的学习习惯,实现持续进步。好好学习,天天向上。"),
IntroCard(title: "✅ 周打卡", body: "每周打卡,支持多种状态记录(正常、迟到、请假、早退、不参加讨论等)。查看小组打卡情况,与同学们互相监督、共同进步。"),
IntroCard(title: "📝 计划管理", body: "提供周计划、月计划、年计划三级管理,支持文字与图片上传。清晰追踪每个周期的目标完成情况,让成长有迹可循。"),
IntroCard(title: "👥 小组共学", body: "加入学习小组,查看组员的打卡与计划完成情况。在集体的氛围中保持学习动力,与志同道合的伙伴一起成长。"),
]
private static let guestData = HomeData(
greeting: "欢迎来到明缘云道场",
displayName: "游客",
encouragement: "登录后即可打卡、提交计划",
modules: modules,
intros: intros
)
private static let loggedInData = HomeData(
greeting: "晚上好",
displayName: "张三",
encouragement: "坚持每周打卡,与小组共同进步。",
modules: modules,
intros: intros
)
}