index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <a class="click-to-copy" :info="info" @click="!copyAni && copy()">
  3. <span :class="`ax-ctc-btn ${copyAni && 'fade'}`">点击复制</span>
  4. <svg :class="`ax-svg-container ${copyAni && 'show'}`">
  5. <polyline :points="`5, 8 12, 15 25, 5`" />
  6. </svg>
  7. </a>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'ClickToCopy',
  12. props: ['info', 'btnTip'],
  13. data () {
  14. return {
  15. copyAni: false
  16. }
  17. },
  18. methods: {
  19. copy () {
  20. const { doCopyAction, doCopyTip } = this
  21. doCopyAction()
  22. doCopyTip()
  23. },
  24. doCopyAction () {
  25. const { info } = this
  26. const inputEle = document.createElement('input')
  27. inputEle.value = info
  28. document.body.appendChild(inputEle)
  29. inputEle.select()
  30. document.execCommand('copy')
  31. inputEle.parentNode.removeChild(inputEle)
  32. },
  33. doCopyTip () {
  34. this.copyAni = true
  35. setTimeout(() => {
  36. this.copyAni = false
  37. }, 1000)
  38. }
  39. }
  40. }
  41. </script>
  42. <style lang="less">
  43. .click-to-copy {
  44. position: relative;
  45. cursor: pointer;
  46. .fade {
  47. opacity: 0 !important;
  48. }
  49. .show {
  50. opacity: 1 !important;
  51. polyline {
  52. stroke-dasharray: 30 30 !important;
  53. }
  54. }
  55. .ax-ctc-btn {
  56. opacity: 1;
  57. transition: all 0.3s;
  58. }
  59. .ax-svg-container {
  60. position: absolute;
  61. left: 50%;
  62. top: 50%;
  63. width: 30px;
  64. height: 20px;
  65. transform: translate(-50%, -50%);
  66. opacity: 0;
  67. transition: all 0.3s;
  68. polyline {
  69. fill: none;
  70. stroke: #46bd87;
  71. stroke-width: 3;
  72. stroke-dasharray: 0 30;
  73. transition: all 0.5s;
  74. }
  75. }
  76. }
  77. </style>