drawFloor.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div :id="`drawFloor${id}`" class="drawFloor" v-loading="canvasLoading">
  3. <canvas :id="`floorCanvas${id}`" :width="cadWidth" :height="cadHeight" ref="canvas" tabindex="0"></canvas>
  4. <div class="operate" v-if="showTools">
  5. <canvasFun @fit="fit" @savePng="savePng" @saveSvg="saveSvg" @divide="divide" @clearDivide="clearDivide" @undo="undo" @redo="redo" @scale="scale"
  6. @changeAbsorb="changeAbsorb" :config="config" ref="canvasFun" @saveJson="saveJson"></canvasFun>
  7. </div>
  8. </div>
  9. </template>
  10. <script>
  11. import { SGraphyView } from "@saga-web/graphy/lib";
  12. import { DivideFloorScene, FloorView } from "@saga-web/cad-engine/lib"
  13. import { SColor, SPoint } from "@saga-web/draw/lib";
  14. import canvasFun from "@/components/business_space/newGraphy/canvasFun"
  15. import { floorQuery } from "@/api/scan/request";
  16. export default {
  17. components: {
  18. canvasFun
  19. },
  20. data() {
  21. return {
  22. drawMainScene: null,
  23. view: null,
  24. dataKey: '',
  25. cadWidth: 800,
  26. cadHeight: 600,
  27. canvasLoading: false,
  28. modelId: '',
  29. FloorID: '',
  30. Outline: [],
  31. floorData: {},
  32. config: {
  33. isEdit: false,
  34. divide: true
  35. }
  36. };
  37. },
  38. props: {
  39. isEdit: {
  40. default: false
  41. },
  42. showTools: {
  43. default: false
  44. },
  45. id: {
  46. default: 0
  47. },
  48. dialog: {
  49. default: false
  50. }
  51. },
  52. created() {
  53. this.FloorID = this.$route.query.FloorID;
  54. if (!this.dialog) {
  55. this.getFloorData();
  56. }
  57. },
  58. mounted() {
  59. this.cadWidth = document.getElementById(`drawFloor${this.id}`).offsetWidth;
  60. this.cadHeight = document.getElementById(`drawFloor${this.id}`).offsetHeight;
  61. },
  62. methods: {
  63. // 初始化canvas
  64. initGraphy(Id, type) {
  65. // type=1 => id:模型id
  66. // type=2 => id:floormap
  67. let that = this;
  68. that.modelId = Id;
  69. that.clearGraphy()
  70. that.drawMainScene = new DivideFloorScene();
  71. that.canvasLoading = true;
  72. if (type == 1) {
  73. that.drawMainScene.getFloorData('/modelapi/base-graph/query', { ModelId: Id }).then(res => {
  74. that.getGraphtSuc(res)
  75. })
  76. } else {
  77. that.drawMainScene.loadUrl(`/image-service/common/file_get?systemId=revit&key=${Id}`).then(res => {
  78. that.getGraphtSuc(res)
  79. })
  80. }
  81. },
  82. // 获取底图成功
  83. getGraphtSuc(res) {
  84. this.canvasLoading = false;
  85. if (res == 'error') {
  86. this.FloorMap = '';
  87. this.$message.warning('数据解析异常');
  88. return;
  89. }
  90. if (res.Result == 'failure') {
  91. this.showTools = false;
  92. this.$message.warning(res.Message);
  93. return;
  94. }
  95. this.view.scene = this.drawMainScene;
  96. this.view.fitSceneToView();
  97. this.drawMainScene.isSpaceSelectable = false;
  98. if (this.$refs.canvasFun) {
  99. this.view.maxScale = this.view.scale * 10;
  100. this.view.minScale = this.view.scale;
  101. this.$refs.canvasFun.everyScale = this.view.scale;
  102. }
  103. if (this.floorData.Outline && this.floorData.Outline.length) {
  104. let newArr = this.floorData.Outline.map(t => {
  105. return new SPoint(t.X, t.Y);
  106. })
  107. this.drawMainScene.addSceneMark(newArr)
  108. }
  109. },
  110. // 获取楼层数据
  111. getFloorData() {
  112. let pa = {
  113. Filters: `FloorID='${this.FloorID}'`
  114. }
  115. floorQuery(pa, res => {
  116. this.floorData = res.Content[0];
  117. this.initGraphy(this.floorData.StructureInfo.FloorMap, 2)
  118. })
  119. },
  120. // 清空平面图
  121. clearGraphy() {
  122. if (this.view) {
  123. this.view.scene = null;
  124. return
  125. }
  126. let id = `floorCanvas${this.id}`;
  127. this.view = new FloorView(id)
  128. },
  129. // canvas 获取焦点
  130. focus() {
  131. document.getElementById(`floorCanvas${this.id}`).focus()
  132. },
  133. // 工具栏操作
  134. // 适配底图到窗口
  135. fit() {
  136. this.view.fitSceneToView()
  137. },
  138. // 保存为png
  139. savePng() {
  140. this.view.saveImage(`${this.floor}.png`, 'png');
  141. },
  142. // 保存为svg
  143. saveSvg() {
  144. this.view.saveSceneSvg(`${this.floor}.svg`, 6400, 4800);
  145. },
  146. // 切割划分
  147. divide() {
  148. this.drawMainScene.isMarking = true;
  149. },
  150. // 清除切割划分
  151. clearDivide() {
  152. this.drawMainScene.clearSceneMark()
  153. },
  154. // 吸附
  155. changeAbsorb(isAbsorbing) {
  156. this.drawMainScene.isAbsorbing = isAbsorbing;
  157. },
  158. // 保存json
  159. saveJson() {
  160. this.view.saveFloorJson(`${this.floor}.json`)
  161. },
  162. // 撤销
  163. undo() {
  164. },
  165. // 反撤销
  166. redo() { },
  167. // 缩放
  168. scale(val) {
  169. if (!this.view) {
  170. return;
  171. }
  172. let scale = this.view.scale;
  173. this.view.scaleByPoint(val / scale, this.cadWidth / 2, this.cadHeight / 2)
  174. },
  175. },
  176. watch: {
  177. "view.scale": {
  178. handler(n) {
  179. if (this.$refs.canvasFun) {
  180. this.$refs.canvasFun.sliderVal = n * 10 / this.view.minScale;
  181. }
  182. }
  183. },
  184. "isEdit": {
  185. handler(n) {
  186. this.config.isEdit = n;
  187. }
  188. }
  189. }
  190. };
  191. </script>
  192. <style scoped lang="less">
  193. .drawFloor {
  194. width: 100%;
  195. height: 100%;
  196. position: relative;
  197. .operate {
  198. position: absolute;
  199. left: 50%;
  200. bottom: 20px;
  201. transform: translateX(-50%);
  202. z-index: 99;
  203. }
  204. }
  205. </style>