Procházet zdrojové kódy

跨页复制问题

haojianlong před 4 roky
rodič
revize
cb28df4ea5

+ 5 - 0
src/components/baseEditer.vue

@@ -98,6 +98,11 @@ export default {
         this.scene.setCmd = "choice";
       }
     };
+    // 监听粘贴事件
+    // document.onpaste = e =>{
+    //   const text = e.clipboardData.getData('Text')
+    //   this.scene.crossPagePaste(text)
+    // }
     // 自动保存(时间差为一分钟)
     this.autoSave = setInterval(() => {
       this.saveMsgNoMessage();

+ 99 - 7
src/components/mapClass/EditScence.ts

@@ -1148,13 +1148,6 @@ export class EditScence extends SGraphScene {
      *
      */
     copy(){
-        // const input = document.createElement('input');
-        // console.log(1111111111111111111)
-        // input.value = 'sfsfsfsf'
-        // document.body.appendChild(input);
-        // input.select()
-        // document.execCommand('copy');
-        // input.style.display='none';
         if (this.selectContainer.itemList.length) {
             this.copyString = {
                 Nodes: [],
@@ -1172,7 +1165,19 @@ export class EditScence extends SGraphScene {
                     this.copyString[type].push(data)
                 }
             })
+            // 生成复制字符串
             console.log(this.copyString)
+            return
+            // 获取input dom
+            const input = document.createElement('input');
+            input.setAttribute('id', 'COPYINPUT')
+            input.value = JSON.stringify(this.copyString)
+            document.body.appendChild(input);
+            input.select()
+            document.execCommand('copy');
+            input.style.display='none';
+            console.log(input.value, Date.now());
+            document.body.removeChild(input)
         }
     }
     
@@ -1256,6 +1261,93 @@ export class EditScence extends SGraphScene {
         }
     }
 
+    /**
+     * 跨页面粘贴
+     *
+     */
+    crossPagePaste(crossPageString: string){
+        try {
+            console.log(crossPageString);
+            const pageObj = JSON.parse(crossPageString)
+            
+            const parserData = new STopologyParser(null);
+            // 需要深拷贝
+            parserData.parseData(JSON.parse(JSON.stringify(pageObj)))
+            // 不需要复制区域
+            // parserData.zoneLegendList.forEach(t => {
+            //     if (t instanceof SCustomLegendItem) {
+            //         if (this.view) {
+            //             t.pos.x += 10 / this.view.scale
+            //             t.pos.y += 10 / this.view.scale
+            //         }
+            //         this.addItem(t)
+            //         this.Nodes.push(t);
+            //         graphItemList.push(t)
+            //     }
+            //  // 加到node
+            //  // 加命令
+            // })
+            const graphItemList = [];
+            parserData.imageLegendList.forEach(t => {
+                if (this.view) {
+                    t.pos.x += 10 / this.view.scale
+                    t.pos.y += 10 / this.view.scale
+                }
+                t.moveable = true;
+                this.addItem(t)
+                this.Nodes.push(t);
+                graphItemList.push(t)
+            })
+            parserData.imageMarkerList.forEach(t => {
+                if (this.view) {
+                    t.pos.x += 10 / this.view.scale
+                    t.pos.y += 10 / this.view.scale
+                }
+                t.moveable = true;
+                this.addItem(t)
+                this.Markers.push(t);
+                graphItemList.push(t)
+            })
+            parserData.lineMarkerList.forEach(t => {
+                if (this.view) {
+                    t.pos.x += 10 / this.view.scale
+                    t.pos.y += 10 / this.view.scale
+                }
+                t.moveable = true;
+                this.addItem(t)
+                this.Markers.push(t);
+                graphItemList.push(t)
+            })
+            parserData.textMarkerList.forEach(t => {
+                if (this.view) {
+                    t.pos.x += 10 / this.view.scale
+                    t.pos.y += 10 / this.view.scale
+                }
+                t.moveable = true;
+                this.addItem(t)
+                this.Markers.push(t);
+                graphItemList.push(t)
+            })
+            parserData.relationList.forEach(t => {
+                if (this.view) {
+                    t.pos.x += 10 / this.view.scale
+                    t.pos.y += 10 / this.view.scale
+                    t.moveToOrigin(t.pos.x, t.pos.y)
+                }
+                t.moveable = true;
+                this.addItem(t)
+                this.Relations.push(t);
+                graphItemList.push(t)
+            })
+            this.scenceUpdate(this);
+            if (graphItemList.length) {
+                this.AddListCommand(graphItemList)
+            }
+        } catch (e) {
+            console.log(e);
+        }
+    }
+
     /** 类型转换    */
     itemToType(obj:SGraphItem):String{
         if (obj instanceof STextMarkerItem) {