feat(entry): 新增本地 mock 数据层
This commit is contained in:
30
entry/src/main/ets/data/repository/SessionRepository.ets
Normal file
30
entry/src/main/ets/data/repository/SessionRepository.ets
Normal file
@@ -0,0 +1,30 @@
|
||||
import { SessionManager } from 'common';
|
||||
import { mockDelay } from './MockUtil';
|
||||
|
||||
/**
|
||||
* 会话数据仓库契约:ViewModel 只依赖此契约。
|
||||
*/
|
||||
export abstract class SessionRepository {
|
||||
abstract isLoggedIn(): boolean;
|
||||
abstract login(): Promise<void>;
|
||||
abstract logout(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现:封装 common 的 SessionManager(持久化 SessionStore)。
|
||||
* M1 为模拟登录(写死 token);M2 起接真实微信/手机号登录。
|
||||
*/
|
||||
export class SessionRepositoryImpl extends SessionRepository {
|
||||
isLoggedIn(): boolean {
|
||||
return SessionManager.get().isLoggedIn;
|
||||
}
|
||||
|
||||
async login(): Promise<void> {
|
||||
await mockDelay(300);
|
||||
SessionManager.get().setSession('mock-token-0001', '', 'u-1001', '张三');
|
||||
}
|
||||
|
||||
logout(): void {
|
||||
SessionManager.get().clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user