graphy.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. <template>
  2. <div id="graphy" 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. <!-- 初始两个按钮 -->
  12. <el-row class="buttons-box">
  13. <div>
  14. <el-autocomplete popper-class="my-autocomplete" v-model="search" :fetch-suggestions="querySearch" placeholder="输入平面图中已有的业务空间名称进行查找"
  15. width="180px" @select="handleSelect">
  16. <i class="el-icon-search el-input__icon" slot="suffix" @click="handleSelect"></i>
  17. <template slot-scope="{ item }">
  18. <div class="name" style="position: relative;">
  19. {{ item.data.RoomLocalName | cutString(8) }}
  20. <span class="addr" style="position: absolute;right:10px;color:#409EFF;">定位</span>
  21. </div>
  22. </template>
  23. </el-autocomplete>
  24. </div>
  25. <div class="button-group">
  26. <!-- 默认操作模式 -->
  27. <div v-show="type==1">
  28. <el-dropdown split-button type="primary" @click="editGraphy" @command="handleCommand">
  29. 创建业务空间
  30. <el-dropdown-menu slot="dropdown">
  31. <el-dropdown-item command="groupCreateBSpace">批量创建业务空间</el-dropdown-item>
  32. </el-dropdown-menu>
  33. </el-dropdown>
  34. <!-- 点击已经关联的业务空间 -->
  35. <el-button type="primary" plain @click="refactorBSP" :disabled="zoneDisable" style="margin-left:10px;">重新划分业务空间</el-button>
  36. <el-button type="primary" @click="editeSpaceDetail" :disabled="zoneDisable">编辑空间详情</el-button>
  37. <el-button plain @click="cancelGraphy" v-show="!zoneDisable">取 消</el-button>
  38. </div>
  39. <!-- 点击已经关联的业务空间 -->
  40. <!-- <div v-show="type==2">
  41. </div> -->
  42. <!-- 点击未关联的业务空间 -->
  43. <div v-show="type==3">
  44. <el-button plain @click="createNewZone">创建单个全新的业务空间</el-button>
  45. <el-button plain @click="lookUnrelatBSpace(true)">从未关联平面图的业务空间中选择</el-button>
  46. <el-button plain @click="cancelGraphy">取 消</el-button>
  47. </div>
  48. <!-- 重新划分业务空间 -->
  49. <div v-show="type==4">
  50. <el-button plain @click="cancelGraphy">取 消</el-button>
  51. <el-button type="primary" @click="saveRefactorBSP">保存</el-button>
  52. </div>
  53. <!-- 批量创建所选业务空间 -->
  54. <div v-show="type==5">
  55. <el-button type="primary" @click="groupCreateZone">批量创建所选业务空间</el-button>
  56. <el-button plain @click="cancelGraphy">取 消</el-button>
  57. </div>
  58. </div>
  59. <div style="position: absolute;right: 0;">
  60. <el-button type="text" @click="lookUnrelatBSpace(false)">未关联平面图的业务空间 {{num}} 条</el-button>
  61. </div>
  62. </el-row>
  63. <!-- 底部操作按钮 -->
  64. <el-row class="canvas-actions-box">
  65. <canvasFun @fit="fit" @savePng="savePng" @saveSvg="saveSvg" @divide="divide" @clearDivide="clearDivide" @undo="undo" @redo="redo"
  66. @changeAbsorb="changeAbsorb" @scale="scale" @groupSelect="groupSelect" :config="config" ref="canvasFun" @saveJson="saveJson"></canvasFun>
  67. </el-row>
  68. </div>
  69. <!-- -->
  70. <!-- 未关联元空间的业务空间 -->
  71. <unRelateBSP ref="unRelateBSP" :isAction="isAction" @createFromUnrelated="createFromUnrelated" :code="tab.code"></unRelateBSP>
  72. <!-- 创建新的业务空间 -->
  73. <createBSP ref="createBSP" @createRoom="createRoom"></createBSP>
  74. <!-- 批量创建选择弹窗 -->
  75. <el-dialog title="提示" :visible.sync="groupCreateDialogVis" width="30%">
  76. <div id="autoRelate">
  77. <p>请选择批量创建方式:</p>
  78. <p>
  79. <el-radio v-model="groupCreateType" :label="1">批量将所有的空白空间创建业务空间</el-radio>
  80. </p>
  81. <p>
  82. <el-radio v-model="groupCreateType" :label="2">批量选择空白空间创建业务空间</el-radio>
  83. </p>
  84. </div>
  85. <span slot="footer" class="dialog-footer">
  86. <el-button size="small" @click="groupCreateDialogVis=false">取消</el-button>
  87. <el-button size="small" type="primary" @click="confirm">确认</el-button>
  88. </span>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script>
  93. import canvasFun from "./canvasFun"
  94. import { mapGetters, mapActions } from "vuex";
  95. import { SColor, SPoint } from "@saga-web/draw/lib";
  96. import { DivideFloorScene, SpaceItem, ZoneItem, FloorView } from "@saga-web/cad-engine/lib";
  97. import { colorArr } from "@/utils/spaceColor"
  98. import unRelateBSP from "./unRelateBSP";
  99. import createBSP from "./createBSP";
  100. import {
  101. buildingQuery,
  102. queryZone,
  103. updateZone,
  104. createZone,
  105. countZone,
  106. getIspNotInSpace,
  107. createRelateInZoneAndISp,
  108. groupCreRelaZoneAndISp
  109. } from "@/api/scan/request"
  110. // BSP => 业务空间
  111. export default {
  112. components: {
  113. canvasFun,
  114. unRelateBSP,
  115. createBSP
  116. },
  117. data() {
  118. return {
  119. canvasWidth: 800,
  120. canvasHeight: 600,
  121. type: 1, // 默认操作模式
  122. search: '',//搜索
  123. buildFloor: ['', ''],
  124. FloorObj: {}, //楼层对象
  125. FloorMap: '', //楼层底图
  126. tab: {},
  127. config: {
  128. isEdit: false,
  129. divide: true,
  130. groupSelect: true
  131. },
  132. canvasLoading: false,
  133. view: null,
  134. scene: null,
  135. Outline: [], // 当前选中的多个空间组成的轮廓线->三维数组
  136. businessSpaceList: [], // 所有业务空间
  137. num: 0, // 未关联元空间的业务空间统计
  138. BSPRelaISPList: [], // 已关联元空间的业务空间
  139. // 未关联元空间的业务空间弹窗
  140. isAction: false,
  141. curOutline: [],
  142. BIMIDToSID: {}, //bimid映射元空间id
  143. curZoneItem: {}, //当前选中的业务空间item
  144. allUnRelatISP: [], //
  145. zoneList: [], // 业务空间-canvas图中
  146. groupCreateDialogVis: false, //批量创建业务空间弹窗
  147. groupCreateType: 1, //批量创建方式
  148. zoneDisable: true, // 重新划分是否禁用
  149. }
  150. },
  151. computed: {
  152. ...mapGetters('layout', ['projectId'])
  153. },
  154. created() {
  155. },
  156. mounted() {
  157. this.canvasWidth = this.$refs.graphy.offsetWidth;
  158. this.canvasHeight = this.$refs.graphy.offsetHeight;
  159. },
  160. methods: {
  161. // 初始化
  162. init(initType) {
  163. this.type = 1;
  164. if (this.scene) {
  165. this.scene.clearSpaceSelection();
  166. this.scene.clearZoneSelection();
  167. this.scene.clearCut();
  168. this.scene.clearLikeSpaces();
  169. this.zoneDisable = true;
  170. this.scene.isZoneSelectable = true;
  171. this.scene.isSpaceSelectable = false;
  172. }
  173. if (this.buildFloor.indexOf('all') > -1 || this.buildFloor.indexOf('noKnow') > -1) {
  174. return;
  175. }
  176. if (initType == 1) {
  177. // 底图
  178. this.getGraphy();
  179. } else {
  180. // 业务空间
  181. this.getBusinessSpace();
  182. }
  183. this.config = {
  184. isEdit: false,
  185. divide: true,
  186. groupSelect: true
  187. }
  188. // 获取当前楼层的元空间
  189. this.getFloorISpace();
  190. // 查询未关联业务空间的元空间
  191. this.getISPSPUnrelaBSP();
  192. // 查询未关联平面图的业务空间
  193. this.getBSPunrelaISP();
  194. },
  195. // 获取当前楼层的元空间
  196. getFloorISpace() {
  197. let pa = {
  198. zone: 'Ispace',
  199. data: {
  200. Filters: `FloorId='${this.buildFloor[1]}'`,
  201. PageSize: 1000
  202. }
  203. }
  204. queryZone(pa, res => {
  205. this.BIMIDToSID = {}
  206. res.Content.map(t => {
  207. this.BIMIDToSID[t.BIMID.split(":")[1]] = t.RoomID;
  208. })
  209. })
  210. },
  211. // 搜索
  212. querySearch(queryString, cb) {
  213. let restaurants = this.zoneList;
  214. let results = queryString ?
  215. restaurants.filter(this.createFilter(queryString)) :
  216. restaurants;
  217. // 调用 callback 返回建议列表的数据
  218. cb(results);
  219. },
  220. // 过滤器
  221. createFilter(queryString) {
  222. return restaurant => {
  223. return restaurant.data.RoomLocalName.indexOf(queryString) > -1;
  224. };
  225. },
  226. // 查询选中,定位
  227. handleSelect(zone) {
  228. // 清空选中
  229. this.scene.clearSpaceSelection();
  230. this.scene.clearZoneSelection();
  231. // 选中当前
  232. zone.selected = true;
  233. this.curZoneItem = zone;
  234. this.zoneDisable = false;
  235. this.view.fitSelectedToView();
  236. },
  237. // 父组件调用
  238. getData(buildFloor, FloorObj, tab) {
  239. let initType = 1;
  240. if (FloorObj.FloorID == this.FloorObj.FloorID) {
  241. initType = 2;
  242. }
  243. this.buildFloor = buildFloor;
  244. this.FloorObj = FloorObj;
  245. this.FloorMap = FloorObj.StructureInfo ? FloorObj.StructureInfo.FloorMap : ''
  246. this.tab = tab;
  247. console.log(arguments)
  248. this.init(initType);
  249. },
  250. // 获取未绑定业务空间的元空间
  251. getISPSPUnrelaBSP() {
  252. let pa = {
  253. data: {
  254. Filters: `FloorId='${this.buildFloor[1]}'`,
  255. PageSize: 1000
  256. },
  257. objectType: this.tab.code
  258. }
  259. this.allUnRelatISP = []
  260. getIspNotInSpace(pa, res => {
  261. this.allUnRelatISP = res.Content;
  262. })
  263. },
  264. // 获取底图
  265. getGraphy() {
  266. let that = this;
  267. that.clearGraphy()
  268. that.scene = new DivideFloorScene();
  269. that.canvasLoading = true;
  270. that.scene.loadUrl(`/image-service/common/file_get?systemId=revit&key=${this.FloorMap}`).then(res => {
  271. that.canvasLoading = false;
  272. if (res == 'error') {
  273. this.FloorMap = '';
  274. this.$message.warning('数据解析异常');
  275. return;
  276. }
  277. that.view.scene = that.scene;
  278. // 蒙版
  279. if (this.FloorObj.Outline) {
  280. let newArr = this.FloorObj.Outline.map(t => {
  281. return new SPoint(t.X, t.Y);
  282. })
  283. this.scene.addSceneMark(newArr)
  284. }
  285. this.scene.isSpaceSelectable = false;
  286. // 绘制业务空间
  287. that.getBusinessSpace();
  288. that.view.fitSceneToView();
  289. that.view.maxScale = that.view.scale * 10;
  290. that.view.minScale = that.view.scale;
  291. if (that.$refs.canvasFun) {
  292. that.$refs.canvasFun.everyScale = that.view.scale;
  293. }
  294. })
  295. },
  296. // 获取当前分区下的业务空间
  297. getBusinessSpace() {
  298. this.canvasLoading = true
  299. let pa = {
  300. zone: this.tab.code,
  301. data: {
  302. Filters: ``,
  303. Orders: "createTime desc, RoomID asc",
  304. PageSize: 1000
  305. }
  306. }
  307. if (this.buildFloor.length && this.buildFloor.length > 1) {
  308. pa.data.Filters = `BuildingId='${this.buildFloor[0]}';FloorId='${this.buildFloor[1]}'`
  309. }
  310. queryZone(pa, res => {
  311. // 所有业务空间
  312. this.businessSpaceList = res.Content;
  313. // 已关联元空间的业务空间
  314. this.BSPRelaISPList = [];
  315. res.Content.map(t => {
  316. if (t.Outline && t.Outline.length) {
  317. this.BSPRelaISPList.push(t)
  318. }
  319. })
  320. // 绘制业务空间
  321. let tempArr = this.BSPRelaISPList.map((t, i) => {
  322. if(t.FloorId == this.buildFloor[1]&&t.ObjectType == this.tab.code){
  323. return {
  324. RoomLocalName: t.RoomLocalName,
  325. OutLine: t.Outline,
  326. RoomID: t.RoomID,
  327. Color: colorArr[i % colorArr.length],
  328. }
  329. } else {
  330. console.log('internet slow')
  331. return undefined;
  332. }
  333. }).filter(item => item)
  334. this.scene.removeAllZone();
  335. this.scene.addZoneList(tempArr);
  336. this.scene.click(this, this.canvasClick);
  337. this.zoneList = this.scene.zoneList;
  338. this.canvasLoading = false;
  339. })
  340. },
  341. // canvas点击事件
  342. canvasClick(item, event) {
  343. console.log(item)
  344. console.log(event)
  345. if (this.type == 4) {//重新划分
  346. } else if (this.type == 5) {//批量
  347. } else {
  348. if (item instanceof SpaceItem && item.selectable) {
  349. if (this.type == 2) {
  350. this.scene.clearZoneSelection();
  351. }
  352. this.type = 3;
  353. this.curZoneItem = {};
  354. }
  355. if (item instanceof ZoneItem && item.selectable) {
  356. if (this.type == 3) {
  357. this.scene.clearSpaceSelection();
  358. }
  359. this.zoneDisable = false;
  360. this.curZoneItem = item;
  361. this.scene.clearZoneSelection();
  362. item.selected = true;
  363. }
  364. }
  365. },
  366. // 编辑平面图
  367. editGraphy() {
  368. this.type = 3;
  369. this.config.isEdit = true;
  370. this.config.groupSelect = false;
  371. this.config.divide = true;
  372. this.scene.isSpaceSelectable = true;
  373. // 设置业务空间不可选
  374. this.scene.isZoneSelectable = false
  375. },
  376. // 查看未关联的业务空间--flag--查看-or-选择
  377. lookUnrelatBSpace(flag) {
  378. this.isAction = flag;
  379. let arr = this.scene.getSelectedSpaces();
  380. if (flag && !arr.length) {
  381. this.$message.warning('请至少选择一个空间');
  382. return;
  383. }
  384. this.$refs.unRelateBSP.showDialog();
  385. },
  386. // 取消(所有取消公用)
  387. cancelGraphy() {
  388. this.init(2);
  389. },
  390. // 批量创建业务空间弹窗
  391. handleCommand(command) {
  392. this.groupCreateDialogVis = true;
  393. },
  394. // 创建弹窗确认
  395. confirm() {
  396. if (this.groupCreateType == 1) {
  397. this.groupCreateBSpace()
  398. } else if (this.groupCreateType == 2) {
  399. this.type = 5;
  400. this.config.isEdit = true;
  401. this.config.groupSelect = true;
  402. this.config.divide = false;
  403. this.groupCreateDialogVis = false;
  404. // 清空选中空间
  405. this.scene.clearSpaceSelection();
  406. // 设置空间可选
  407. this.scene.isSpaceSelectable = true;
  408. // 设置业务空间不可选
  409. this.scene.isZoneSelectable = false;
  410. }
  411. },
  412. // 批量创建业务空间
  413. groupCreateBSpace() {
  414. let text = []
  415. let Spaces = this.allUnRelatISP.map(t => {
  416. if (t.Outline) {
  417. text.push(t.RoomLocalName || t.RoomName)
  418. return {
  419. IspaceId: t.RoomID,
  420. RoomLocalName: t.RoomLocalName || t.RoomName,
  421. Outline: [t.Outline],
  422. BuildingId: this.buildFloor[0],
  423. FloorId: this.buildFloor[1],
  424. Height: t.Height || 0
  425. }
  426. } else {
  427. return undefined
  428. }
  429. }).filter(item => item);
  430. if (Spaces.length) {
  431. this.$confirm(
  432. "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
  433. "<p>涉及的空间:</p>" +
  434. "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
  435. text.toString() +
  436. "</p>",
  437. "提示", {
  438. dangerouslyUseHTMLString: true,
  439. confirmButtonText: "确定",
  440. cancelButtonText: "取消",
  441. type: "warning"
  442. }
  443. ).then(() => {
  444. this.groupCreateDialogVis = false;
  445. this.canvasLoading = true;
  446. this.groupCreateBSP(Spaces)
  447. }).catch(() => {
  448. this.$message({
  449. type: "info",
  450. message: "已取消批量创建"
  451. });
  452. });
  453. } else {
  454. this.$message('没有未关联的空间')
  455. }
  456. },
  457. // 创建新的业务空间
  458. createNewZone() {
  459. let arr = this.scene.getSelectedSpaces();
  460. if (arr.length) {
  461. let tempArr = [];
  462. arr.map(t => {
  463. tempArr.push(t.data.Name);
  464. })
  465. this.$refs.createBSP.showDialog(tempArr.toString());
  466. } else {
  467. this.$message.warning('请至少选择一个空间');
  468. }
  469. },
  470. // 创建新的业务空间-弹窗返回确认创建
  471. createRoom(val) {
  472. let zoneObj = { Outline: [], Height: 0 }, IspaceIdList = [];
  473. let selectSpaces = this.scene.getSelectedSpaces();
  474. selectSpaces.map(t => {
  475. zoneObj.Outline.push(t.data.OutLine);
  476. if (this.BIMIDToSID[t.data.SourceId]) {
  477. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  478. }
  479. if (t.data.Height && (zoneObj.Height == 0 || t.data.Height < zoneObj.Height)) {
  480. zoneObj.Height = t.data.Height;
  481. }
  482. })
  483. // 如果有划分,求交集
  484. if (this.scene.cutItem || this.scene.sceneMark) {
  485. zoneObj.Outline = [];
  486. let arr = this.scene.getIntersect();
  487. arr.map(t => {
  488. let temp = t.map(item => {
  489. return {
  490. X: item.x,
  491. Y: -item.y,
  492. Z: 0
  493. }
  494. })
  495. zoneObj.Outline.push([temp]);
  496. })
  497. }
  498. if (!zoneObj.Outline.length) {
  499. zoneObj.Outline = null;
  500. }
  501. zoneObj.RoomLocalName = val;
  502. zoneObj.BuildingId = this.buildFloor[0];
  503. zoneObj.FloorId = this.buildFloor[1];
  504. this.createSingleBSP(zoneObj, IspaceIdList)
  505. },
  506. // 从未关联平面图的业务空间中选择--按钮返回关联信号
  507. createFromUnrelated(BSP) {
  508. BSP.Outline = [];
  509. BSP.Height = 0;
  510. let arr = this.scene.getSelectedSpaces(), IspaceIdList = [];
  511. arr.map(t => {
  512. BSP.Outline.push(t.data.OutLine);
  513. if (this.BIMIDToSID[t.data.SourceId]) {
  514. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  515. }
  516. if (t.Height && (BSP.Height == 0 || t.Height < BSP.Height)) {
  517. BSP.Height = t.Height;
  518. }
  519. })
  520. this.updateBSPOutline(BSP, IspaceIdList)
  521. },
  522. // 编辑空间详情
  523. editeSpaceDetail() {
  524. let item = this.curZoneItem.data;
  525. let query = {
  526. RoomID: item.RoomID,
  527. zone: this.tab.code,
  528. isMyTab: 1,
  529. buildFloorSelectd: this.buildFloor
  530. }
  531. this.$router.push({
  532. path: "/ledger/spaceDetail",
  533. query: query
  534. })
  535. },
  536. // 重新划分业务空间
  537. refactorBSP() {
  538. this.config.isEdit = true;
  539. this.config.groupSelect = false;
  540. this.config.divide = true;
  541. this.type = 4;
  542. // 设置空间可选
  543. this.scene.isSpaceSelectable = true;
  544. // 将已关联的设置不可选,并将当前选的隐藏
  545. this.scene.isZoneSelectable = false;
  546. this.curZoneItem.visible = false;
  547. // 将当前业务空间的每个元素添加到场景中并选中
  548. this.scene.addAllLikeSpace(this.curZoneItem.data.OutLine);
  549. },
  550. // 重新划分--保存
  551. saveRefactorBSP() {
  552. let selectSpace = this.scene.getSelectedSpaces();
  553. let selectLikeSpace = this.scene.getSelectedLikeSpace();
  554. //更新业务空间
  555. let zoneObj = { Outline: [], Height: 0 }, IspaceIdList = [];
  556. // 空间
  557. selectSpace.map(t => {
  558. zoneObj.Outline.push(t.data.OutLine);
  559. if (this.BIMIDToSID[t.data.SourceId]) {
  560. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  561. }
  562. if (t.Height && (zoneObj.Height == 0 || t.Height < zoneObj.Height)) {
  563. zoneObj.Height = t.Height;
  564. }
  565. })
  566. // 类空间
  567. selectLikeSpace.map(t => {
  568. zoneObj.Outline.push(t.data);
  569. })
  570. // 如果有划分,求交集
  571. if (this.scene.cutItem || this.scene.sceneMark) {
  572. zoneObj.Outline = [];
  573. let spaceIntersect = this.scene.getIntersect();
  574. spaceIntersect.map(t => {
  575. let temp = t.map(item => {
  576. return {
  577. X: item.x,
  578. Y: -item.y,
  579. Z: 0
  580. }
  581. })
  582. zoneObj.Outline.push([temp]);
  583. })
  584. let likeSpaceIntersect = this.scene.getLikeIntersect();
  585. likeSpaceIntersect.map(t => {
  586. let temp = t.map(item => {
  587. return {
  588. X: item.x,
  589. Y: -item.y,
  590. Z: 0
  591. }
  592. })
  593. zoneObj.Outline.push([temp]);
  594. })
  595. }
  596. if (!zoneObj.Outline.length) {
  597. zoneObj.Outline = null;
  598. }
  599. zoneObj.RoomID = this.curZoneItem.data.RoomID;
  600. this.updateBSPOutline(zoneObj, IspaceIdList)
  601. },
  602. // 批量创建所选业务空间
  603. groupCreateZone() {
  604. let arr = this.scene.getSelectedSpaces();
  605. let spaces = arr.map(t => {
  606. return {
  607. IspaceId: this.BIMIDToSID[t.data.SourceId],
  608. RoomLocalName: t.data.Name,
  609. Outline: [t.data.OutLine],
  610. BuildingId: this.buildFloor[0],
  611. FloorId: this.buildFloor[1],
  612. Height: t.data.Height || 0
  613. }
  614. })
  615. if (spaces.length) {
  616. this.canvasLoading = true;
  617. this.groupCreateBSP(spaces)
  618. } else {
  619. this.$message.warning('未选择空间');
  620. }
  621. },
  622. // 更新业务空间和元空间的关系
  623. relationInBSPandISP(SpaceId, IspaceIdList) {
  624. let pa = {
  625. data: { SpaceId: SpaceId, IspaceIdList: IspaceIdList },
  626. type: this.tab.code
  627. }
  628. createRelateInZoneAndISp(pa, res => {
  629. this.$message.success('创建成功');
  630. this.init(2);
  631. })
  632. },
  633. // 批量更新业务空间和元空间的关系
  634. groupCreRelaZoneAndISp(Spaces) {
  635. Spaces = Spaces.filter(item => item.IspaceId);
  636. if (Spaces.length) {
  637. let param = {
  638. data: {
  639. Content: Spaces
  640. },
  641. type: this.tab.code
  642. }
  643. groupCreRelaZoneAndISp(param, res => {
  644. this.$message.success('创建成功')
  645. this.canvasLoading = false;
  646. this.init(2)
  647. })
  648. } else {
  649. this.$message.success('创建成功')
  650. this.canvasLoading = false;
  651. this.init(2)
  652. }
  653. },
  654. // 批量创建
  655. groupCreateBSP(spaces) {
  656. spaces = spaces.map(t => {
  657. t.BIMLocation = this.getAverageVal(t.Outline);
  658. return t;
  659. })
  660. let pa = {
  661. zone: this.tab.code,
  662. data: {
  663. Content: spaces
  664. }
  665. }
  666. createZone(pa, res => {
  667. res.EntityList.map(t => {
  668. spaces = spaces.map(item => {
  669. if (t.RoomLocalName == item.RoomLocalName) {
  670. item.SpaceId = t.RoomID
  671. }
  672. return item;
  673. })
  674. })
  675. this.groupCreRelaZoneAndISp(spaces)
  676. })
  677. },
  678. // 单个创建
  679. createSingleBSP(space, IspaceIdList) {
  680. space.BIMLocation = space.Outline ? this.getAverageVal(space.Outline) : null;
  681. let pa = {
  682. zone: this.tab.code,
  683. data: {
  684. Content: [space]
  685. }
  686. }
  687. createZone(pa, res => {
  688. this.relationInBSPandISP(res.EntityList[0].RoomID, IspaceIdList)
  689. })
  690. },
  691. // 更新业务空间区域
  692. updateBSPOutline(zoneObj, IspaceIdList) {
  693. zoneObj.BIMLocation = zoneObj.Outline ? this.getAverageVal(zoneObj.Outline) : null;
  694. let pa = {
  695. zone: this.tab.code,
  696. data: {
  697. Content: [zoneObj],
  698. Projection: ['Outline', 'BIMLocation']
  699. },
  700. }
  701. updateZone(pa, res => {
  702. this.relationInBSPandISP(zoneObj.RoomID, IspaceIdList)
  703. })
  704. },
  705. // 查询未关联平面图的业务空间(项目下+当前分区)
  706. getBSPunrelaISP() {
  707. let pa = {
  708. zone: this.tab.code,
  709. data: {
  710. Filters: `Outline isNull`
  711. }
  712. }
  713. countZone(pa, res => {
  714. this.num = res.Count;
  715. })
  716. },
  717. // 计算平均值 作为业务空间BIMLocation
  718. getAverageVal(Outline) {
  719. let X = 0, Y = 0, Z = 0, len = 0;
  720. Outline.map(t => {
  721. if (t[0]) {
  722. t[0].map(item => {
  723. X += item.X;
  724. Y += item.Y;
  725. Z += item.Z;
  726. })
  727. len += t[0].length
  728. }
  729. })
  730. X = (X / len).toFixed(2);
  731. Y = (Y / len).toFixed(2);
  732. Z = (Z / len).toFixed(2);
  733. return `${X},${Y},${Z}`
  734. },
  735. // canvas 获取焦点
  736. focus() {
  737. document.getElementById(`floorCanvas`).focus()
  738. },
  739. // 清除canvas
  740. clearGraphy() {
  741. if (this.view) {
  742. this.view.scene = null;
  743. return
  744. }
  745. this.view = new FloorView('floorCanvas')
  746. },
  747. // 工具栏操作
  748. // 吸附
  749. changeAbsorb(isAbsorbing) {
  750. this.scene.isAbsorbing = isAbsorbing;
  751. },
  752. // 框选
  753. groupSelect() {
  754. this.scene.isRectSelection = true;
  755. },
  756. // 适配底图到窗口
  757. fit() {
  758. this.view.fitSceneToView()
  759. },
  760. // 保存为png
  761. savePng() {
  762. this.view.saveImage(`${this.buildFloor[1]}.png`, 'png');
  763. },
  764. // 保存为svg
  765. saveSvg() {
  766. this.view.saveSceneSvg(`${this.buildFloor[1]}.svg`, 6400, 4800);
  767. },
  768. // 保存json
  769. saveJson() {
  770. this.view.saveFloorJson(`${this.buildFloor[1]}.json`)
  771. },
  772. // 切割划分
  773. divide() {
  774. this.scene.isCutting = true;
  775. },
  776. // 清除切割划分
  777. clearDivide() {
  778. this.scene.clearCut();
  779. },
  780. // 撤销
  781. undo() {
  782. },
  783. // 反撤销
  784. redo() { },
  785. // 缩放
  786. scale(val) {
  787. if (!this.view) {
  788. return;
  789. }
  790. let scale = this.view.scale;
  791. this.view.scaleByPoint(val / scale, this.canvasWidth / 2, this.canvasHeight / 2);
  792. },
  793. },
  794. filters: {
  795. cutString: function (str, len) {
  796. //length属性读出来的汉字长度为1
  797. if (!!str && typeof str == "string" && str.length > len) {
  798. return str.substring(0, len) + "...";
  799. } else {
  800. return str || "--";
  801. }
  802. }
  803. },
  804. watch: {
  805. projectId() {
  806. this.FloorMap = '';
  807. this.tab = {};
  808. },
  809. "view.scale": {
  810. handler(n) {
  811. if (this.$refs.canvasFun) {
  812. this.$refs.canvasFun.sliderVal = n * 10 / this.view.minScale;
  813. }
  814. }
  815. },
  816. "scene.isRectSelection": {
  817. handler(n) {
  818. if (!n) {
  819. this.$refs.canvasFun.active = '';
  820. }
  821. }
  822. },
  823. "scene.isCutting": {
  824. handler(n) {
  825. if (!n) {
  826. this.$refs.canvasFun.active = '';
  827. this.$refs.canvasFun.isSwitch = false;
  828. this.scene.isAbsorbing = false;
  829. }
  830. }
  831. },
  832. }
  833. }
  834. </script>
  835. <style lang="less" scoped>
  836. #graphy {
  837. position: relative;
  838. width: 100%;
  839. height: calc(100% - 56px);
  840. .canvas-box {
  841. width: 100%;
  842. height: 100%;
  843. }
  844. .buttons-box {
  845. position: absolute;
  846. top: 0;
  847. width: 100%;
  848. z-index: 999;
  849. & > div {
  850. float: left;
  851. }
  852. /deep/ .el-autocomplete {
  853. display: block;
  854. width: 320px;
  855. margin-right: 10px;
  856. }
  857. .button-group button,
  858. .button-group .el-dropdown {
  859. display: block;
  860. float: left;
  861. }
  862. .my-autocomplete {
  863. li {
  864. line-height: normal;
  865. padding: 7px;
  866. .name {
  867. text-overflow: ellipsis;
  868. overflow: hidden;
  869. }
  870. .addr {
  871. font-size: 12px;
  872. color: #b4b4b4;
  873. }
  874. .highlighted .addr {
  875. color: #ddd;
  876. }
  877. }
  878. }
  879. }
  880. .canvas-actions-box {
  881. position: absolute;
  882. bottom: 20px;
  883. left: 50%;
  884. transform: translateX(-50%);
  885. z-index: 999;
  886. }
  887. }
  888. </style>