123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <template>
- <div class="baseTopo" id="baseTopo" ref="baseTopo">
- <topoTooltip
- v-show="showTooltip"
- class="topoTooltip-box"
- ref="topoTooltip"
- @closeTooltip="showTooltip = false"
- :havItem="havItem"
- ></topoTooltip>
- <canvas
- id="persagy_topo"
- :width="canvasWidth"
- :height="canvasHeight"
- tabindex="0"
- ></canvas>
- </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 topoTooltip from "./topoTooltip.vue";
- import { mapState, mapMutations } from "vuex";
- import bus from "@/bus/bus";
- import { saveGroup, readGroup, uploadGroup, getImageGroup } from "@/api/editer";
- export default {
- components: { topoTooltip },
- data() {
- return {
- scene: null,
- view: null,
- canvasWidth: 700,
- canvasHeight: 700,
- havItem: false,
- showTooltip: false,
- };
- },
- computed: {
- ...mapState(["editCmd", "legendObj", "graphId", "id", "categoryId","projectId"]),
- },
- mounted() {
- 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.scene = this.scene;
- this.scene.clearCmdStatus = this.clearCmdStatus;
-
- this.initBusEvent();
-
- this.scene.getItem = this.onContextMenu;
- this.scene.emitChoice = this.emitChoice;
-
- this.scene.vueOnMouseDown = this.vueOnMouseDown;
-
- document.getElementById("baseTopo").oncontextmenu = function (e) {
- return false;
- };
-
- this.readtopoMsg();
-
-
- },
- methods: {
- ...mapMutations([
- "SETCHOICELEHEND",
- "SETLEGENDOBJ",
- "SETPROJECT",
- "SETCATEGROY",
- ]),
-
- clearCmdStatus() {
- this.SETCHOICELEHEND("");
- this.SETLEGENDOBJ(null);
- },
-
- onContextMenu(item, [event]) {
- this.showTooltip = true;
- if (item) {
- this.havItem = true;
- } else {
- this.havItem = false;
- }
- const doms = document.getElementsByClassName("topoTooltip-box")[0];
- doms.style.left = event.offsetX + "px";
- doms.style.top = event.offsetY + "px";
- },
-
- vueOnMouseDown(e) {
-
- this.showTooltip = false;
- },
-
- emitChoice(itemList) {
- bus.$emit("emitChoice", itemList);
- },
-
- initBusEvent() {
-
- bus.$on("updateStyle", (type, val) => {
- this.scene.updateStyle(type, val);
- });
-
- bus.$on("topoUndo", (val) => {
- this.scene.undo();
- });
-
- bus.$on("topoRedo", (val) => {
- this.scene.redo();
- });
-
- bus.$on("deleteItem", (val) => {
- this.scene.deleteItem();
- });
-
- bus.$on("copy", (val) => {
- this.scene.copy();
- });
-
- bus.$on("paste", (val) => {
- this.scene.paste();
- });
-
- bus.$on("saveTopo", (val) => {
- const elements = this.scene.save();
- const obj = {
- elements,
- name: "1",
- categoryId: this.categoryId,
- projectId: this.projectId,
- buildingId: "1",
- floorId: "1",
- note: "1",
- log: {
-
- mark: "1",
- commandList: [
- {
- command: "1",
- desc: "1",
- detail: "1",
- },
- ],
- },
- };
- Object.assign(obj, {
- graphId: this.graphId,
- id: this.id,
- });
- console.log(obj);
- saveGroup(obj).then((res) => {
- console.log("res", res);
- });
- });
-
- bus.$on("setOrder", (val) => {
- this.scene.setOrder(val);
- });
-
- bus.$on("setItemStatus", (val) => {
- this.scene.setItemStatus();
- });
- },
-
- readtopoMsg() {
- let obj = {
- graphId: this.graphId,
- id: this.id,
- };
- readGroup(obj).then((res) => {
- this.SETCATEGROY(res.content.categoryId);
- const parse = new PTopoParser();
- parse.parseData(res.content.elements);
- parse.markers.forEach((item) => {
- item.selectable = true;
- item.moveable = true;
- item.connect("finishCreated", this.scene, this.scene.finishCreated);
- item.connect("onContextMenu", this, this.scene.getItem);
- this.scene.addItem(item);
- });
- });
- },
- readMapmsg() {
- let parser = new SFloorParser();
- const msg = require("./../../assets/map/1.json");
- parser.parseData(msg.EntityList[0].Elements);
- parser.spaceList.forEach((t) => this.scene.addItem(t));
- parser.wallList.forEach((t) => this.scene.addItem(t));
- parser.virtualWallList.forEach((t) => this.scene.addItem(t));
- parser.doorList.forEach((t) => this.scene.addItem(t));
- parser.columnList.forEach((t) => this.scene.addItem(t));
- parser.casementList.forEach((t) => this.scene.addItem(t));
- this.view.fitSceneToView();
- },
- },
- watch: {
- editCmd(val) {
- console.log("val", val);
- if (this.scene) {
-
- this.scene.editCmd = val;
- }
- },
- legendObj: {
- handler: function (val, oldVal) {
- this.scene.legendObj = val;
- },
- deep: true,
- },
- },
- created() {
- console.log(this.$route.query)
-
- },
- };
- </script>
- <style lang="less" scoped>
- .baseTopo {
- width: 100%;
- height: 100%;
- position: relative;
- .topoTooltip-box {
- position: absolute;
- left: 0;
- top: 0;
- }
- }
- </style>
|