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.

48 lines
1.7 KiB

12 months ago
  1. import { notification } from 'antd';
  2. import './axios'
  3. export const splitAddress = (address: string, index?: number) => {
  4. try {
  5. let idx = index ? index : 5;
  6. return address.substring(0, idx) + '...' + address.substring(address.length - idx, address.length)
  7. } catch (error) {
  8. return ''
  9. }
  10. }
  11. export const getTime = (value: number) => {
  12. let date = new Date(value);
  13. let yy: number | string = date.getFullYear();
  14. let mm: number | string = date.getMonth() + 1;
  15. let dd: number | string = date.getDate();
  16. let xs: number | string = date.getHours();
  17. let ff: number | string = date.getMinutes();
  18. let ss: number | string = date.getSeconds();
  19. mm = mm >= 10 ? mm : '0' + mm;
  20. dd = dd >= 10 ? dd : '0' + dd;
  21. xs = xs >= 10 ? xs : '0' + xs;
  22. ff = ff >= 10 ? ff : '0' + ff;
  23. ss = ss >= 10 ? ss : '0' + ss;
  24. return `${yy}-${mm}-${dd} ${xs}:${ff}:${ss}`
  25. };
  26. export function copy(value: string) {
  27. // 动态创建 textarea 标签
  28. const textarea: any = document.createElement('textarea')
  29. // 将该 textarea 设为 readonly 防止 iOS 下自动唤起键盘,同时将 textarea 移出可视区域
  30. textarea.readOnly = 'readonly'
  31. textarea.style.position = 'absolute'
  32. textarea.style.left = '-9999px'
  33. // 将要 copy 的值赋给 textarea 标签的 value 属性
  34. // 网上有些例子是赋值给innerText,这样也会赋值成功,但是识别不了\r\n的换行符,赋值给value属性就可以
  35. textarea.value = value
  36. // 将 textarea 插入到 body 中
  37. document.body.appendChild(textarea)
  38. // 选中值并复制
  39. textarea.select()
  40. textarea.setSelectionRange(0, textarea.value.length)
  41. document.execCommand('Copy')
  42. document.body.removeChild(textarea)
  43. notification.success({
  44. message: '复制成功'
  45. })
  46. }