// 写入剪贴板;Clipboard API 只在 HTTPS/localhost 可用,局域网 HTTP 访问时退回 execCommand export async function copyText(text: string): Promise { if (navigator.clipboard && window.isSecureContext) { try { await navigator.clipboard.writeText(text) return true } catch { // 权限被拒时继续尝试旧方法 } } const ta = document.createElement('textarea') ta.value = text ta.style.cssText = 'position:fixed;top:0;left:0;opacity:0' document.body.append(ta) ta.select() const ok = document.execCommand('copy') ta.remove() return ok }