From 9d1d8a362aa07be1b2daf19ee0e23a25ed5aac77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= Date: Mon, 4 May 2026 13:26:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=89=AA=E8=B4=B4=E6=9D=BF):=20=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E5=89=AA=E8=B4=B4=E6=9D=BF=E6=93=8D=E4=BD=9C=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在复制文本和图片到剪贴板时,捕获并返回更详细的错误信息 同时更新GlobalSnackbar组件,优化类型导入和消息显示 --- components/GlobalSnackbar.tsx | 15 ++++++++++++--- utils/clipboard.ts | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/components/GlobalSnackbar.tsx b/components/GlobalSnackbar.tsx index 023319e..c1b3314 100644 --- a/components/GlobalSnackbar.tsx +++ b/components/GlobalSnackbar.tsx @@ -35,7 +35,14 @@ * ``` */ -import React, { JSX, useState, createContext, useContext, type ReactNode } from 'react'; +import { + JSX, + useState, + createContext, + useContext, + type ReactNode, + type SyntheticEvent, +} from 'react'; import { Snackbar, Alert, type SxProps, type Theme, alpha, Portal } from '@mui/material'; /** @@ -181,7 +188,9 @@ export function GlobalSnackbar({ > {message} - ) : undefined} + ) : ( +
{message}
+ )} ); @@ -210,7 +219,7 @@ export function useSnackbarState(initialOptions?: SnackbarOptions): UseSnackbarS setOpen(false); }; - const handleClose = (_event?: React.SyntheticEvent | Event, reason?: string) => { + const handleClose = (_event?: SyntheticEvent | Event, reason?: string) => { if (reason === 'clickaway') return; closeMessage(); }; diff --git a/utils/clipboard.ts b/utils/clipboard.ts index 1c7eb7c..99ca0f6 100644 --- a/utils/clipboard.ts +++ b/utils/clipboard.ts @@ -10,8 +10,8 @@ export const copyTextToClipboard = async (text: string): Promise => { .then(() => { resolve(true); }) - .catch(() => { - reject(false); + .catch((error) => { + reject(new Error(`复制文本到剪贴板失败,错误: ${error?.message || 'Unknown error'}`)); }); }); }; @@ -32,8 +32,8 @@ export const copyImageToClipboard = async (blob: Blob): Promise => { .then(() => { resolve(true); }) - .catch(() => { - reject(false); + .catch((error) => { + reject(new Error(`复制图片到剪贴板失败,错误: ${error?.message || 'Unknown error'}`)); }); }); };