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

79 lines
2.6 KiB
Plaintext
Raw 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 { 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;
}
}