fix:复制问题
This commit is contained in:
1 parent
57950c6aa1
commit
2b13ca2e91
1 file changed
+43
-8
@@ -176,14 +176,49 @@ const openForm = () => {
|
||||
}
|
||||
|
||||
/** 复制到剪贴板方法 */
|
||||
const copyToClipboard = (text: string) => {
|
||||
navigator.clipboard.writeText(text).then(() => {
|
||||
message.success('复制成功')
|
||||
}).catch((error) => {
|
||||
message.error('复制失败')
|
||||
console.log('复制失败',error)
|
||||
})
|
||||
}
|
||||
// const copyToClipboard = (text: string) => {
|
||||
// navigator.clipboard.writeText(text).then(() => {
|
||||
// message.success('复制成功')
|
||||
// }).catch((error) => {
|
||||
// message.error('复制失败')
|
||||
// console.log('复制失败',error)
|
||||
// })
|
||||
// }
|
||||
const copyToClipboard = async (text) => {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
ElMessage.success('复制成功');
|
||||
} catch (error) {
|
||||
// 降级到传统方法
|
||||
fallbackCopy(text);
|
||||
}
|
||||
} else {
|
||||
fallbackCopy(text);
|
||||
}
|
||||
};
|
||||
|
||||
const fallbackCopy = (text) => {
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
textArea.style.position = 'fixed';
|
||||
textArea.style.opacity = '0';
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
|
||||
try {
|
||||
const successful = document.execCommand('copy');
|
||||
if (successful) {
|
||||
ElMessage.success('复制成功');
|
||||
} else {
|
||||
ElMessage.error('复制失败');
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('复制功能不支持');
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
|
||||
Reference in new issue
Block a user