fix: 修复非HTTPS环境下剪贴板复制失败问题
- 添加安全检查,仅在clipboard可用时尝试复制 - 添加错误处理,避免复制失败影响用户体验 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -108,11 +108,19 @@ async function handleGenerate() {
|
|||||||
card_type_id: Number(form.value.card_type_id),
|
card_type_id: Number(form.value.card_type_id),
|
||||||
quantity: form.value.count,
|
quantity: form.value.count,
|
||||||
})
|
})
|
||||||
toast.success(t('agent.cards.create.generateSuccess', { count: data.codes.length }))
|
toast.success(t('agent.cards.create.generateSuccess', { count: data.codes?.length || 0 }))
|
||||||
|
|
||||||
const codesText = data.codes.join('\n')
|
// 尝试复制到剪贴板(仅在安全上下文中可用)
|
||||||
await navigator.clipboard.writeText(codesText)
|
if (data.codes?.length && navigator?.clipboard?.writeText) {
|
||||||
toast.success(t('agent.cards.create.copiedToClipboard'))
|
try {
|
||||||
|
const codesText = data.codes.join('\n')
|
||||||
|
await navigator.clipboard.writeText(codesText)
|
||||||
|
toast.success(t('agent.cards.create.copiedToClipboard'))
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
// 剪贴板复制失败,忽略
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
router.push('/agent/cards')
|
router.push('/agent/cards')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user