Browse Source

Merge branch 'develop' of http://39.106.8.246:3003/web/persagy_topo_editer into develop

YaolongHan 4 years ago
parent
commit
ed23b4ac3a

+ 15 - 1
src/components/editClass/big-edit/SBaseEditScene.ts

@@ -33,6 +33,7 @@ import { uuid } from "./until";
 import { SBaseArrow, SBaseEquipment, SBaseExpainEdit, SBasePipeUninTool, SBasePipe } from "./"
 import { PTopoParser } from "./../persagy-edit/"
 import { SBaseArrowPolyEdit } from './items/SBaseArrowPolyEdit';
+import { SGraphAddListCommand } from '../edit/commands/SGraphAddListCommand';
 
 /**
  * big-edit 场景
@@ -160,6 +161,8 @@ export class SBaseEditScene extends SGraphEditScene {
         item.selectable = true;
         this.addItem(item);
         this.grabItem = item;
+        console.log(this.grabItem);
+        
         item.connect("finishCreated", this, this.finishCreated);
         item.connect("onContextMenu", this, this.getItem);
         if (this.view) {
@@ -474,8 +477,8 @@ export class SBaseEditScene extends SGraphEditScene {
      */
     paste(): void {
         const copyList = JSON.parse(JSON.stringify(this.copyString));
-        console.log('copyList', copyList)
         const parserData = new PTopoParser();
+        const graphItemList: SGraphEdit[] = [];
         parserData.parseData(copyList);
         parserData.markers.forEach((item: SGraphEdit) => {
             item.selectable = true;
@@ -485,11 +488,22 @@ export class SBaseEditScene extends SGraphEditScene {
                 item.pos.y += 10 / this.view.scale
             }
             this.addItem(item);
+            graphItemList.push(item);
         });
+        this.addListCommand(graphItemList);
         this.view ? this.view.update() : '';
     } // Function paste()
 
     /**
+     *  添加多个item命令
+     * 
+     *  @param  itemList       鼠标事件对象
+     */
+    addListCommand(itemList: SGraphEdit[]): void {
+        this.undoStack.push(new SGraphAddListCommand(this, itemList));
+    } // Function addListCommand()
+
+    /**
      * 图例置顶、置底
      *
      * @parm type 设置类型

+ 2 - 0
src/components/editClass/big-edit/items/SBaseArrowPolyEdit.ts

@@ -61,7 +61,9 @@ export class SBaseArrowPolyEdit extends SBaseLineEdit {
 		 * @param data      坐标集合|第一个点坐标
 		 */
 	constructor(parent: SGraphItem | null, data: Marker) {
+		
 		super(parent, data);
+		console.log(data);
 		this.pointChange();
 	} // Constructor
 

+ 79 - 0
src/components/editClass/edit/commands/SGraphAddListCommand.ts

@@ -0,0 +1,79 @@
+/*
+ * *********************************************************************************************************************
+ *
+ *          !!
+ *        .F88X
+ *        X8888Y
+ *      .}888888N;
+ *        i888888N;        .:!              .I$WI:
+ *          R888888I      .'N88~            i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
+ *          .R888888I    .;N8888~          .X8'  "8I.!,/8"  !%NY8`"8I8~~8>,88I
+ *            +888888N;  .8888888Y                                  "&&8Y.}8,
+ *            ./888888N;  .R888888Y        .'}~    .>}'.`+>  i}!    "i'  +/'  .'i~  !11,.:">,  .~]!  .i}i
+ *              ~888888%:  .I888888l      .]88~`1/iY88Ii+1'.R$8$8]"888888888>  Y8$  W8E  X8E  W8888'188Il}Y88$*
+ *              18888888    E8888881    .]W%8$`R8X'&8%++N8i,8N%N8+l8%`  .}8N:.R$RE%N88N%N$K$R  188,FE$8%~Y88I
+ *            .E888888I  .i8888888'      .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
+ *            8888888I  .,N888888~        ~88i"8W,!N8*.I88.}888%F,i$88"F88"  888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
+ *          i888888N'      I888Y          ]88;/EX*IFKFK88X  K8R  .l8W  88Y  ~88}'88E&%8W.X8N``]88!.$8K  .:W8I
+ *        .i888888N;        I8Y          .&8$  .X88!  i881.:%888>I88  ;88]  +88+.';;;;:.Y88X  18N.,88l  .+88/
+ *      .:R888888I
+ *      .&888888I                                          Copyright (c) 2016-2020.  博锐尚格科技股份有限公司
+ *        ~8888'
+ *        .!88~                                                                     All rights reserved.
+ *
+ * *********************************************************************************************************************
+ */
+
+import { SUndoCommand } from '@persagy-web/base/lib';
+import { SGraphCommand, SGraphItem, SGraphScene } from '@persagy-web/graph/lib';
+
+/**
+ * 批量添加 item 命令
+ *
+ * @author 韩耀龙 <han_yao_long@163.com>
+ */
+export class SGraphAddListCommand extends SGraphCommand {
+    /** 命令item对象    */
+    itemList: SGraphItem[];
+    /** 命令名称    */
+    readonly command: string = "AddListCommand"
+    /** 命令item的父类   */
+    parent: SGraphItem | null;
+    constructor(scene: SGraphScene, itemList: SGraphItem[]) {
+        super(scene);
+        this.itemList = itemList;
+        this.parent = itemList[0].parent;
+    }
+    /**
+   * 合并命令
+   *
+   * @return  boolean 是否已执行合并
+   * */
+    mergeWith(command: SUndoCommand): boolean {
+        return false;
+    } // Function mergeWith()
+
+    /**
+     * 重做
+     *
+     * */
+    redo(): void {
+        this.itemList.map((item) => {
+            item.parent = this.parent;
+        })
+        // @ts-ignore
+        this.parent.update();
+    } // Function redo()
+
+    /**
+     * 撤销
+     *
+     * */
+    undo(): void {
+        this.itemList.map((item) => {
+            item.parent = null;
+        })
+        // @ts-ignore
+        this.parent.update();
+    } // Function undo()
+}

+ 24 - 24
src/components/editClass/edit/items/SBaseLineEdit.ts

@@ -162,31 +162,33 @@ export class SBaseLineEdit extends SGraphEdit {
         super(parent);
         this.showSelect = false;
         this.data = data;
-        if (data.style && data.style.default) {
+        if (data.style) {
             // 关于顶点
-            if (data.style.default.line) {
+            if (data.style.line) {
                 let setPointList: SPoint[];
-                setPointList = data.style.default.line.map((i: { x: number; y: number; }) => {
+                setPointList = data.style.line.map((i: { x: number; y: number; }) => {
                     return new SPoint(i.x, i.y)
                 });
                 this.line = setPointList;
             }
-            // 颜色
-            if (data.style.default.strokeColor) {
-                this.strokeColor = new SColor(data.style.default.strokeColor)
-            }
-            // 颜色
-            if (data.style.default.fillColor) {
-                this.fillColor = new SColor(data.style.default.fillColor)
-            }
-            // 线宽
-            if (data.style.default.lineWidth) {
-                this.lineWidth = data.style.default.lineWidth
-            }
-
-            // 线样式
-            if (data.style.default.lineStyle) {
-                this.lineStyle = data.style.default.lineStyle
+            if (data.style.default) {
+                // 颜色
+                if (data.style.default.strokeColor) {
+                    this.strokeColor = new SColor(data.style.default.strokeColor)
+                }
+                // 颜色
+                if (data.style.default.fillColor) {
+                    this.fillColor = new SColor(data.style.default.fillColor)
+                }
+                // 线宽
+                if (data.style.default.lineWidth) {
+                    this.lineWidth = data.style.default.lineWidth
+                }
+    
+                // 线样式
+                if (data.style.default.lineStyle) {
+                    this.lineStyle = data.style.default.lineStyle
+                }
             }
         }
     }
@@ -243,7 +245,6 @@ export class SBaseLineEdit extends SGraphEdit {
         if (event.shiftKey || this._verAndLeve) {
             event = this.compare(event);
         }
-
         if (event.buttons == SMouseButton.LeftButton) {
             if (this.status == SItemStatus.Normal) {
                 // return super.onMouseDown(event);
@@ -359,8 +360,8 @@ export class SBaseLineEdit extends SGraphEdit {
             let dis = SMathUtil.pointDistance(
                 p.x,
                 p.y,
-                this.line[i].x,
-                this.line[i].y
+                this.line[i].x + this.x,
+                this.line[i].y + this.y
             );
             if (dis < len) {
                 len = dis;
@@ -394,7 +395,6 @@ export class SBaseLineEdit extends SGraphEdit {
             t.y = t.y + this.y;
             return t;
         });
-
         this.x = 0;
         this.y = 0;
     } // Function moveToOrigin()
@@ -530,7 +530,7 @@ export class SBaseLineEdit extends SGraphEdit {
     toData(): any {
         this.moveToOrigin()
         const Line = [{ x: this.line[0].x, y: this.line[0].y }, { x: this.line[1].x, y: this.line[1].y }];
-        this.data.style.default.line = Line;
+        this.data.style.line = Line;
         this.data.style.default.lineWidth = this.lineWidth;
         this.data.style.default.lineStyle = this.lineStyle;
         this.data.style.default.strokeColor = this.strokeColor.value;

+ 0 - 2
src/components/editClass/edit/items/SBaseRectEdit.ts

@@ -282,8 +282,6 @@ export class SBaseRectEdit extends SGraphEdit {
             this.status = SItemStatus.Normal;
             this.releaseItem();
             this.$emit("finishCreated");
-            this.width = this.boundingRect().width;
-            this.height = this.boundingRect().height;
         }
 
         this.calRect();

+ 4 - 2
src/components/editClass/persagy-edit/PTopoScene.ts

@@ -1,5 +1,5 @@
 import { SBaseEditScene, SBasePipe,SBaseEquipment } from "./../big-edit";
-import { SGraphEdit, } from "./../edit";
+import { SGraphEdit, SGraphPropertyCommand, } from "./../edit";
 import { SMouseEvent } from "@persagy-web/base/lib";
 import { SGraphSelectContainer, SLineStyle } from "@persagy-web/graph";
 import { SItemStatus } from "@persagy-web/big/lib/enums/SItemStatus";
@@ -124,7 +124,6 @@ export class PTopoScene extends SBaseEditScene {
      * @param itemList? SGraphEdit[] 如果不传入默认使用选择器中选中得item
      */
     updateStyle(styletype: string, changestyle: any, itemList?: SGraphEdit[]): void {
-
         // 如果未传入需要修改样式的item,默认取选择器中的item
         let List = null;
         if (itemList && itemList.length) {
@@ -149,6 +148,9 @@ export class PTopoScene extends SBaseEditScene {
             if (item instanceof SGraphSelectContainer) {
                 return
             }
+            const oldMsg = item[styletype];
+            const newMsg = styleValue;
+            this.undoStack.push(new SGraphPropertyCommand(this, item, styletype, oldMsg, newMsg));
             item[styletype] = styleValue;
         })
 

+ 18 - 1
src/components/editview/baseTopoEditer.vue

@@ -48,6 +48,7 @@ export default {
       havItem: false, //右击是否选中item
       showTooltip: false, //是否显示tooltip
       topoContent: {}, // 读图后存储图所有数据
+      autoSave: null, // 自动保存定时器
     };
   },
   computed: {
@@ -81,6 +82,10 @@ export default {
     };
     // 读取底图
     this.readtopoMsg();
+    // 2分钟自动保存
+    this.autoSave = setInterval(() => {
+      this.autoSaveTopo();
+    }, 120000);
   },
   methods: {
     ...mapMutations([
@@ -238,7 +243,7 @@ export default {
         }
       });
     },
-    // 保存草稿
+    // 生成快照并保存草稿
     saveTopoDraft() {
       const uuid = uuidv1();
       return Promise.all([this.generateSnap(uuid), this.saveDraft(uuid)]).then(
@@ -338,6 +343,15 @@ export default {
         });
       });
     },
+    // 自动保存
+    autoSaveTopo() {
+      console.log(this.scene.undoStack.isChange);
+      if (this.scene && this.scene.undoStack.isChange) {
+        this.saveTopoDraft().then(() => {
+          this.scene.undoStack.isChange = false;
+        });
+      }
+    },
     // 发布草稿
     issueDraft() {
       const pa = {
@@ -417,6 +431,9 @@ export default {
     this.SETISPUB(this.$route.query.isPub);
     this.categoryName = decodeURI(this.$route.query.categoryName);
   },
+  beforeDestroy() {
+    clearInterval(this.autoSave);
+  },
 };
 </script>
 <style lang="less" scoped>