Browse Source

edit:fix>冲突

YaolongHan 4 years ago
parent
commit
9640a73c34

+ 20 - 0
src/components/editClass/persagy-edit/PTopoView.ts

@@ -0,0 +1,20 @@
+import { SColor, SPainter } from '@persagy-web/draw/lib';
+import { SGraphView } from '@persagy-web/graph/lib';
+
+/**
+ * 拓扑图view
+ *
+ * @author  韩耀龙 <han_yao_long@163.com>
+ */
+export class PTopoView extends SGraphView {
+	/**
+	 * 绘制场景背景
+	 *
+	 * @param painter     绘制对象
+	 */
+	protected drawBackground(painter: SPainter): void {
+		painter.brush.color = SColor.White;
+		painter.pen.color = SColor.Transparent;
+		painter.drawRect(0, 0, this.width, this.height);
+	} // Function drawBackground()
+}

+ 2 - 1
src/components/editClass/persagy-edit/index.ts

@@ -1,4 +1,5 @@
 import { PTopoScene } from "./PTopoScene";
 import { PTopoParser } from "./PTopoParser";
 import { SPersagyImageEdit } from "./item/SPersagyImageEdit"
-export { PTopoParser, PTopoScene, SPersagyImageEdit }
+import { PTopoView } from './PTopoView';
+export { PTopoParser, PTopoScene, SPersagyImageEdit, PTopoView }

+ 15 - 4
src/components/editview/baseTopoEditer.vue

@@ -16,11 +16,16 @@
   </div>
 </template>
 <script>
-import { PTopoScene, PTopoParser } from "@/components/editClass/persagy-edit";
-import { SGraphView } from "@persagy-web/graph";
-import { SFloorParser } from "@persagy-web/big/lib";
+import {
+  PTopoScene,
+  PTopoParser,
+  PTopoView,
+} from "@/components/editClass/persagy-edit";
+// import { SGraphView } from "@persagy-web/graph";
+// import { SFloorParser } from "@persagy-web/big/lib";
 import topoTooltip from "./topoTooltip.vue";
 import { mapState, mapMutations } from "vuex";
+import base64ToFile from "@/utils/base64ToFile";
 import bus from "@/bus/bus";
 import {
   saveGroup,
@@ -57,7 +62,7 @@ export default {
     this.canvasWidth = this.$refs.baseTopo.offsetWidth;
     this.canvasHeight = this.$refs.baseTopo.offsetHeight - 10;
     this.scene = new PTopoScene();
-    this.view = new SGraphView("persagy_topo");
+    this.view = new PTopoView("persagy_topo");
     this.view.scene = this.scene;
     this.scene.clearCmdStatus = this.clearCmdStatus;
     // 初始化bus绑定事件
@@ -193,6 +198,10 @@ export default {
       bus.$on("setItemStatus", (val) => {
         this.scene.setItemStatus();
       });
+      // 下载图片
+      bus.$on("saveTopoImg", () => {
+        this.view.saveImage(`${this.topoContent.name}.png`, "png");
+      });
       // 手动添加设备实例
       bus.$on("addEquipment", (val) => {
         this.addEquipmentList(val);
@@ -270,6 +279,8 @@ export default {
         this.view.fitSceneToView();
       });
     },
+    // 生成快照
+    generateSnap() {},
   },
   watch: {
     editCmd(val) {

+ 14 - 0
src/utils/base64ToFile.js

@@ -0,0 +1,14 @@
+export default function base64ToFile(data) {
+    // 将base64 的图片转换成file对象上传 atob将ascii码解析成binary数据
+    const binary = atob(data.split(',')[1]);
+    const mime = data.split(',')[0].match(/:(.*?);/)[1];
+    const array = [];
+    for (let i = 0; i < binary.length; i++) {
+        array.push(binary.charCodeAt(i));
+    }
+    const fileData = new Blob([new Uint8Array(array)], {
+        type: mime,
+    });
+    const file = new File([fileData], `${new Date().getTime()}.png`, { type: mime });
+    return file;
+}

+ 5 - 1
src/views/editer.vue

@@ -7,7 +7,7 @@
         <div class="project-save">自动保存成功-V2.2</div>
       </div>
       <div class="right">
-        <img src="./../assets/images/download.png" alt />
+        <img @click="saveTopoImg" src="./../assets/images/download.png" alt />
         <img @click="saveTopo" src="./../assets/images/save.png" alt />
         <img @click="issueTopo" src="./../assets/images/issue.png" alt />
       </div>
@@ -29,6 +29,10 @@ export default {
       bus.$emit("saveTopo");
     },
     issueTopo() {},
+    // 下载图片
+    saveTopoImg(){
+      bus.$emit("saveTopoImg")
+    }
   },
 };
 </script>