From 73d8b38f993f673fdc7c01c892f4c5453abdf240 Mon Sep 17 00:00:00 2001 From: pengxiaolong <15716207+pengxiaolong711@user.noreply.gitee.com> Date: Thu, 25 Sep 2025 21:23:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/hosts/hostsList.vue | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/views/hosts/hostsList.vue b/src/views/hosts/hostsList.vue index 7b6d3f7..34585d4 100644 --- a/src/views/hosts/hostsList.vue +++ b/src/views/hosts/hostsList.vue @@ -164,6 +164,7 @@ stripe v-loading="loading" max-height="500" + @cell-dblclick="handleCellDbClick" @selection-change="handleSelectionChange" > @@ -352,6 +353,60 @@ import { ElMessage, ElMessageBox } from "element-plus"; import { color } from "echarts"; import { getCountryName } from "@/utils/countryUtil"; import { ElLoading } from "element-plus"; + + +//复制单元格内容 +function handleCellDbClick(row, column, cell, event) { + const text = cell?.textContent?.trim(); + if (!text) { + ElMessage({ + type: "warning", + message: "无内容可复制", + }); + return; + } + copyToClipboard(text); +} + +//复制到剪切板 +async function copyToClipboard(text) { + try { + // 尝试使用现代Clipboard API + if (navigator.clipboard) { + await navigator.clipboard.writeText(text); + ElMessage({ + type: "success", + message: "复制成功", + }); + return; + } + + // 备用方法:使用document.execCommand + const textarea = document.createElement('textarea'); + textarea.value = text; + document.body.appendChild(textarea); + textarea.select(); + + if (document.execCommand('copy')) { + ElMessage({ + type: "success", + message: "复制成功", + }); + } else { + throw new Error('execCommand failed'); + } + + document.body.removeChild(textarea); + } catch (err) { + console.error('复制失败:', err); + ElMessage({ + type: "error", + message: "复制失败", + }); + } +} + + //ip国家 let countryData = ref(""); //获取屏幕宽度