重构:前端架构优化 - 消灭巨石文件,统一代码规范
Phase 1 - 消灭巨石页面: - 拆分 AdminKuaishouCloudFulfillmentView (1,224行→kuaishou-cloud/子目录) - 拆分 AdminFulfillmentBindingsView (989行→bindings/子目录) - 拆分 AdminTaskDetailView (1,007行→9个子组件+2个composable) - 合并去重 useClaimPage + useAdminManualRedeemPage (1,554行→共享模块+差异化薄层) - 拆分 services/admin/platform-config.ts (477行→8个领域子模块) Phase 2 - 架构收口: - 拆分 types/admin.ts (925行→13个子文件+platform-config/子目录) - 统一 API code 检查(http.ts拦截器统一处理业务错误) - 修改 apiPost 签名消除 as unknown as 类型断言(6处) - 新增 BusinessError 类型便于错误分类处理 所有改动通过 vue-tsc --noEmit 零错误和 vite build 验证
This commit is contained in:
@@ -17,7 +17,22 @@ const http = axios.create({
|
||||
})
|
||||
|
||||
http.interceptors.response.use(
|
||||
(response) => response.data,
|
||||
(response) => {
|
||||
const data = response.data as ApiEnvelope<unknown>
|
||||
|
||||
// Business-level error: HTTP 200 but code !== 0
|
||||
if (typeof data?.code === 'number' && data.code !== 0) {
|
||||
const error = new Error(data.msg || '操作失败') as Error & {
|
||||
errorCode?: string
|
||||
code?: number
|
||||
}
|
||||
error.errorCode = data.errorCode
|
||||
error.code = data.code
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
return response.data
|
||||
},
|
||||
(error) => {
|
||||
const responseMessage =
|
||||
typeof error?.response?.data?.msg === 'string' ? error.response.data.msg.trim() : ''
|
||||
@@ -111,8 +126,8 @@ export function apiGetBlob(url: string, params?: Record<string, unknown>) {
|
||||
})
|
||||
}
|
||||
|
||||
export function apiPost<T>(url: string, data?: Record<string, unknown>) {
|
||||
return request<T>({ method: 'POST', url, data })
|
||||
export function apiPost<T>(url: string, data?: unknown) {
|
||||
return request<T>({ method: 'POST', url, data: data as Record<string, unknown> })
|
||||
}
|
||||
|
||||
export function apiDelete<T>(url: string) {
|
||||
|
||||
Reference in New Issue
Block a user