瀏覽代碼

✨ feat(avatar): 优化头像上传错误提示

- 引入sonner的toast组件替代原生alert
- 将图片格式错误提示改为toast显示
- 将图片大小超限提示改为toast显示
- 将文件处理失败提示改为toast显示
- 将用户ID缺失提示改为toast显示
- 将上传失败提示改为toast显示
yourname 7 月之前
父節點
當前提交
58a87d333c
共有 1 個文件被更改,包括 6 次插入5 次删除
  1. 6 5
      src/client/mobile/components/AvatarUpload.tsx

+ 6 - 5
src/client/mobile/components/AvatarUpload.tsx

@@ -2,6 +2,7 @@ import React, { useState, useRef } from 'react';
 import { uploadMinIOWithPolicy } from '@/client/utils/minio';
 import { compressImage, isImageFile, checkFileSize } from '@/client/utils/upload';
 import { AvatarCropper } from './AvatarCropper';
+import { toast } from 'sonner';
 
 // 水墨风格色彩系统
 const COLORS = {
@@ -53,7 +54,7 @@ export const AvatarUpload: React.FC<AvatarUploadProps> = ({
     if (!isImageFile(file)) {
       const error = new Error('请选择图片文件');
       if (onUploadError) onUploadError(error);
-      else alert(error.message);
+      else toast(error.message);
       return;
     }
 
@@ -61,7 +62,7 @@ export const AvatarUpload: React.FC<AvatarUploadProps> = ({
     if (!checkFileSize(file, 2)) {
       const error = new Error('图片大小不能超过2MB');
       if (onUploadError) onUploadError(error);
-      else alert(error.message);
+      else toast(error.message);
       return;
     }
 
@@ -75,7 +76,7 @@ export const AvatarUpload: React.FC<AvatarUploadProps> = ({
       console.error('文件处理失败:', error);
       const err = error as Error;
       if (onUploadError) onUploadError(err);
-      else alert('文件处理失败,请重试');
+      else toast('文件处理失败,请重试');
     } finally {
       // 清除文件输入
       if (fileInputRef.current) {
@@ -88,7 +89,7 @@ export const AvatarUpload: React.FC<AvatarUploadProps> = ({
     if (!userId) {
       const error = new Error('用户ID未提供');
       if (onUploadError) onUploadError(error);
-      else alert(error.message);
+      else toast(error.message);
       return;
     }
 
@@ -120,7 +121,7 @@ export const AvatarUpload: React.FC<AvatarUploadProps> = ({
       console.error('头像上传失败:', error);
       const err = error as Error;
       if (onUploadError) onUploadError(err);
-      else alert('头像上传失败,请重试');
+      else toast('头像上传失败,请重试');
     } finally {
       setIsUploading(false);
       if (cropImageUrl) {