feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import type { ApiError, ErrorType } from './httpClient'
|
||||
|
||||
class ErrorHandler {
|
||||
private errorMessages: Record<ErrorType, string> = {
|
||||
NETWORK_ERROR: '网络连接失败,请检查网络设置',
|
||||
TIMEOUT_ERROR: '请求超时,请稍后重试',
|
||||
BUSINESS_ERROR: '操作失败,请稍后重试',
|
||||
AUTH_ERROR: '认证失败,请重新登录',
|
||||
TOKEN_EXPIRED: '登录已过期,请重新登录',
|
||||
UNKNOWN_ERROR: '未知错误,请稍后重试'
|
||||
}
|
||||
|
||||
handleError(error: ApiError): void {
|
||||
this.logError(error)
|
||||
this.showErrorMessage(error.message)
|
||||
}
|
||||
|
||||
showErrorMessage(message: string): void {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
}
|
||||
|
||||
showSuccessMessage(message: string): void {
|
||||
uni.showToast({
|
||||
title: message,
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
}
|
||||
|
||||
logError(error: ApiError): void {
|
||||
console.error('[API Error]', {
|
||||
type: error.type,
|
||||
code: error.code,
|
||||
message: error.message,
|
||||
detail: error.detail
|
||||
})
|
||||
}
|
||||
|
||||
getErrorMessage(error: ApiError): string {
|
||||
return this.errorMessages[error.type] || error.message
|
||||
}
|
||||
|
||||
isAuthError(error: ApiError): boolean {
|
||||
return error.type === 'AUTH_ERROR' || error.type === 'TOKEN_EXPIRED'
|
||||
}
|
||||
|
||||
isNetworkError(error: ApiError): boolean {
|
||||
return error.type === 'NETWORK_ERROR' || error.type === 'TIMEOUT_ERROR'
|
||||
}
|
||||
|
||||
isBusinessError(error: ApiError): boolean {
|
||||
return error.type === 'BUSINESS_ERROR'
|
||||
}
|
||||
}
|
||||
|
||||
const errorHandler = new ErrorHandler()
|
||||
|
||||
export default errorHandler
|
||||
export { ErrorHandler }
|
||||
Reference in New Issue
Block a user