From 0d315227092de2feb30887c843060db8083a6646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=9E=B3?= <7854742+wang_rumeng@user.noreply.gitee.com> Date: Sat, 6 Sep 2025 16:58:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=B6=88=E6=81=AF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/errorHandle.ts | 7 +- api/request.ts | 1 - app/page.tsx | 2 - .../Interaction/MovieProjectService.ts | 13 +- .../Interaction/templateStoryService.ts | 1 - app/types/global.d.ts | 16 ++ components/common/GlobalMessage.tsx | 92 +++++++++ components/layout/top-bar.tsx | 4 +- components/pages/create-to-video2.tsx | 11 +- .../pages/work-flow/use-workflow-data.tsx | 3 +- components/providers.tsx | 34 +++- components/script-renderer/ScriptRenderer.tsx | 7 +- components/ui/character-tab-content.tsx | 9 +- components/ui/edit-modal.tsx | 7 +- components/ui/oauth-callback-handler.tsx | 90 --------- components/ui/shot-editor/ShotsEditor.tsx | 7 +- components/ui/shot-tab-content.tsx | 5 +- components/ui/sonner.tsx | 31 --- components/ui/toast.tsx | 129 ------------ components/ui/toaster.tsx | 35 ---- hooks/use-toast.ts | 191 ------------------ tsconfig.json | 8 +- 22 files changed, 172 insertions(+), 531 deletions(-) create mode 100644 app/types/global.d.ts create mode 100644 components/common/GlobalMessage.tsx delete mode 100644 components/ui/oauth-callback-handler.tsx delete mode 100644 components/ui/sonner.tsx delete mode 100644 components/ui/toast.tsx delete mode 100644 components/ui/toaster.tsx delete mode 100644 hooks/use-toast.ts diff --git a/api/errorHandle.ts b/api/errorHandle.ts index 50b7fa7..2486b2d 100644 --- a/api/errorHandle.ts +++ b/api/errorHandle.ts @@ -1,4 +1,3 @@ -import { message } from "antd"; import { debounce } from "lodash"; /** @@ -52,11 +51,7 @@ export const errorHandle = debounce( customMessage || HTTP_ERROR_MESSAGES[code] || DEFAULT_ERROR_MESSAGE; // 显示错误提示 - message.error({ - content: errorMessage, - duration: 3, - className: 'custom-error-message' - }); + window.msg.error(errorMessage); // 执行特殊错误码的处理函数 const handler = ERROR_HANDLERS[code]; diff --git a/api/request.ts b/api/request.ts index 7a59dbf..c30cc5a 100644 --- a/api/request.ts +++ b/api/request.ts @@ -1,5 +1,4 @@ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, AxiosHeaders } from 'axios'; -import { message } from "antd"; import { BASE_URL } from './constants' import { errorHandle } from './errorHandle'; diff --git a/app/page.tsx b/app/page.tsx index e2c41ee..782e582 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,13 +1,11 @@ import { TopBar } from "@/components/layout/top-bar"; import { HomePage2 } from "@/components/pages/home-page2"; -import OAuthCallbackHandler from "@/components/ui/oauth-callback-handler"; export default function Home() { return ( <> - ); diff --git a/app/service/Interaction/MovieProjectService.ts b/app/service/Interaction/MovieProjectService.ts index 1d4ebb0..428bd44 100644 --- a/app/service/Interaction/MovieProjectService.ts +++ b/app/service/Interaction/MovieProjectService.ts @@ -1,7 +1,6 @@ -import { CreateMovieProjectV2Request, CreateMovieProjectV3Request } from "@/api/DTO/movie_start_dto"; + import { createMovieProject, createMovieProjectV2, createMovieProjectV3 } from "@/api/create_movie"; -import { QueueResponse, QueueStatus, withQueuePolling, QueueResponseData } from "@/api/movie_queue"; -import { message } from "antd"; +import { QueueResponse, withQueuePolling, QueueResponseData } from "@/api/movie_queue"; /** * 电影项目创建模式 @@ -56,13 +55,13 @@ export class MovieProjectService { }, onError: (error: Error) => { if (error.message === '操作已取消') { - message.info('Queue cancelled'); + window.msg.info('Queue cancelled'); } else { - message.error(error instanceof Error ? error.message : "Failed to create project"); + window.msg.error(error instanceof Error ? error.message : "Failed to create project"); } }, onCancel: () => { - message.info('Queue cancelled'); + window.msg.info('Queue cancelled'); } }); @@ -80,7 +79,7 @@ export class MovieProjectService { if (error instanceof Error && error.message === '操作已取消') { throw error; } - message.error(error instanceof Error ? error.message : "Failed to create project"); + window.msg.error(error instanceof Error ? error.message : "Failed to create project"); throw error; } } diff --git a/app/service/Interaction/templateStoryService.ts b/app/service/Interaction/templateStoryService.ts index 99f8a13..89dacc4 100644 --- a/app/service/Interaction/templateStoryService.ts +++ b/app/service/Interaction/templateStoryService.ts @@ -1,4 +1,3 @@ -import { message } from "antd"; import { StoryTemplateEntity } from "../domain/Entities"; import { useUploadFile } from "../domain/service"; import { debounce } from "lodash"; diff --git a/app/types/global.d.ts b/app/types/global.d.ts new file mode 100644 index 0000000..6136c85 --- /dev/null +++ b/app/types/global.d.ts @@ -0,0 +1,16 @@ +import { GlobalMessage } from '@/components/common/GlobalMessage'; +import { toast } from 'sonner'; + +declare global { + interface Window { + msg: GlobalMessage; + $message: { + success: (message: string, duration?: number) => void; + error: (message: string, duration?: number) => void; + warning: (message: string, duration?: number) => void; + info: (message: string, duration?: number) => void; + loading: (message: string) => ReturnType; + dismiss: () => void; + }; + } +} \ No newline at end of file diff --git a/components/common/GlobalMessage.tsx b/components/common/GlobalMessage.tsx new file mode 100644 index 0000000..a31c859 --- /dev/null +++ b/components/common/GlobalMessage.tsx @@ -0,0 +1,92 @@ +'use client'; + +import { toast, type ToastT } from 'sonner'; +import { + CheckCircle2, + XCircle, + AlertCircle, + Info, + Loader2 +} from 'lucide-react'; + +/** + * 全局消息提示工具 + * 对 sonner toast 进行封装,提供更简洁的 API + */ +class GlobalMessage { + success(message: string, duration = 3000, options?: Partial) { + toast.success(message, { + icon: , + duration, + ...options, + }); + } + + error(message: string, duration = 3000, options?: Partial) { + toast.error(message, { + icon: , + duration, + ...options, + }); + } + + warning(message: string, duration = 3000, options?: Partial) { + toast.warning(message, { + icon: , + duration, + ...options, + }); + } + + info(message: string, duration = 3000, options?: Partial) { + toast(message, { + icon: , + duration, + ...options, + }); + } + + loading(message: string, options?: Partial) { + return toast.promise( + new Promise(() => {}), + { + loading: message, + icon: , + ...options, + } + ); + } + + dismiss() { + toast.dismiss(); + } +} + +// 导出单例实例 +export const msg = new GlobalMessage(); + +// 为了方便使用,也导出单独的方法 +export const { success, error, warning, info, loading, dismiss } = msg; +// 在文件末尾添加全局注册方法 +export function registerGlobalMessage() { + if (typeof window !== 'undefined') { + // 注册完整实例 + window.msg = msg; + + // 注册便捷方法 + window.$message = { + success: msg.success.bind(msg), + error: msg.error.bind(msg), + warning: msg.warning.bind(msg), + info: msg.info.bind(msg), + loading: msg.loading.bind(msg), + dismiss: msg.dismiss.bind(msg), + }; + + // 添加调试信息 + console.log('GlobalMessage registered:', { + msg: window.msg, + $message: window.$message + }); + } +} diff --git a/components/layout/top-bar.tsx b/components/layout/top-bar.tsx index 1f78b40..0be548b 100644 --- a/components/layout/top-bar.tsx +++ b/components/layout/top-bar.tsx @@ -239,9 +239,9 @@ export function TopBar({ collapsed }: { collapsed: boolean }) { )} {/* Notifications */} - {/* */} + {/* Theme Toggle */} {/*