cenoteGraphy.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div id="cenoteGraphy" style="height:100%;width:100%;" ref="graphy">
  3. <div v-show="!floorMap">
  4. <div class="center" style="height: 400px;padding-top:182px;box-sizing:border-box;">
  5. <i class="icon-wushuju iconfont"></i>
  6. 暂无数据
  7. </div>
  8. </div>
  9. <div class="canvas-box" v-show="floorMap" v-loading="canvasLoading">
  10. <canvas id="floorCanvas" :width="canvasWidth" :height="canvasHeight" ref="canvas" tabindex="0"></canvas>
  11. <el-row class="canvas-actions-box">
  12. <canvasFun @scale="scale" @groupSelect="groupSelect" @fit="fit" @savePng="savePng" @saveSvg="saveSvg" @saveJson="saveJson" :config="config"
  13. ref="canvasFun"></canvasFun>
  14. </el-row>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import canvasFun from "@/components/business_space/newGraphy/canvasFun";
  20. import { SColor, SPoint } from "@saga-web/draw/lib";
  21. import { DivideFloorScene, SpaceItem, ZoneItem } from "@saga-web/cad-engine/lib";
  22. import { FloorView } from "@saga-web/cad-engine/lib/FloorView";
  23. import { colorArr } from '@/utils/spaceColor';
  24. import { getFloorMsgByFloorID, queryZone, shaftSpaceQuery, shaftZoneLink } from '@/api/scan/request';
  25. import { resolve, reject } from 'q';
  26. export default {
  27. data() {
  28. return {
  29. canvasLoading: false,//加载canvas
  30. floorMap: '',//地图
  31. canvasWidth: 800,
  32. canvasHeight: 600,
  33. view: null,
  34. scene: null,
  35. buildingData: [],//建筑,楼层
  36. space: '',//当前空间类型
  37. businessSpaceList: [],//所有业务空间
  38. BSPRelaISPList: [],//已关联元空间的业务空间
  39. zoneList: [], // 业务空间-canvas图中
  40. selectAble: false,
  41. relatedSpaceIdList: [],//已关联的业务空间id
  42. config: {
  43. isEdit: false,
  44. groupSelect: true
  45. },
  46. }
  47. },
  48. mounted() {
  49. this.canvasWidth = this.$refs.graphy.offsetWidth;
  50. this.canvasHeight = this.$refs.graphy.offsetHeight;
  51. },
  52. components: {
  53. canvasFun
  54. },
  55. created() {
  56. },
  57. methods: {
  58. //获取楼层map
  59. getFloorMap(buildfloor, space) {
  60. if (buildfloor.length == 2 && space && buildfloor[1] && buildfloor[0]) {
  61. this.buildingData = buildfloor
  62. let pa = {
  63. Filters: `FloorID='${this.buildingData[1]}'`
  64. }
  65. getFloorMsgByFloorID(pa, res => {
  66. this.floorMap = res.Content[0].StructureInfo ? res.Content[0].StructureInfo.FloorMap : '';
  67. this.space = space;
  68. this.getGraphy();
  69. })
  70. }
  71. else {
  72. this.floorMap = '';
  73. }
  74. },
  75. //加载
  76. load() {
  77. if (this.scene) {
  78. this.scene.clearSpaceSelection();
  79. this.scene.clearZoneSelection();
  80. }
  81. //加载底板
  82. this.getGraphy()
  83. },
  84. //获取底图
  85. getGraphy() {
  86. let that = this;
  87. that.clearGraphy()
  88. that.scene = new DivideFloorScene();
  89. that.canvasLoading = true;
  90. that.scene.loadUrl(`/image-service/common/file_get?systemId=revit&key=${this.floorMap}`).then(res => {
  91. that.canvasLoading = false;
  92. if (res == 'error') {
  93. this.floorMap = '';
  94. this.$message.warning('数据解析异常');
  95. return;
  96. }
  97. that.view.scene = that.scene;
  98. that.scene.isSpaceSelectable = false;
  99. // 绘制业务空间
  100. that.getBusinessSpace();
  101. that.view.fitSceneToView();
  102. that.view.minScale = that.view.scale;
  103. if (that.$refs.canvasFun) {
  104. that.$refs.canvasFun.everyScale = that.view.scale;
  105. }
  106. })
  107. },
  108. // 获取当前分区下的业务空间
  109. getBusinessSpace() {
  110. this.canvasLoading = true
  111. let promise1 = new Promise((resolve, reject) => {
  112. let params = {
  113. data: {
  114. Filters: `not RoomID isNull;ObjectType = '${this.space}';buildingId = '${this.buildingData[0]}';floorId = '${this.buildingData[1]}'`,
  115. Orders: "RoomLocalName desc"
  116. },
  117. ShaftId: this.$route.query.ShaftId
  118. };
  119. shaftSpaceQuery(params, res => {
  120. resolve(res)
  121. })
  122. });
  123. let promise2 = new Promise((resolve, reject) => {
  124. let pa = {
  125. zone: this.space,
  126. data: {
  127. Filters: ``,
  128. Orders: "createTime desc, RoomID asc",
  129. PageSize: 1000
  130. }
  131. }
  132. if (this.buildingData.length && this.buildingData.length > 1) {
  133. pa.data.Filters = `BuildingId='${this.buildingData[0]}';FloorId='${this.buildingData[1]}'`
  134. }
  135. queryZone(pa, res => {
  136. resolve(res);
  137. })
  138. })
  139. Promise.all([promise1, promise2]).then(values => {
  140. let relatedZone = values[0].Content;
  141. let zoneData = values[1].Content;
  142. this.relatedSpaceIdList = [];
  143. relatedZone.map(item => {
  144. this.relatedSpaceIdList.push(item.RoomID);
  145. })
  146. // 所有业务空间
  147. this.businessSpaceList = zoneData;
  148. // 已关联元空间的业务空间
  149. this.BSPRelaISPList = [];
  150. zoneData.map(t => {
  151. if (t.Outline && t.Outline.length) {
  152. this.BSPRelaISPList.push(t)
  153. }
  154. })
  155. // 绘制业务空间
  156. let tempArr = this.BSPRelaISPList.map((t, i) => {
  157. if (t.FloorId == this.buildingData[1] && t.ObjectType == this.space) {
  158. return {
  159. RoomLocalName: t.RoomLocalName,
  160. OutLine: t.Outline,
  161. RoomID: t.RoomID,
  162. Color: colorArr[i % colorArr.length],
  163. HighLightFlag: relatedZone.findIndex((item) => (item.RoomID == t.RoomID)) > -1,
  164. Transparency: relatedZone.findIndex((item) => (item.RoomID == t.RoomID)) > -1 ? 20 : 1
  165. }
  166. } else {
  167. return undefined
  168. }
  169. }).filter(item => item)
  170. this.scene.removeAllZone();
  171. this.scene.addZoneList(tempArr);
  172. this.scene.click(this, this.canvasClick);
  173. this.canvasLoading = false;
  174. })
  175. },
  176. // canvas点击事件
  177. canvasClick(item, event) {
  178. if (!this.config.isEdit) {
  179. item.selected = false;
  180. }
  181. },
  182. //取消编辑
  183. cancelEdit() {
  184. this.config.isEdit = false;
  185. this.scene.clearZoneSelection();
  186. this.getBusinessSpace();
  187. },
  188. //编辑
  189. edit() {
  190. this.config.isEdit = true;
  191. this.scene.zoneList.map(t => {
  192. t.selected = t.highLightFlag;
  193. t.transparency = 20;
  194. t.highLightFlag = false;
  195. })
  196. },
  197. //保存编辑
  198. saveEdit() {
  199. let arr = this.scene.getSelectedZone();
  200. let param = {
  201. BuildingId: this.buildingData[0],
  202. FloorId: this.buildingData[1],
  203. Type: this.space,
  204. data: {
  205. ShaftId: this.$route.query.ShaftId,
  206. SpaceIdList: []
  207. }
  208. }
  209. param.data.SpaceIdList = arr.map(t => {
  210. return t.data.RoomID;
  211. })
  212. shaftZoneLink(param, res => {
  213. this.config.isEdit = false;
  214. this.$message.success("保存成功");
  215. this.getBusinessSpace();
  216. })
  217. },
  218. // 清除canvas
  219. clearGraphy() {
  220. // debugger
  221. this.scene = null;
  222. if (this.view) {
  223. this.view.scene = null;
  224. return
  225. }
  226. this.view = new FloorView('floorCanvas')
  227. },
  228. // 适配底图到窗口
  229. fit() {
  230. this.view.fitSceneToView()
  231. },
  232. // 缩放
  233. scale(val) {
  234. if (!this.view) {
  235. return;
  236. }
  237. let scale = this.view.scale;
  238. this.view.scaleByPoint(val / scale, this.canvasWidth / 2, this.canvasHeight / 2);
  239. },
  240. // 保存为png
  241. savePng() {
  242. this.view.saveImage(`${this.buildingData[1]}.png`, 'png');
  243. },
  244. // 保存为svg
  245. saveSvg() {
  246. this.view.saveSceneSvg(`${this.buildingData[1]}.svg`, 6400, 4800);
  247. },
  248. // 框选
  249. groupSelect() {
  250. this.scene.isRectSelection = 2;
  251. },
  252. // 保存json
  253. saveJson() {
  254. this.view.saveFloorJson(`${this.buildingData[1]}.json`)
  255. },
  256. },
  257. watch: {
  258. "view.scale": {
  259. handler(n) {
  260. if (this.$refs.canvasFun) {
  261. let s = n * 10 / this.view.minScale
  262. this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s;
  263. }
  264. }
  265. },
  266. "scene.isRectSelection": {
  267. handler(n) {
  268. if (!n) {
  269. this.$refs.canvasFun.active = '';
  270. }
  271. }
  272. },
  273. }
  274. }
  275. </script>
  276. <style lang="less" scoped>
  277. .canvas-actions-box {
  278. position: absolute;
  279. bottom: 20px;
  280. left: 50%;
  281. transform: translateX(-50%);
  282. z-index: 999;
  283. }
  284. .canvas-box {
  285. width: 100%;
  286. height: 100%;
  287. }
  288. </style>