mirror of
https://gitee.com/mateos/mateclaw.git
synced 2026-09-16 12:27:53 +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 { useI18n } from 'vue-i18n'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { skillApi } from '@/api/index'
|
import { skillApi } from '@/api/index'
|
||||||
|
import { copyToClipboard } from '@/utils/clipboard'
|
||||||
|
|
||||||
interface RequirementStatus {
|
interface RequirementStatus {
|
||||||
key: string
|
key: string
|
||||||
@ -146,21 +147,7 @@ function handleClose() {
|
|||||||
|
|
||||||
async function copy(cmd: string) {
|
async function copy(cmd: string) {
|
||||||
try {
|
try {
|
||||||
if (navigator.clipboard) {
|
await copyToClipboard(cmd)
|
||||||
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)
|
|
||||||
}
|
|
||||||
ElMessage.success(t('common.copied'))
|
ElMessage.success(t('common.copied'))
|
||||||
} catch {
|
} catch {
|
||||||
ElMessage.warning(t('common.copyFailed'))
|
ElMessage.warning(t('common.copyFailed'))
|
||||||
|
|||||||
@ -13,6 +13,7 @@ export async function copyToClipboard(text: string): Promise<void> {
|
|||||||
ta.style.left = '-9999px'
|
ta.style.left = '-9999px'
|
||||||
document.body.appendChild(ta)
|
document.body.appendChild(ta)
|
||||||
ta.select()
|
ta.select()
|
||||||
document.execCommand('copy')
|
const ok = document.execCommand('copy')
|
||||||
document.body.removeChild(ta)
|
document.body.removeChild(ta)
|
||||||
|
if (!ok) throw new Error('Clipboard copy command failed')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user