-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
863393d
commit 837a5dd
Showing
2 changed files
with
104 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { message } from "antd"; | ||
|
||
export const copyToClipboard = async (text: string, successText?: string) => { | ||
if (!navigator?.clipboard) { | ||
message.error("当前浏览器不支持剪贴板操作,请手动复制内容"); | ||
return; | ||
} | ||
|
||
try { | ||
await navigator.clipboard.writeText(text); | ||
message.success(successText ? `${successText} 已成功复制到剪贴板` : "文本已成功复制到剪贴板"); | ||
} catch (err) { | ||
console.error("复制到剪贴板失败:", err); | ||
message.error("复制失败,请手动复制内容"); | ||
} | ||
}; |