share.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <div class="intro brightness" v-clickoutside="handleoutside" @touchmove.stop>
  3. <div v-if="!istips">
  4. <p>分享链接给好友</p>
  5. <div class="link" v-html="url"></div>
  6. <div class="btn">
  7. <span
  8. @click.stop="$emit('close')"
  9. >
  10. 取消
  11. </span>
  12. <span ref="btn" class="submit" :data-clipboard-text="url">
  13. 一键复制
  14. </span>
  15. </div>
  16. <img
  17. class="close"
  18. @click.stop="$emit('close')"
  19. :src="require('@/assets/images/close.png')"
  20. />
  21. </div>
  22. <transition name="fade">
  23. <div class="tips" v-if="istips">
  24. 场景链接复制成功
  25. </div>
  26. </transition>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. methods: {
  32. handleoutside() {
  33. this.$emit("close");
  34. },
  35. },
  36. mounted() {
  37. let copy = new window.ClipboardJS(this.$refs.btn);
  38. copy.on("success", (e) => {
  39. this.istips = true
  40. setTimeout(() => {
  41. this.istips = false
  42. this.$emit('close')
  43. }, 3000);
  44. e.clearSelection();
  45. });
  46. copy.on("error", (err) => console.log(err));
  47. },
  48. data() {
  49. return {
  50. url: window.location.href.replace('http://','https://'),
  51. istips:false
  52. };
  53. }
  54. };
  55. </script>
  56. <style lang="less" scoped>
  57. @bx: 0 3px 6px rgba(0, 0, 0, 1);
  58. @bc: rgba(12, 91, 246, 0.8);
  59. @animation: 0.3s ease all;
  60. .intro {
  61. text-align: center;
  62. width: 100%;
  63. height: 100%;
  64. position: fixed;
  65. top: 0;
  66. left: 0;
  67. > div {
  68. padding: 10px;
  69. width: 90%;
  70. transform: translate(-50%, -50%);
  71. top: 50%;
  72. left: 50%;
  73. position: fixed;
  74. background-color: rgba(0, 0, 0, 0.5);
  75. border-radius: 10px;
  76. box-sizing: content-box;
  77. > p {
  78. text-align: left;
  79. }
  80. .link {
  81. color: #fff;
  82. text-align: center;
  83. padding: 10px 30px;
  84. word-wrap: break-word;
  85. line-height: 1.5;
  86. margin: 20px 0;
  87. background-color: rgba(0, 0, 0, 0.35);
  88. }
  89. .btn{
  90. width: 100%;
  91. display: flex;
  92. justify-content: space-around;
  93. align-items: center;
  94. margin-bottom: 20px;
  95. >span{
  96. color: #fff;
  97. border: 1px solid #ccc;
  98. background-color: transparent;
  99. border-radius: 30px;
  100. width: 40%;
  101. height: 40px;
  102. line-height: 40px;
  103. }
  104. .submit{
  105. background-color: @color;
  106. border: 1px solid @color;
  107. }
  108. }
  109. .close {
  110. position: absolute;
  111. bottom: -18px;
  112. width: 36px;
  113. padding: 8px;
  114. left: 50%;
  115. transform: translateX(-50%);
  116. border-radius: 30px;
  117. box-shadow: @bx;
  118. background-color: @bc;
  119. }
  120. }
  121. .tips{
  122. position: absolute;
  123. top: 50%;
  124. left: 50%;
  125. transform: translate(-50%,-50%);
  126. width: 50%;
  127. padding: 20px 10px;
  128. }
  129. }
  130. </style>