From cea423281390fd4ff332577f2daedb81b42f8852 Mon Sep 17 00:00:00 2001 From: MT-Mint <798521692@qq.com> Date: Thu, 9 Apr 2026 10:27:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=BF=E4=B8=BB=E9=A1=B5=E5=A4=8D?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/core/iframe-messages.ts | 8 ++++++++ frontend/src/lib/utils.ts | 9 +++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/src/core/iframe-messages.ts b/frontend/src/core/iframe-messages.ts index f413f0fc..eac47ecb 100644 --- a/frontend/src/core/iframe-messages.ts +++ b/frontend/src/core/iframe-messages.ts @@ -11,6 +11,8 @@ export const POST_MESSAGE_TYPES = { FULLSCREEN: "fullscreen", // 会话是否处于聊天态 IS_CHATTING: "isChatting", + // 请求宿主页执行复制 + COPY_TO_CLIPBOARD: "copyToClipboard", // 选择预定义 skill SELECT_SKILLS: "selectedSkills", // 打开 skill 选择对话框 @@ -42,6 +44,11 @@ export interface IsChattingMessage { isChatting: boolean; } +export interface CopyToClipboardMessage { + type: typeof POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD; + text: string; +} + export interface SelectSkillMessage { type: typeof POST_MESSAGE_TYPES.SELECT_SKILLS; selectedSkills: SelectedSkillPayloadItem[]; @@ -106,6 +113,7 @@ export function sendToParent( message: | FullscreenMessage | IsChattingMessage + | CopyToClipboardMessage | SelectSkillMessage | OpenSkillDialogMessage, ): void { diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 45b5fc2e..4397759c 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -1,5 +1,6 @@ import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; +import { POST_MESSAGE_TYPES, sendToParent } from "@/core/iframe-messages"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); @@ -18,14 +19,14 @@ export const externalLinkClassNoUnderline = "text-primary hover:underline"; export async function copyToClipboard(text: string): Promise { const isInIframe = window.self !== window.top; const message = { - type: "copyToClipboard", + type: POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD, text, - }; + } as const; - if (isInIframe && window.parent) { + if (isInIframe) { try { // Request parent window to copy - window.parent.postMessage(message, "*"); + sendToParent(message); console.log( "[copyToClipboard] iframe mode → postMessage to parent", message,