Bläddra i källkod

修复复制消息

plg 5 dagar sedan
förälder
incheckning
e07839d3ee
3 ändrade filer med 36 tillägg och 5 borttagningar
  1. 1 0
      package.json
  2. 2 0
      src/main.js
  3. 33 5
      src/views/manage/channelManagement/channelManagement.vue

+ 1 - 0
package.json

@@ -24,6 +24,7 @@
     "md5": "^2.3.0",
     "vant": "^2.8.4",
     "vue": "^2.6.10",
+    "vue-clipboard2": "^0.3.3",
     "vue-jsmind": "^1.5.0",
     "vue-power-tree": "0.0.6",
     "vue-qr": "^4.0.9",

+ 2 - 0
src/main.js

@@ -10,6 +10,8 @@ import http from "@/utils/http";
 import ElementUI from 'element-ui';
 import * as echarts from "echarts"
 import jm from 'vue-jsmind'
+import VueClipboard from 'vue-clipboard2'
+Vue.use(VueClipboard)
 Vue.use(jm)
 
 if (window.jsMind) {

+ 33 - 5
src/views/manage/channelManagement/channelManagement.vue

@@ -179,6 +179,9 @@
                 ></i>
                 &nbsp;&nbsp;
                 <i
+                v-clipboard:copy="scope.row.extractCode"
+                  v-clipboard:success="copySuc"
+                  v-clipboard:error="copyFail"
                   title="复制文本"
                   style="color: #00bf78"
                   v-show="
@@ -186,7 +189,7 @@
                     scope.row.extractCode != null &&
                     scope.row.extractCode != ''
                   "
-                  @click="onCopy(scope.row)"
+                
                   class="el-icon-copy-document"
                 ></i>
                 <i
@@ -200,13 +203,16 @@
                 ></i>
                 &nbsp;&nbsp;
                 <i
+                  v-clipboard:copy="scope.row.extractCode"
+                  v-clipboard:success="copySuc"
+                  v-clipboard:error="copyFail"
                   title="复制文本"
                   v-show="
                     !scope.row.isShow &&
                     scope.row.extractCode != null &&
                     scope.row.extractCode != ''
                   "
-                  @click="onCopy(scope.row)"
+               
                   class="el-icon-copy-document"
                 ></i>
               </div>
@@ -476,10 +482,32 @@ export default {
     this.searchTarget();
   },
   methods: {
+    copySuc(){
+    this.$message.success("复制成功")
+},
+
+copyFail(){
+    this.$message.success("复制失败")
+},
     onCopy(row) {
-      navigator.clipboard.writeText(row.extractCode).then(() => {
-        this.$message.success("复制成功");
-      });
+      if (navigator.clipboard && window.isSecureContext) {
+        navigator.clipboard.writeText(row.extractCode).then(() => {
+          this.$message.success("复制成功");
+        });
+      }else {
+        const textArea = document.createElement('textarea')
+        textArea.value = val
+        // 使text area不在viewport,同时设置不可见
+        document.body.appendChild(textArea)
+        textArea.focus()
+        textArea.select()
+        this.$message.success('复制成功')
+        return new Promise((res, rej) => {
+          // 执行复制命令并移除文本框
+          document.execCommand('copy') ? res() : rej()
+          textArea.remove()
+        })
+      }
     },
     titleFormatter(val) {
       if (val.planStatus == "1") {