From ed96f256a4c3c02b65a2037dba18eaec72269dcf Mon Sep 17 00:00:00 2001 From: Autumn-27 <53844290+Autumn-27@users.noreply.github.com> Date: Thu, 20 Aug 2026 11:21:07 -0400 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E6=8A=A5=E5=91=8A=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E5=9C=A8=20HTTP=20=E9=9D=9E=E5=AE=89=E5=85=A8=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E4=B8=8B=E5=A4=B1=E6=95=88=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20execCommand=20=E9=99=8D=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_01Bs2rrsVHUBTxRusm9espwB --- .../tasks/detail/_tabs/report-tab.tsx | 42 ++++++++++++++++--- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/web/src/app/(main)/function/tasks/detail/_tabs/report-tab.tsx b/web/src/app/(main)/function/tasks/detail/_tabs/report-tab.tsx index 056b786..a9bb3e8 100644 --- a/web/src/app/(main)/function/tasks/detail/_tabs/report-tab.tsx +++ b/web/src/app/(main)/function/tasks/detail/_tabs/report-tab.tsx @@ -10,6 +10,34 @@ import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { api } from "@/lib/api"; +async function copyText(text: string): Promise { + // 优先使用异步剪贴板 API(仅在 HTTPS / localhost 等安全上下文可用) + if (navigator.clipboard && window.isSecureContext) { + try { + await navigator.clipboard.writeText(text); + return true; + } catch { + // 继续走降级方案 + } + } + // 降级:HTTP 等非安全上下文下用 execCommand + try { + const textarea = document.createElement("textarea"); + textarea.value = text; + textarea.style.position = "fixed"; + textarea.style.left = "-9999px"; + textarea.style.top = "0"; + document.body.appendChild(textarea); + textarea.focus(); + textarea.select(); + const ok = document.execCommand("copy"); + document.body.removeChild(textarea); + return ok; + } catch { + return false; + } +} + export function ReportTab({ taskId }: { taskId: string }) { const [report, setReport] = React.useState(""); const [loading, setLoading] = React.useState(true); @@ -34,12 +62,16 @@ export function ReportTab({ taskId }: { taskId: string }) { }; }, [taskId]); - function copy() { + async function copy() { if (!report) return; - navigator.clipboard?.writeText(report); - setCopied(true); - toast.success("已复制 Markdown"); - setTimeout(() => setCopied(false), 1500); + const ok = await copyText(report); + if (ok) { + setCopied(true); + toast.success("已复制 Markdown"); + setTimeout(() => setCopied(false), 1500); + } else { + toast.error("复制失败,请手动选择文本复制"); + } } let content: React.ReactNode;