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

31 lines
801 B
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 { 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();
}
}