✨ 优化 2026 主题移动端与详情体验
This commit is contained in:
1 parent
45a96112bc
commit
12738b874a
9 files changed
+184
-117
No files matched your search
+29
-12
@@ -36,30 +36,47 @@ export const copyToClipboard = async (
|
||||
}
|
||||
}
|
||||
|
||||
const showManualCopyDialog = () => {
|
||||
window.prompt('复制下面内容', text)
|
||||
}
|
||||
|
||||
try {
|
||||
// 优先使用 Clipboard API
|
||||
if (document.hasFocus() && navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
showCopyMessage(successMsg, 'success')
|
||||
return true
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
showCopyMessage(successMsg, 'success')
|
||||
return true
|
||||
} catch {
|
||||
// Continue to the DOM fallback.
|
||||
}
|
||||
}
|
||||
// 后备方案:使用传统的复制方法
|
||||
|
||||
const textarea = document.createElement('textarea')
|
||||
textarea.value = text
|
||||
textarea.style.position = 'fixed'
|
||||
textarea.style.opacity = '0'
|
||||
textarea.setAttribute('readonly', '')
|
||||
textarea.style.cssText =
|
||||
'position:fixed;left:0;top:0;width:1px;height:1px;opacity:0;z-index:-1;'
|
||||
document.body.appendChild(textarea)
|
||||
textarea.focus()
|
||||
textarea.select()
|
||||
const success = document.execCommand('copy')
|
||||
document.body.removeChild(textarea)
|
||||
textarea.setSelectionRange(0, textarea.value.length)
|
||||
let success = false
|
||||
try {
|
||||
success = document.execCommand('copy')
|
||||
} finally {
|
||||
document.body.removeChild(textarea)
|
||||
}
|
||||
if (success) {
|
||||
showCopyMessage(successMsg, 'success')
|
||||
return true
|
||||
} else {
|
||||
throw new Error('execCommand copy failed')
|
||||
}
|
||||
|
||||
showManualCopyDialog()
|
||||
showCopyMessage('已打开手动复制窗口', 'error')
|
||||
return false
|
||||
} catch (err) {
|
||||
console.error('复制失败:', err)
|
||||
showManualCopyDialog()
|
||||
showCopyMessage(errorMsg, 'error')
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user