baseTopoEditer.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <div class="baseTopo" id="baseTopo" ref="baseTopo">
  3. <topoTooltip
  4. v-show="showTooltip"
  5. class="topoTooltip-box"
  6. ref="topoTooltip"
  7. @closeTooltip="showTooltip = false"
  8. :havItem="havItem"
  9. ></topoTooltip>
  10. <canvas
  11. id="persagy_topo"
  12. :width="canvasWidth"
  13. :height="canvasHeight"
  14. tabindex="0"
  15. ></canvas>
  16. </div>
  17. </template>
  18. <script>
  19. import { PTopoScene, PTopoParser } from "@/components/editClass/persagy-edit";
  20. import { SGraphView } from "@persagy-web/graph";
  21. import { SFloorParser } from "@persagy-web/big/lib";
  22. import topoTooltip from "./topoTooltip.vue";
  23. import { mapState, mapMutations } from "vuex";
  24. import bus from "@/bus/bus";
  25. import { saveGroup, readGroup, uploadGroup, getImageGroup } from "@/api/editer";
  26. export default {
  27. components: { topoTooltip },
  28. data() {
  29. return {
  30. scene: null, //场景
  31. view: null, //视图
  32. canvasWidth: 700, //画布宽
  33. canvasHeight: 700, //画布高
  34. havItem: false, //右击是否选中item
  35. showTooltip: false, //是否显示tooltip
  36. };
  37. },
  38. computed: {
  39. ...mapState(["editCmd", "legendObj", "graphId", "id", "categoryId","projectId"]),
  40. },
  41. mounted() {
  42. this.canvasWidth = this.$refs.baseTopo.offsetWidth;
  43. this.canvasHeight = this.$refs.baseTopo.offsetHeight - 10;
  44. this.scene = new PTopoScene();
  45. this.view = new SGraphView("persagy_topo");
  46. this.view.scene = this.scene;
  47. this.scene.clearCmdStatus = this.clearCmdStatus;
  48. // 初始化bus绑定事件
  49. this.initBusEvent();
  50. // 右键事件
  51. this.scene.getItem = this.onContextMenu;
  52. this.scene.emitChoice = this.emitChoice;
  53. //左键事件
  54. this.scene.vueOnMouseDown = this.vueOnMouseDown;
  55. // 屏蔽浏览器右键功能(防止与编辑器右键交互重合)
  56. document.getElementById("baseTopo").oncontextmenu = function (e) {
  57. return false;
  58. };
  59. // 读取底图
  60. this.readtopoMsg();
  61. // 读取平面图-------测试代码
  62. // this.readMapmsg();
  63. },
  64. methods: {
  65. ...mapMutations([
  66. "SETCHOICELEHEND",
  67. "SETLEGENDOBJ",
  68. "SETPROJECT",
  69. "SETCATEGROY",
  70. ]),
  71. // 恢复命令状态
  72. clearCmdStatus() {
  73. this.SETCHOICELEHEND("");
  74. this.SETLEGENDOBJ(null);
  75. },
  76. // 右键获取item
  77. onContextMenu(item, [event]) {
  78. this.showTooltip = true;
  79. if (item) {
  80. this.havItem = true;
  81. } else {
  82. this.havItem = false;
  83. }
  84. const doms = document.getElementsByClassName("topoTooltip-box")[0];
  85. doms.style.left = event.offsetX + "px";
  86. doms.style.top = event.offsetY + "px";
  87. },
  88. // 左键事键
  89. vueOnMouseDown(e) {
  90. // 关闭tooltip
  91. this.showTooltip = false;
  92. },
  93. // 选中后的回调函数
  94. emitChoice(itemList) {
  95. bus.$emit("emitChoice", itemList);
  96. },
  97. //初始化bus绑定事件
  98. initBusEvent() {
  99. // 改变样式
  100. bus.$on("updateStyle", (type, val) => {
  101. this.scene.updateStyle(type, val);
  102. });
  103. // 撤销
  104. bus.$on("topoUndo", (val) => {
  105. this.scene.undo();
  106. });
  107. // 重做
  108. bus.$on("topoRedo", (val) => {
  109. this.scene.redo();
  110. });
  111. // 删除
  112. bus.$on("deleteItem", (val) => {
  113. this.scene.deleteItem();
  114. });
  115. // 复制
  116. bus.$on("copy", (val) => {
  117. this.scene.copy();
  118. });
  119. // 粘贴
  120. bus.$on("paste", (val) => {
  121. this.scene.paste();
  122. });
  123. // 保存
  124. bus.$on("saveTopo", (val) => {
  125. const elements = this.scene.save();
  126. const obj = {
  127. elements,
  128. name: "1", // 名称
  129. categoryId: this.categoryId, // 图分类ID
  130. projectId: this.projectId, // 项目ID
  131. buildingId: "1", // 建筑ID
  132. floorId: "1", // 楼层id
  133. note: "1", // 图说明
  134. log: {
  135. // 图操作日志
  136. mark: "1", // 图的存盘标记
  137. commandList: [
  138. {
  139. command: "1", // 命令
  140. desc: "1", // 描述
  141. detail: "1", // 详情
  142. },
  143. ],
  144. },
  145. };
  146. Object.assign(obj, {
  147. graphId: this.graphId,
  148. id: this.id,
  149. });
  150. console.log(obj);
  151. saveGroup(obj).then((res) => {
  152. console.log("res", res);
  153. });
  154. });
  155. // 设置实例置顶置底
  156. bus.$on("setOrder", (val) => {
  157. this.scene.setOrder(val);
  158. });
  159. // 设置实例status状态
  160. bus.$on("setItemStatus", (val) => {
  161. this.scene.setItemStatus();
  162. });
  163. },
  164. // 读取拓扑图
  165. readtopoMsg() {
  166. let obj = {
  167. graphId: this.graphId,
  168. id: this.id,
  169. };
  170. readGroup(obj).then((res) => {
  171. this.SETCATEGROY(res.content.categoryId);
  172. const parse = new PTopoParser();
  173. parse.parseData(res.content.elements);
  174. parse.markers.forEach((item) => {
  175. item.selectable = true;
  176. item.moveable = true;
  177. item.connect("finishCreated", this.scene, this.scene.finishCreated);
  178. item.connect("onContextMenu", this, this.scene.getItem);
  179. this.scene.addItem(item);
  180. });
  181. });
  182. },
  183. readMapmsg() {
  184. let parser = new SFloorParser();
  185. const msg = require("./../../assets/map/1.json");
  186. parser.parseData(msg.EntityList[0].Elements);
  187. parser.spaceList.forEach((t) => this.scene.addItem(t));
  188. parser.wallList.forEach((t) => this.scene.addItem(t));
  189. parser.virtualWallList.forEach((t) => this.scene.addItem(t));
  190. parser.doorList.forEach((t) => this.scene.addItem(t));
  191. parser.columnList.forEach((t) => this.scene.addItem(t));
  192. parser.casementList.forEach((t) => this.scene.addItem(t));
  193. this.view.fitSceneToView();
  194. },
  195. },
  196. watch: {
  197. editCmd(val) {
  198. console.log("val", val);
  199. if (this.scene) {
  200. // 设置当前编辑状态
  201. this.scene.editCmd = val;
  202. }
  203. },
  204. legendObj: {
  205. handler: function (val, oldVal) {
  206. this.scene.legendObj = val;
  207. },
  208. deep: true,
  209. },
  210. },
  211. created() {
  212. console.log(this.$route.query)
  213. // this.SETPROJECT(this.$route.query);
  214. },
  215. };
  216. </script>
  217. <style lang="less" scoped>
  218. .baseTopo {
  219. width: 100%;
  220. height: 100%;
  221. position: relative;
  222. .topoTooltip-box {
  223. position: absolute;
  224. left: 0;
  225. top: 0;
  226. }
  227. }
  228. </style>