github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/static_source/admin/src/utils/clipboard.ts (about) 1 import {useClipboard} from "@vueuse/core"; 2 import {ElMessage} from "element-plus"; 3 import {unref} from "vue"; 4 import {useI18n} from "@/hooks/web/useI18n"; 5 const {t} = useI18n() 6 7 export const copyToClipboard = async (sourceScript: string) => { 8 const { copy, copied, isSupported } = useClipboard({source: sourceScript}) 9 if (!isSupported) { 10 ElMessage.error(t('setting.copyFailed')) 11 } else { 12 await copy() 13 if (unref(copied)) { 14 ElMessage.success(t('setting.copySuccess')) 15 } 16 } 17 } 18 19 export const pasteFromClipboard = async () => { 20 try { 21 const text = await navigator.clipboard.readText() 22 return text 23 } catch (e) { 24 ElMessage.error(t('setting.copyFailed')) 25 } 26 }