fix: AI 摘要复制失败 — HTTP 环境 Clipboard API 不可用
navigator.clipboard 需要安全上下文(HTTPS/localhost),
内网 HTTP 部署时自动降级为 textarea + execCommand('copy')
This commit is contained in:
@@ -120,10 +120,21 @@ async function generateAISummary() {
|
|||||||
|
|
||||||
async function copySummary() {
|
async function copySummary() {
|
||||||
if (!aiSummary.value) return
|
if (!aiSummary.value) return
|
||||||
try {
|
|
||||||
// Strip markdown markers for plain text
|
|
||||||
const plain = aiSummary.value.replace(/^#{1,4}\s+/gm, '').replace(/\*\*/g, '').replace(/\*/g, '')
|
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)
|
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('摘要已复制到剪贴板')
|
ElMessage.success('摘要已复制到剪贴板')
|
||||||
} catch {
|
} catch {
|
||||||
ElMessage.error('复制失败')
|
ElMessage.error('复制失败')
|
||||||
|
|||||||
Reference in New Issue
Block a user