From 0b73bba28e2a8473ab71f5c8b4760c1995ff4fc1 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期二, 21 十月 2025 18:29:07 +0800
Subject: [PATCH] fix: s
---
src/utils/common/common.ts | 32 +++++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts
index 374c3a8..b0d960d 100644
--- a/src/utils/common/common.ts
+++ b/src/utils/common/common.ts
@@ -1,5 +1,5 @@
import dayjs from 'dayjs';
-import { BoleRegExp } from '@bole-core/core';
+import { BoleRegExp, Message } from '@bole-core/core';
import { round, floor, omitBy } from 'lodash';
export function format(date: string | Date, fmt = 'YYYY-MM-DD') {
@@ -115,3 +115,33 @@
}
return roleName;
}
+
+export function copyTextToClipboard(text: string) {
+ if (navigator.clipboard && window.isSecureContext) {
+ // navigator clipboard 鍚戝壀璐存澘鍐欐枃鏈�
+ navigator.clipboard
+ .writeText(text)
+ .then(() => {
+ Message.successMessage('宸插鍒�');
+ })
+ .catch((error) => {
+ console.error('Failed to copy text to clipboard:', error);
+ });
+ } else {
+ // 鍒涘缓text area
+ let textArea = document.createElement('textarea');
+ textArea.value = text;
+ // 浣縯ext area涓嶅湪viewport锛屽悓鏃惰缃笉鍙
+ textArea.style.position = 'absolute';
+ textArea.style.opacity = 0 as any;
+ textArea.style.left = '-999999px';
+ textArea.style.top = '-999999px';
+ document.body.appendChild(textArea);
+ textArea.select();
+ let res = document.execCommand('copy');
+ if (res) {
+ Message.successMessage('宸插鍒�');
+ }
+ textArea.remove();
+ }
+}
--
Gitblit v1.9.1