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