Explorar o código

长连接粘贴板

walter hai 6 meses
pai
achega
cda940b9ea

+ 21 - 5
src/point/view/integral/integral_application.vue

@@ -146,7 +146,7 @@
         </div>
         <div class="flex-box-end" style="margin-top: 20px;" >
           <van-button type="info" :disabled="rwsBusinessProgress < 100" @click="rwsBusinessData.showBusiness = false" size="small">确 定</van-button>
-          <van-tag style="margin-left: 0.2rem;" @click="rwsClipResult">{{rwsBusinessData.result.length}} / {{rwsBusinessData.dataList.length}}</van-tag>
+          <van-tag ref="copyResult" style="margin-left: 0.2rem;" @click.prevent.stop="rwsClipResult">{{rwsBusinessData.result.length}} / {{rwsBusinessData.dataList.length}}</van-tag>
         </div>
       </div>
     </van-popup>
@@ -164,6 +164,7 @@ import {Switch,Progress,Icon  } from 'vant'
 import RuleScopeSelector from "../../../components/RuleScopeSelector.vue";
 import ReconnectingWebSocket from "reconnecting-websocket";
 import {generateUUID, getToken} from "../../../utils/auth";
+import Clipboard from "clipboard";
 
 Vue.use(Switch).use(Progress).use(Icon)
 
@@ -230,7 +231,8 @@ export default {
         msgQueue:[],
         result:[],
         intervalId:null,
-      }
+      },
+      rwsCopyResult:null,
     }
   },
   computed:{
@@ -516,6 +518,7 @@ export default {
       this.rwsBusinessData.dataList = [];
       this.rwsBusinessData.msgQueue = [];
       this.rwsBusinessData.result = [];
+      this.rwsBusinessData.copyResult = null;
       if (this.rwsBusinessData.intervalId) clearInterval(this.rwsBusinessData.intervalId);
       this.rwsBusinessData.intervalId = null;
     },
@@ -631,9 +634,22 @@ export default {
       /*开始提交*/
       this.rwsIntegralApplication();
     },
-    rwsClipResult(){
-      navigator.clipboard.writeText(JSON.stringify(this.rwsBusinessData.result));
-      this.$notify({type: 'info', message: '结果已经复制到剪切板'})
+    rwsClipResult(event){
+      const clipboard = new Clipboard(event.target,{
+        text: () => JSON.stringify(this.rwsBusinessData.result)
+      });
+      clipboard.on('success',() => {
+        this.$notify({type: 'info', message: '复制成功'});
+        clipboard.destroy();
+      });
+      clipboard.on('error', () => {
+        this.$notify({type: 'info', message: '复制失败,请联系系统管理员'});
+        clipboard.destroy();
+      });
+      clipboard.onClick(event);
+
+      // navigator.clipboard.writeText(JSON.stringify(this.rwsBusinessData.result));
+      // this.$notify({type: 'info', message: '结果已经复制到剪切板'})
     },
     rwsIntegralApplication(){
       let msg = this.rwsBusinessData.msgQueue.shift();

+ 17 - 4
src/point/view/integral/integral_entry_n.vue

@@ -155,7 +155,7 @@
 <!--        </div>-->
         <div class="flex-box-end" style="margin-top: 20px;">
           <van-button type="info" :disabled="rwsBusinessProgress < 100" @click="rwsBusinessData.showBusiness = false" size="small" >确 定</van-button>
-          <van-tag style="margin-left: 0.2rem;" @click="rwsClipResult">{{rwsBusinessData.result.length}} / {{rwsBusinessData.dataList.length}}</van-tag>
+          <van-tag style="margin-left: 0.2rem;" @click.prevent.stop="rwsClipResult">{{rwsBusinessData.result.length}} / {{rwsBusinessData.dataList.length}}</van-tag>
         </div>
       </div>
     </van-popup>
@@ -176,6 +176,7 @@ import {Switch,Progress} from 'vant'
 import RuleScopeSelector from "../../../components/RuleScopeSelector.vue";
 import ReconnectingWebSocket from "reconnecting-websocket";
 import {generateUUID, getToken} from "../../../utils/auth";
+import Clipboard from "clipboard";
 
 Vue.use(Switch).use(Progress)
 export default {
@@ -743,9 +744,21 @@ export default {
 
       this.rwsBusinessSubmit(members,items);
     },
-    rwsClipResult(){
-      navigator.clipboard.writeText(JSON.stringify(this.rwsBusinessData.result));
-      this.$notify({type: 'info', message: '结果已经复制到剪切板'})
+    rwsClipResult(event){
+      const clipboard = new Clipboard(event.target,{
+        text: () => JSON.stringify(this.rwsBusinessData.result)
+      });
+      clipboard.on('success',() => {
+        this.$notify({type: 'info', message: '复制成功'});
+        clipboard.destroy();
+      });
+      clipboard.on('error', () => {
+        this.$notify({type: 'info', message: '复制失败,请联系系统管理员'});
+        clipboard.destroy();
+      });
+      clipboard.onClick(event);
+      // navigator.clipboard.writeText(JSON.stringify(this.rwsBusinessData.result));
+      // this.$notify({type: 'info', message: '结果已经复制到剪切板'})
     }
   },
   created () {