fix: AI 摘要复制失败 — HTTP 环境 Clipboard API 不可用

navigator.clipboard 需要安全上下文(HTTPS/localhost),
内网 HTTP 部署时自动降级为 textarea + execCommand('copy')
This commit is contained in:
2026-06-24 19:39:28 +08:00
parent 24c7aff093
commit 5b50e7ec27
+13 -2
View File
@@ -120,10 +120,21 @@ async function generateAISummary() {
async function copySummary() {
if (!aiSummary.value) return
try {
// Strip markdown markers for plain text
const plain = aiSummary.value.replace(/^#{1,4}\s+/gm, '').replace(/\*\*/g, '').replace(/\*/g, '')
try {
// Prefer Clipboard API (requires HTTPS or localhost)
if (navigator.clipboard && window.isSecureContext) {
await navigator.clipboard.writeText(plain)
} else {
// Fallback for HTTP environments
const ta = document.createElement('textarea')
ta.value = plain
ta.style.position = 'fixed'; ta.style.left = '-9999px'; ta.style.top = '-9999px'
document.body.appendChild(ta)
ta.focus(); ta.select()
document.execCommand('copy')
document.body.removeChild(ta)
}
ElMessage.success('摘要已复制到剪贴板')
} catch {
ElMessage.error('复制失败')