baseTopoEditer.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="baseTopo" id="baseTopo" ref="baseTopo">
  3. <topoTooltip v-show="showTooltip" class="topoTooltip-box" ref="topoTooltip" :havItem="havItem"></topoTooltip>
  4. <canvas id="persagy_topo" :width="canvasWidth" :height="canvasHeight" tabindex="0"></canvas>
  5. </div>
  6. </template>
  7. <script>
  8. import { PTopoScene, PTopoParser } from "@/components/editClass/persagy-edit";
  9. import { SGraphView } from "@persagy-web/graph";
  10. import topoTooltip from "./topoTooltip.vue";
  11. import { mapState, mapMutations } from "vuex";
  12. import bus from "@/bus/bus";
  13. import { saveGroup, readGroup } from "@/api/editer";
  14. export default {
  15. components: { topoTooltip },
  16. data() {
  17. return {
  18. scene: null, //场景
  19. view: null, //视图
  20. canvasWidth: 700, //画布宽
  21. canvasHeight: 700, //画布高
  22. havItem: false, //右击是否选中item
  23. showTooltip: false, //是否显示tooltip
  24. };
  25. },
  26. computed: {
  27. ...mapState(["choiceLegend"]),
  28. },
  29. mounted() {
  30. this.canvasWidth = this.$refs.baseTopo.offsetWidth;
  31. this.canvasHeight = this.$refs.baseTopo.offsetHeight - 10;
  32. this.scene = new PTopoScene();
  33. this.view = new SGraphView("persagy_topo");
  34. this.view.scene = this.scene;
  35. this.scene.clearCmdStatus = this.clearCmdStatus;
  36. // 初始化bus绑定事件
  37. this.initBusEvent();
  38. // 右键事件
  39. this.scene.getItem = this.onContextMenu;
  40. this.scene.emitChoice = this.emitChoice;
  41. //左键事件
  42. this.scene.vueOnMouseDown = this.vueOnMouseDown;
  43. // 屏蔽浏览器右键功能(防止与编辑器右键交互重合)
  44. document.getElementById("baseTopo").oncontextmenu = function (e) {
  45. return false;
  46. };
  47. // 读取底图
  48. this.readtopoMsg();
  49. },
  50. methods: {
  51. ...mapMutations(["SETCHOICELEHEND"]),
  52. // 恢复命令状态
  53. clearCmdStatus() {
  54. this.SETCHOICELEHEND("");
  55. },
  56. // 右键获取item
  57. onContextMenu(item, [event]) {
  58. this.showTooltip = true;
  59. console.log(item);
  60. if (item) {
  61. this.havItem = true;
  62. } else {
  63. this.havItem = false;
  64. }
  65. const doms = document.getElementsByClassName("topoTooltip-box")[0];
  66. doms.style.left = event.offsetX + "px";
  67. doms.style.top = event.offsetY + "px";
  68. },
  69. // 左键事键
  70. vueOnMouseDown(e) {
  71. // 关闭tooltip
  72. this.showTooltip = false;
  73. },
  74. // 选中后的回调函数
  75. emitChoice(itemList) {
  76. bus.$emit("emitChoice", itemList);
  77. },
  78. //初始化bus绑定事件
  79. initBusEvent() {
  80. // 改变样式
  81. bus.$on("updateStyle", (type, val) => {
  82. this.scene.updateStyle(type, val);
  83. });
  84. // 撤销
  85. bus.$on("topoUndo", (val) => {
  86. this.scene.undo();
  87. });
  88. // 重做
  89. bus.$on("topoRedo", (val) => {
  90. this.scene.redo();
  91. });
  92. // 删除
  93. bus.$on("deleteItem", (val) => {
  94. this.scene.deleteItem();
  95. });
  96. // 复制
  97. bus.$on("copy", (val) => {
  98. this.scene.copy();
  99. });
  100. // 粘贴
  101. bus.$on("paste", (val) => {
  102. this.scene.paste();
  103. });
  104. // 保存
  105. bus.$on("saveTopo", (val) => {
  106. const Elements = this.scene.save();
  107. const obj = {
  108. Elements,
  109. Name: "1", // 名称
  110. CategoryID: "1", // 图分类ID
  111. ProjectID: "1", // 项目ID
  112. BuildingID: "1", // 建筑ID
  113. FloorID: "1", // 楼层id
  114. Note: "1", // 图说明
  115. Log: {
  116. // 图操作日志
  117. Mark: "1", // 图的存盘标记
  118. CommandList: [
  119. {
  120. Command: "1", // 命令
  121. Desc: "1", // 描述
  122. Detail: "1", // 详情
  123. },
  124. ],
  125. },
  126. };
  127. Object.assign(obj, {
  128. GraphId: "6500f7d6db5a40d4be4313ea654b1373",
  129. Id: "d6c1926ee74b438d87c6b06fec9806c6",
  130. });
  131. console.log(obj);
  132. saveGroup(obj).then((res) => {
  133. console.log("res", res);
  134. });
  135. });
  136. },
  137. // 读取拓扑图
  138. readtopoMsg() {
  139. let obj = {
  140. GraphId: "6500f7d6db5a40d4be4313ea654b1373",
  141. Id: "d6c1926ee74b438d87c6b06fec9806c6",
  142. };
  143. readGroup(obj).then((res) => {
  144. console.log("resssssss", res);
  145. const parse = new PTopoParser();
  146. parse.parseData(res.Content.Elements);
  147. console.log(parse.Markers);
  148. parse.Markers.forEach((item) => {
  149. this.scene.addItem(item);
  150. });
  151. console.log(this.scene);
  152. });
  153. },
  154. },
  155. watch: {
  156. choiceLegend(val) {
  157. if (this.scene) {
  158. // 设置当前编辑状态
  159. this.scene.editCmd = this.choiceLegend;
  160. }
  161. },
  162. },
  163. };
  164. </script>
  165. <style lang="less" scoped>
  166. .baseTopo {
  167. width: 100%;
  168. height: 100%;
  169. position: relative;
  170. .topoTooltip-box {
  171. position: absolute;
  172. left: 0;
  173. top: 0;
  174. }
  175. }
  176. </style>