share.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="share" :class="{ full: smBtn }">
  3. <div class="main">
  4. <h3>分享页面</h3>
  5. <div class="code">
  6. <img :src="require(`@/assets/img/code${urlNum}.png`)" alt="" />
  7. <p>保存二维码,或点击复制链接</p>
  8. </div>
  9. <div class="btnn" @click="copyPcTxt">复制分享链接</div>
  10. <!-- 关闭按钮 -->
  11. <div class="close" @click="$emit('close')"></div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. export default {
  17. name: "share",
  18. props: {
  19. smBtn: {
  20. type: Boolean,
  21. default: false,
  22. },
  23. },
  24. components: {},
  25. data() {
  26. //这里存放数据
  27. return {
  28. urlNum: "1185",
  29. };
  30. },
  31. //监听属性 类似于data概念
  32. computed: {},
  33. //监控data中的数据变化
  34. watch: {},
  35. //方法集合
  36. methods: {
  37. //点击复制链接
  38. copyPcTxt() {
  39. // 存储传递过来的数据
  40. let OrderNumber = window.location.href;
  41. // 创建一个input 元素
  42. // createElement() 方法通过指定名称创建一个元素
  43. let newInput = document.createElement("input");
  44. // 讲存储的数据赋值给input的value值
  45. newInput.value = OrderNumber;
  46. // appendChild() 方法向节点添加最后一个子节点。
  47. document.body.appendChild(newInput);
  48. // 选中input元素中的文本
  49. // select() 方法用于选择该元素中的文本。
  50. newInput.select();
  51. // 执行浏览器复制命令
  52. // execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令
  53. document.execCommand("Copy");
  54. // 清空输入框
  55. newInput.remove();
  56. // 下面是element的弹窗 不需要的自行删除就好
  57. alert("复制成功");
  58. },
  59. },
  60. //生命周期 - 创建完成(可以访问当前this实例)
  61. created() {
  62. let temp = window.location.hash;
  63. if (temp.includes("1186")) this.urlNum = "1186";
  64. else if (temp.includes("1187")) this.urlNum = "1187";
  65. else if (temp.includes("1188")) this.urlNum = "1188";
  66. },
  67. //生命周期 - 挂载完成(可以访问DOM元素)
  68. mounted() {},
  69. beforeCreate() {}, //生命周期 - 创建之前
  70. beforeMount() {}, //生命周期 - 挂载之前
  71. beforeUpdate() {}, //生命周期 - 更新之前
  72. updated() {}, //生命周期 - 更新之后
  73. beforeDestroy() {}, //生命周期 - 销毁之前
  74. destroyed() {}, //生命周期 - 销毁完成
  75. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  76. };
  77. </script>
  78. <style lang='less' scoped>
  79. .share {
  80. transition: width 0.3s;
  81. color: #fff6d2;
  82. position: fixed;
  83. top: 0;
  84. left: 0;
  85. z-index: 998;
  86. width: calc(100% - 200px);
  87. height: 100%;
  88. &::before {
  89. content: "";
  90. position: absolute;
  91. left: 0;
  92. top: 0;
  93. width: 100%;
  94. height: 100%;
  95. backdrop-filter: blur(10px);
  96. z-index: -1;
  97. }
  98. .main {
  99. border-radius: 10px;
  100. padding-top: 50px;
  101. position: absolute;
  102. top: 50%;
  103. left: 50%;
  104. transform: translate(-50%, -50%);
  105. width: 400px;
  106. height: 550px;
  107. background-color: rgba(161, 101, 59, 0.8);
  108. & > h3 {
  109. font-size: 30px;
  110. text-align: center;
  111. }
  112. .code {
  113. padding-top: 15px;
  114. background-color: #fff6d2;
  115. border-radius: 5px;
  116. width: 260px;
  117. height: 300px;
  118. margin: 30px auto;
  119. text-align: center;
  120. & > img {
  121. width: 240px;
  122. }
  123. & > p {
  124. color: #774926;
  125. margin-top: 15px;
  126. font-size: 12px;
  127. }
  128. }
  129. .btnn {
  130. cursor: pointer;
  131. margin: 0 auto;
  132. width: 260px;
  133. height: 60px;
  134. border-radius: 30px;
  135. border: 2px solid #fff6d2;
  136. font-size: 20px;
  137. color: #fff6d2;
  138. text-align: center;
  139. line-height: 56px;
  140. }
  141. .close {
  142. cursor: pointer;
  143. position: absolute;
  144. right: -18px;
  145. top: -18px;
  146. width: 44px;
  147. height: 44px;
  148. background: url("../../../assets/img/close.png");
  149. background-size: 100% 100%;
  150. }
  151. }
  152. }
  153. .full {
  154. width: 100%;
  155. }
  156. </style>