share.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div class="share">
  3. <div class="main">
  4. <div class="top">
  5. <h2>分享展览</h2>
  6. <i class="el-icon-close" @click="$emit('close')"></i>
  7. </div>
  8. <div class="myInput">
  9. https://lanhuapp.com/web/#/item/project/product?tid=de3e5e3
  10. </div>
  11. <div class="btn">
  12. <el-button type="primary" style="width:165px;height:40px" @click="copy">复制链接</el-button>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. name: "share",
  20. components: {},
  21. data() {
  22. //这里存放数据
  23. return {};
  24. },
  25. //监听属性 类似于data概念
  26. computed: {},
  27. //监控data中的数据变化
  28. watch: {},
  29. //方法集合
  30. methods: {
  31. copy(){
  32. // 存储传递过来的数据
  33. let OrderNumber = "9999999999";
  34. // 创建一个input 元素
  35. // createElement() 方法通过指定名称创建一个元素
  36. let newInput = document.createElement("input");
  37. // 讲存储的数据赋值给input的value值
  38. newInput.value = OrderNumber;
  39. // appendChild() 方法向节点添加最后一个子节点。
  40. document.body.appendChild(newInput);
  41. // 选中input元素中的文本
  42. // select() 方法用于选择该元素中的文本。
  43. newInput.select();
  44. // 执行浏览器复制命令
  45. // execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令
  46. document.execCommand("Copy");
  47. // 清空输入框
  48. newInput.remove();
  49. // 下面是element的弹窗 不需要的自行删除就好
  50. this.$message({
  51. message: "复制成功",
  52. type: "success",
  53. });
  54. }
  55. },
  56. //生命周期 - 创建完成(可以访问当前this实例)
  57. created() {},
  58. //生命周期 - 挂载完成(可以访问DOM元素)
  59. mounted() {},
  60. beforeCreate() {}, //生命周期 - 创建之前
  61. beforeMount() {}, //生命周期 - 挂载之前
  62. beforeUpdate() {}, //生命周期 - 更新之前
  63. updated() {}, //生命周期 - 更新之后
  64. beforeDestroy() {}, //生命周期 - 销毁之前
  65. destroyed() {}, //生命周期 - 销毁完成
  66. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  67. };
  68. </script>
  69. <style lang='less' scoped>
  70. .share {
  71. position: fixed;
  72. top: 0;
  73. left: 0;
  74. z-index: 9999;
  75. width: 100vw;
  76. height: 100vh;
  77. .main {
  78. padding: 20px;
  79. border-radius: 3px;
  80. position: absolute;
  81. top: 50%;
  82. left: 50%;
  83. transform: translate(-50%, -50%);
  84. z-index: 9999;
  85. width: 500px;
  86. height: 220px;
  87. background: url("../../../assets/img/bg.png") no-repeat left bottom #b7cdd9;
  88. .top {
  89. margin-bottom: 20px;
  90. display: flex;
  91. justify-content: space-between;
  92. align-items: center;
  93. color: #165491;
  94. font-weight: 700;
  95. font-size: 22px;
  96. & > i {
  97. cursor: pointer;
  98. font-size: 30px;
  99. }
  100. }
  101. .myInput {
  102. overflow: hidden;
  103. text-overflow: ellipsis;
  104. white-space: nowrap;
  105. padding: 0 10px;
  106. width: 100%;
  107. height: 60px;
  108. line-height: 60px;
  109. background-color: #fff;
  110. border-radius: 5px;
  111. }
  112. .btn{
  113. margin-top: 20px;
  114. width: 100%;
  115. display: flex;
  116. justify-content: center;
  117. height: 40px;
  118. }
  119. }
  120. }
  121. </style>