feat(frontend): 对接后端统一响应格式,增强错误处理

- 新增 types/api.ts,定义 ApiResponse/PaginatedData 泛型类型和业务错误码常量
- 增强 request.ts 拦截器:提取后端错误信息、映射 HTTP 状态码和业务错误码为中文提示
- 为 auth/audit/subsystem API 添加泛型返回类型
- 为各视图添加 try/catch 防止未处理的 Promise 拒绝
This commit is contained in:
2026-07-15 10:52:41 +08:00
parent 4f1df02f53
commit 3de59c4fc2
10 changed files with 137 additions and 32 deletions
+8 -3
View File
@@ -1,4 +1,4 @@
import request from './request'
import type { ApiResponse } from '@/types/api'
export interface Subsystem {
id: number
@@ -10,6 +10,11 @@ export interface Subsystem {
sso_enabled: boolean
}
export interface SSOResponse {
sso_url: string
expires_in: number
}
// Mock 数据
const mockSubsystems: Subsystem[] = [
{
@@ -70,7 +75,7 @@ const mockSubsystems: Subsystem[] = [
export const subsystemApi = {
// 获取子系统列表
getSubsystems(): Promise<any> {
getSubsystems(): Promise<ApiResponse<Subsystem[]>> {
return new Promise((resolve) => {
setTimeout(() => {
resolve({
@@ -83,7 +88,7 @@ export const subsystemApi = {
},
// 获取 SSO 跳转 URL
getSSOUrl(id: number): Promise<any> {
getSSOUrl(id: number): Promise<ApiResponse<SSOResponse>> {
return new Promise((resolve) => {
setTimeout(() => {
const subsystem = mockSubsystems.find((s) => s.id === id)