| 123456789101112131415161718192021222324 |
- import { IBestToast } from '@ibestservices/ibest-ui';
- import { pasteboard } from '@kit.BasicServicesKit';
- export function copyText(text: string, showToast: boolean = true) {
- const pasteboardData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text);
- const systemPasteboard = pasteboard.getSystemPasteboard();
- systemPasteboard.setData(pasteboardData); // 将数据放入剪切板
- systemPasteboard.getData().then((data) => {
- if (data) {
- if (showToast) {
- IBestToast.show({
- type: "success",
- message: "复制成功"
- })
- }
- } else {
- IBestToast.show({
- type: "fail",
- message: "复制失败"
- })
- }
- })
- }
|