From 3c42cdfe02b7a8e890d19b6bddd1a14365e754d5 Mon Sep 17 00:00:00 2001
From: wupengfei <834520024@qq.com>
Date: 星期五, 30 五月 2025 17:15:35 +0800
Subject: [PATCH] fix: bug

---
 src/utils/common/common.ts |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts
index b05dfc3..72f10aa 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') {
@@ -106,3 +106,42 @@
 export function filterNumbersFromString(str: string) {
   return str.replace(/\D/g, '');
 }
+
+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();
+  }
+}
+
+export function addStarForString(str: string, start = 0, end = 0) {
+  return str.substring(0, start) + '*'.repeat(end - start) + str.substring(end);
+}
+
+export function addStarForEmail(str: string) {
+  const end = str.lastIndexOf('.');
+  return addStarForString(str, 2, end);
+}

--
Gitblit v1.9.1