账户登录

This commit is contained in:
张锐 committed 2026-11-22 10:14:44 +08:00
1 parent a0c723cdcc
commit 3b555ae815
37 files changed
+728 -26

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
export const API = "/api/admin/v1";
export type ApiErrorBody = { message?: string };
/** 统一发送管理后台 JSON 请求,并在会话失效时通知应用返回登录页。 */
export async function apiPost<T = any>(path: string, body: unknown = {}): Promise<T> {
const response = await fetch(API + path, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (response.status === 401) {
window.dispatchEvent(new Event("shoplix:unauthorized"));
}
if (!response.ok) {
const error = (await response.json().catch(() => ({}))) as ApiErrorBody;
throw new Error(error.message || "请求失败");
}
return response.json() as Promise<T>;
}
/** 将后端返回的相对素材地址转换为当前域名下的可访问地址。 */
export function assetUrl(url?: string): string {
return url || "";
}