From a441299ebbfca9567ced69f669f68569b6f7ca0c Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期五, 12 十二月 2025 09:31:42 +0800
Subject: [PATCH] fix: 修改数据看板
---
src/utils/common/common.ts | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 56 insertions(+), 1 deletions(-)
diff --git a/src/utils/common/common.ts b/src/utils/common/common.ts
index 374c3a8..063053a 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') {
@@ -87,6 +87,31 @@
if (!realPhoneNumber) return '';
return realPhoneNumber.replace(/^(\d{3})(\d*)(\d{4})$/, '$1 $2 $3');
}
+
+ /**
+ * 瀛楃涓茶劚鏁忥細涓棿鏇挎崲涓�*
+ * @param {string} str - 寰呭鐞嗙殑瀛楃涓�
+ */
+ static maskString({ str, start = 3, end = 2 }: { str: string; start?: number; end?: number }) {
+ // 绌哄��/闈炲瓧绗︿覆澶勭悊
+ if (!str || typeof str !== 'string') return str || '';
+
+ const len = str.length;
+ // 杈圭晫鍦烘櫙锛氶暱搴︹墹5鏃讹紝鏃犻渶鏇挎崲锛堝墠3+鍚�2宸茶鐩栧叏閮ㄥ瓧绗︼級
+ if (len <= 5) return str;
+
+ // 鎴彇鍓�3涓瓧绗�
+ const prefix = str.slice(0, start);
+ // 鎴彇鍚�2涓瓧绗�
+ const suffix = str.slice(-end);
+ // 涓棿闇�瑕佹浛鎹㈢殑闀垮害 = 鎬婚暱搴� - 鍓�3 - 鍚�2
+ const middleLength = len - start - end;
+ // 鐢熸垚瀵瑰簲闀垮害鐨�*
+ const middle = '*'.repeat(middleLength);
+
+ // 鎷兼帴缁撴灉
+ return prefix + middle + suffix;
+ }
}
export function paginateList<T>(list: T[], pageIndex: number, pageSize: number) {
@@ -115,3 +140,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