优化代码
This commit is contained in:
@@ -164,6 +164,7 @@
|
||||
stripe
|
||||
v-loading="loading"
|
||||
max-height="500"
|
||||
@cell-dblclick="handleCellDbClick"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<!-- <el-table-column type="selection" width="35" /> -->
|
||||
@@ -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("");
|
||||
//获取屏幕宽度
|
||||
|
||||
Reference in New Issue
Block a user