| | |
| | | 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') { |
| | |
| | | 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) { |
| | |
| | | } |
| | | 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; |
| | | // 使text 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(); |
| | | } |
| | | } |