mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-13 03:13:41 +08:00
fix(ui/clipboard): surface fallback copy failure + unify PreflightInstallDialog
This commit is contained in:
parent
57a459602e
commit
48f87066bd
@ -79,6 +79,7 @@ import { computed, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { skillApi } from '@/api/index'
|
||||
import { copyToClipboard } from '@/utils/clipboard'
|
||||
|
||||
interface RequirementStatus {
|
||||
key: string
|
||||
@ -146,21 +147,7 @@ function handleClose() {
|
||||
|
||||
async function copy(cmd: string) {
|
||||
try {
|
||||
if (navigator.clipboard) {
|
||||
await navigator.clipboard.writeText(cmd)
|
||||
} else {
|
||||
// Fallback for clipboard-API-disabled contexts (eg http://). The
|
||||
// textarea trick is broadly supported and avoids a noisy permission
|
||||
// failure on the production-ish workflow.
|
||||
const ta = document.createElement('textarea')
|
||||
ta.value = cmd
|
||||
ta.style.position = 'fixed'
|
||||
ta.style.left = '-9999px'
|
||||
document.body.appendChild(ta)
|
||||
ta.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(ta)
|
||||
}
|
||||
await copyToClipboard(cmd)
|
||||
ElMessage.success(t('common.copied'))
|
||||
} catch {
|
||||
ElMessage.warning(t('common.copyFailed'))
|
||||
|
||||
@ -13,6 +13,7 @@ export async function copyToClipboard(text: string): Promise<void> {
|
||||
ta.style.left = '-9999px'
|
||||
document.body.appendChild(ta)
|
||||
ta.select()
|
||||
document.execCommand('copy')
|
||||
const ok = document.execCommand('copy')
|
||||
document.body.removeChild(ta)
|
||||
if (!ok) throw new Error('Clipboard copy command failed')
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user