share.vue 3.7 KB

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