import { post } from './http.ts' export function getCurrentUserId() { const raw = typeof window === "undefined" ? "" : window.localStorage.getItem("uid") || ""; const value = Number(raw); if (!Number.isFinite(value) || value <= 0) { throw new Error("未获取到用户ID"); } return value; } /** 桌面端登录接口响应 data 段 */ export interface LoginData { token?: string userId?: number | string username?: string [key: string]: unknown } export interface LoginResponse { success: boolean message?: string msg?: string data?: LoginData } /** * 桌面端登录(原页面裸 window.fetch('/newApi/login') 收敛到 shared 层: * 页面不得直连 /newApi,见 shared-api-allowlist 测试约定) */ export function loginWithDevice(account: string, password: string, deviceId: string) { return post( '/newApi/login', { username: account, password, deviceId }, { headers: { 'X-Device-Id': deviceId, 'X-Requested-With': 'XMLHttpRequest' }, }, ) }