feat(web): 添加剪贴板复制兼容 HTTP 环境

- 新增 useClipboard composable,支持 execCommand 备用方案
- 修复 HTTP 环境下复制按钮无响应问题
This commit is contained in:
mofeng-git
2025-12-31 20:31:42 +08:00
parent d0e2e13b35
commit 8be45155ac
2 changed files with 71 additions and 3 deletions

View File

@@ -27,6 +27,7 @@ import type {
AtxDevices,
} from '@/types/generated'
import { setLanguage } from '@/i18n'
import { useClipboard } from '@/composables/useClipboard'
import AppLayout from '@/components/AppLayout.vue'
import { Button } from '@/components/ui/button'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
@@ -173,6 +174,7 @@ const rustdeskStatus = ref<RustDeskStatusResponse | null>(null)
const rustdeskPassword = ref<RustDeskPasswordResponse | null>(null)
const rustdeskLoading = ref(false)
const rustdeskCopied = ref<'id' | 'password' | null>(null)
const { copy: clipboardCopy } = useClipboard()
const rustdeskLocalConfig = ref({
enabled: false,
rendezvous_server: '',
@@ -860,11 +862,12 @@ async function regenerateRustdeskPassword() {
}
}
function copyToClipboard(text: string, type: 'id' | 'password') {
navigator.clipboard.writeText(text).then(() => {
async function copyToClipboard(text: string, type: 'id' | 'password') {
const success = await clipboardCopy(text)
if (success) {
rustdeskCopied.value = type
setTimeout(() => (rustdeskCopied.value = null), 2000)
})
}
}
function getRustdeskServiceStatusText(status: string | undefined): string {