/** 解析 ABP RESTfulResult 并返回 data(与 request.ts 逻辑一致) */ export function unwrapAbpResponse(body: unknown): T { if (!body || typeof body !== 'object') { throw new Error('接口返回为空'); } const o = body as Record; const hasWrapper = 'statusCode' in o || 'StatusCode' in o || 'succeeded' in o || 'Succeeded' in o; if (!hasWrapper) { return body as T; } const statusCode = Number(o.statusCode ?? o.StatusCode ?? 0); const succeeded = (o.succeeded ?? o.Succeeded) as boolean | undefined; if (statusCode === 200 && succeeded !== false) { return (o.data ?? o.Data) as T; } const errors = o.errors ?? o.Errors; if (Array.isArray(errors) && errors.length > 0) { const msg = errors .map((item) => { if (item && typeof item === 'object' && 'errorMessage' in item) { return String((item as { errorMessage: string }).errorMessage); } return String(item); }) .join(', '); throw new Error(msg || '请求失败'); } throw new Error('请求失败'); }