소스 검색

修改复制组件

1
mo 3 년 전
부모
커밋
f93a6b00c5
1개의 변경된 파일29개의 추가작업 그리고 6개의 파일을 삭제
  1. 29 6
      src/views/liveClassManager/modals/shareDetail.vue

+ 29 - 6
src/views/liveClassManager/modals/shareDetail.vue

@@ -28,7 +28,14 @@
             请在电脑浏览器中打开以上链接进行直播
           </p>
         </div>
-        <div class="shareBtn shareText" @click="copyText">复制分享内容</div>
+        <div
+          class="shareBtn shareText"
+          data-clipboard-action="copy"
+          data-clipboard-target=".shareBtn"
+          @click="copyText"
+        >
+          复制分享内容
+        </div>
       </div>
       <div class="codeWrap" v-if="form.shareType == 2">
         <div class="shareWrap">
@@ -64,13 +71,10 @@ export default {
       content: "",
       url: "",
       Teacherurl: "",
-      clipboard:null
+      clipboard: null,
     };
   },
   mounted() {
-    this.clipboard = new Clipboard(".shareText",{
-      target:this.copyText()
-    });
     this.url =
       vaildStudentUrl() + `/#/liveClassTransfer?roomUid=${this.row.roomUid}`;
     let domain = window.location.domain;
@@ -95,6 +99,25 @@ export default {
         }\n直播地址:${this.url}\n`;
       }
 
+      var clipboard = new Clipboard(".shareText", {
+        text: function (trigger) {
+          return text;
+        },
+      });
+      clipboard.on("success", (e) => {
+        console.log("复制成功");
+        this.$message.success("复制成功");
+        this.$emit("close");
+        // 释放内存
+        clipboard.destroy();
+      });
+      clipboard.on("error", (e) => {
+        // 不支持复制
+        console.log("该浏览器不支持自动复制");
+        // 释放内存
+        clipboard.destroy();
+      });
+
       // if (text) {
 
       //   console.log(clipboard)
@@ -107,7 +130,7 @@ export default {
       //     e.clearSelection();
       //   });
       // }
-      return text
+      // return text
     },
 
     shareImage() {