feat(entry): 新增本地 mock 数据层

This commit is contained in:
AndyChen1024
2026-09-11 20:47:51 +08:00
parent b390dbf214
commit 28fc0a1026
6 changed files with 308 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
import { CheckinRecord, CheckinStatus, GroupMember, PersonalCheckinRecord } from '../../model/CheckinModels';
import { mockDelay } from './MockUtil';
/**
* 打卡数据仓库契约。
*/
export abstract class CheckinRepository {
abstract observeCheckin(): Promise<CheckinRecord>;
abstract submitCheckin(status: string): Promise<CheckinRecord>;
}
/**
* 本地 mock 实现:内存 seed,提交更新自身状态。
*/
export class FakeCheckinRepository extends CheckinRepository {
private record: CheckinRecord = FakeCheckinRepository.seed();
async observeCheckin(): Promise<CheckinRecord> {
await mockDelay(250);
return this.record;
}
async submitCheckin(status: string): Promise<CheckinRecord> {
await mockDelay(300);
this.record.checked = true;
this.record.status = status;
// 更新"我"(第一个成员)在小组成员列表里的状态
if (this.record.groupMembers.length > 0) {
const me = this.record.groupMembers[0];
me.checkedIn = true;
me.status = status;
me.checkinTime = '今天 09:12';
}
return this.record;
}
private static seed(): CheckinRecord {
const r = new CheckinRecord();
r.classDate = '2026-09-06';
r.weekday = '周日';
r.dayNum = '06';
r.checked = false;
r.status = '';
r.groupName = '进阶一组';
r.groupMembers = [
FakeCheckinRepository.member('u-1001', '张三', false, '', ''),
FakeCheckinRepository.member('u-1002', '李四', true, CheckinStatus.NORMAL, '今天 09:05'),
FakeCheckinRepository.member('u-1003', '王五', true, CheckinStatus.LATE, '今天 09:18'),
FakeCheckinRepository.member('u-1004', '赵六', false, '', ''),
FakeCheckinRepository.member('u-1005', '孙七', true, CheckinStatus.LEAVE, '今天 08:40')
];
r.personalHistory = [
FakeCheckinRepository.history('h-1', '2026-08-30', CheckinStatus.NORMAL, '08:52'),
FakeCheckinRepository.history('h-2', '2026-08-23', CheckinStatus.LATE, '09:21'),
FakeCheckinRepository.history('h-3', '2026-08-16', CheckinStatus.ABSENT, '--')
];
return r;
}
private static member(id: string, name: string, checkedIn: boolean, status: string, checkinTime: string): GroupMember {
const m = new GroupMember();
m.id = id;
m.name = name;
m.checkedIn = checkedIn;
m.status = status;
m.checkinTime = checkinTime;
return m;
}
private static history(id: string, date: string, status: string, time: string): PersonalCheckinRecord {
const h = new PersonalCheckinRecord();
h.id = id;
h.date = date;
h.status = status;
h.time = time;
return h;
}
}