feat(frontend): 对接后端统一响应格式,增强错误处理
- 新增 types/api.ts,定义 ApiResponse/PaginatedData 泛型类型和业务错误码常量 - 增强 request.ts 拦截器:提取后端错误信息、映射 HTTP 状态码和业务错误码为中文提示 - 为 auth/audit/subsystem API 添加泛型返回类型 - 为各视图添加 try/catch 防止未处理的 Promise 拒绝
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import request from './request'
|
||||
import type { ApiResponse, PaginatedData } from '@/types/api'
|
||||
|
||||
export interface LoginAudit {
|
||||
id: number
|
||||
@@ -39,7 +39,7 @@ const mockOpsAudits: OpsAudit[] = [
|
||||
|
||||
export const auditApi = {
|
||||
// 获取登录审计
|
||||
getLoginAudit(params?: any): Promise<any> {
|
||||
getLoginAudit(_params?: any): Promise<ApiResponse<PaginatedData<LoginAudit>>> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
@@ -55,7 +55,7 @@ export const auditApi = {
|
||||
},
|
||||
|
||||
// 获取运维操作审计
|
||||
getOpsAudit(params?: any): Promise<any> {
|
||||
getOpsAudit(_params?: any): Promise<ApiResponse<PaginatedData<OpsAudit>>> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(() => {
|
||||
resolve({
|
||||
|
||||
Reference in New Issue
Block a user