feat(web): 用户端骨架——登录、工作台、新建项目、解析进度、读标清单
- packages/api-client:从 openapi.yaml 生成类型;cookie + CSRF / Bearer 两种鉴权、 分片上传、fetch 读事件流(API2) - apps/web:Vue 3 + Vite + TanStack Query,样式只来自 tokens.css / components.css(AR10); 扣点说明放在「开始解析」旁边(红线 9);接口地址、路由方式运行时可配(架构 §5.2) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
19
apps/web/src/lib/api.ts
Normal file
19
apps/web/src/lib/api.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 接口客户端单例。网页版走 cookie(写操作由 api-client 自动带 X-CSRF-Token);
|
||||
* 桌面版以后在这里传 getToken(从系统钥匙串取 Bearer 令牌),业务代码不用改。
|
||||
*/
|
||||
import { ApiError, createApi, type ClientOptions } from "@bid-doctor/api-client";
|
||||
import { runtimeConfig } from "./config";
|
||||
|
||||
export const apiOptions: ClientOptions = { baseUrl: runtimeConfig.apiBaseUrl };
|
||||
export const api = createApi(apiOptions);
|
||||
|
||||
/** 网络中断等非接口错误也包成「请求失败」,界面统一处理。 */
|
||||
export function errorTitle(e: unknown): string {
|
||||
if (e instanceof ApiError) return e.problem.title;
|
||||
return "网络连接失败,请检查网络后重试";
|
||||
}
|
||||
|
||||
export function isApiError(e: unknown, code?: string): e is ApiError {
|
||||
return e instanceof ApiError && (code === undefined || e.code === code);
|
||||
}
|
||||
Reference in New Issue
Block a user