You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
import { notification } from 'antd'; import './axios'
export const splitAddress = (address: string, index?: number) => { try { let idx = index ? index : 5; return address.substring(0, idx) + '...' + address.substring(address.length - idx, address.length) } catch (error) { return '' } }
export const getTime = (value: number) => { let date = new Date(value); let yy: number | string = date.getFullYear(); let mm: number | string = date.getMonth() + 1; let dd: number | string = date.getDate(); let xs: number | string = date.getHours(); let ff: number | string = date.getMinutes(); let ss: number | string = date.getSeconds(); mm = mm >= 10 ? mm : '0' + mm; dd = dd >= 10 ? dd : '0' + dd; xs = xs >= 10 ? xs : '0' + xs; ff = ff >= 10 ? ff : '0' + ff; ss = ss >= 10 ? ss : '0' + ss; return `${yy}-${mm}-${dd} ${xs}:${ff}:${ss}` };
export function copy(value: string) { // 动态创建 textarea 标签
const textarea: any = document.createElement('textarea') // 将该 textarea 设为 readonly 防止 iOS 下自动唤起键盘,同时将 textarea 移出可视区域
textarea.readOnly = 'readonly' textarea.style.position = 'absolute' textarea.style.left = '-9999px' // 将要 copy 的值赋给 textarea 标签的 value 属性
// 网上有些例子是赋值给innerText,这样也会赋值成功,但是识别不了\r\n的换行符,赋值给value属性就可以
textarea.value = value // 将 textarea 插入到 body 中
document.body.appendChild(textarea) // 选中值并复制
textarea.select() textarea.setSelectionRange(0, textarea.value.length) document.execCommand('Copy') document.body.removeChild(textarea) notification.success({ message: '复制成功' }) }
|