refactor copy

This commit is contained in:
Fine 2024-11-24 17:05:00 +08:00
parent aff69c057f
commit 1d2031420b

View File

@ -16,18 +16,22 @@
*/ */
import { ElNotification } from "element-plus"; import { ElNotification } from "element-plus";
export default (value: string): void => {
const input = document.createElement("input"); export default (text: string): void => {
input.value = value; navigator.clipboard
document.body.appendChild(input); .writeText(text)
input.select(); .then(() => {
if (document.execCommand("Copy")) {
document.execCommand("Copy");
}
input.remove();
ElNotification({ ElNotification({
title: "Success", title: "Success",
message: "Copied", message: "Copied",
type: "success", type: "success",
}); });
})
.catch((err) => {
ElNotification({
title: "Error",
message: err,
type: "warning",
});
});
}; };