fix: PSK 复制兼容 HTTP 环境(execCommand 降级)
This commit is contained in:
@@ -166,7 +166,20 @@ const handleToggle = async (row) => {
|
|||||||
|
|
||||||
const copySecret = async (secret) => {
|
const copySecret = async (secret) => {
|
||||||
try {
|
try {
|
||||||
await navigator.clipboard.writeText(secret)
|
// 优先 clipboard API(需要 HTTPS)
|
||||||
|
if (navigator.clipboard && window.isSecureContext) {
|
||||||
|
await navigator.clipboard.writeText(secret)
|
||||||
|
} else {
|
||||||
|
// HTTP 降级:execCommand
|
||||||
|
const textarea = document.createElement('textarea')
|
||||||
|
textarea.value = secret
|
||||||
|
textarea.style.position = 'fixed'
|
||||||
|
textarea.style.opacity = '0'
|
||||||
|
document.body.appendChild(textarea)
|
||||||
|
textarea.select()
|
||||||
|
document.execCommand('copy')
|
||||||
|
document.body.removeChild(textarea)
|
||||||
|
}
|
||||||
ElMessage.success('已复制到剪贴板')
|
ElMessage.success('已复制到剪贴板')
|
||||||
} catch {
|
} catch {
|
||||||
ElMessage.error('复制失败,请手动复制')
|
ElMessage.error('复制失败,请手动复制')
|
||||||
|
|||||||
Reference in New Issue
Block a user