feat(entry): 建立 MVVM+data 分层骨架,接入 V2 状态管理与 Navigation 路由

This commit is contained in:
AndyChen1024
2026-09-11 16:22:45 +08:00
parent 3a116df871
commit 058b978f25
11 changed files with 336 additions and 33 deletions

View File

@@ -0,0 +1,33 @@
import { HttpClient, ApiResult, ApiError } from 'common';
/**
* 后端用户接口 DTO(与后端字段约定对齐)。
*/
export class UserDto {
id: string = '';
name: string = '';
email: string = '';
}
/**
* 用户相关网络请求服务:负责发请求、解析统一响应、返回 DTO。
* TODO: BASE_URL 应改为环境注入(debug/release 分离)。
*/
export class UserApi {
private static readonly BASE_URL: string = 'https://api.example.com';
private readonly http: HttpClient;
constructor(http: HttpClient) {
this.http = http;
}
async fetchUser(id: string): Promise<UserDto> {
const raw = await this.http.get(`${UserApi.BASE_URL}/api/user/${id}`);
const result = JSON.parse(raw) as ApiResult<UserDto>;
if (!result.isSuccess()) {
throw ApiError.business(result.code, result.message);
}
return result.data;
}
}