graphy.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  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. return {
  323. RoomLocalName: t.RoomLocalName,
  324. OutLine: t.Outline,
  325. RoomID: t.RoomID,
  326. Color: colorArr[i % colorArr.length],
  327. }
  328. })
  329. this.scene.removeAllZone();
  330. this.scene.addZoneList(tempArr);
  331. this.scene.click(this, this.canvasClick);
  332. this.zoneList = this.scene.zoneList;
  333. this.canvasLoading = false;
  334. })
  335. },
  336. // canvas点击事件
  337. canvasClick(item, event) {
  338. console.log(item)
  339. console.log(event)
  340. if (this.type == 4) {//重新划分
  341. } else if (this.type == 5) {//批量
  342. } else {
  343. if (item instanceof SpaceItem && item.selectable) {
  344. if (this.type == 2) {
  345. this.scene.clearZoneSelection();
  346. }
  347. this.type = 3;
  348. this.curZoneItem = {};
  349. }
  350. if (item instanceof ZoneItem && item.selectable) {
  351. if (this.type == 3) {
  352. this.scene.clearSpaceSelection();
  353. }
  354. this.zoneDisable = false;
  355. this.curZoneItem = item;
  356. this.scene.clearZoneSelection();
  357. item.selected = true;
  358. }
  359. }
  360. },
  361. // 编辑平面图
  362. editGraphy() {
  363. this.type = 3;
  364. this.config.isEdit = true;
  365. this.config.groupSelect = false;
  366. this.config.divide = true;
  367. this.scene.isSpaceSelectable = true;
  368. // 设置业务空间不可选
  369. this.scene.isZoneSelectable = false
  370. },
  371. // 查看未关联的业务空间--flag--查看-or-选择
  372. lookUnrelatBSpace(flag) {
  373. this.isAction = flag;
  374. let arr = this.scene.getSelectedSpaces();
  375. if (flag && !arr.length) {
  376. this.$message.warning('请至少选择一个空间');
  377. return;
  378. }
  379. this.$refs.unRelateBSP.showDialog();
  380. },
  381. // 取消(所有取消公用)
  382. cancelGraphy() {
  383. this.init(2);
  384. },
  385. // 批量创建业务空间弹窗
  386. handleCommand(command) {
  387. this.groupCreateDialogVis = true;
  388. },
  389. // 创建弹窗确认
  390. confirm() {
  391. if (this.groupCreateType == 1) {
  392. this.groupCreateBSpace()
  393. } else if (this.groupCreateType == 2) {
  394. this.type = 5;
  395. this.config.isEdit = true;
  396. this.config.groupSelect = true;
  397. this.config.divide = false;
  398. this.groupCreateDialogVis = false;
  399. // 清空选中空间
  400. this.scene.clearSpaceSelection();
  401. // 设置空间可选
  402. this.scene.isSpaceSelectable = true;
  403. // 设置业务空间不可选
  404. this.scene.isZoneSelectable = false;
  405. }
  406. },
  407. // 批量创建业务空间
  408. groupCreateBSpace() {
  409. let text = []
  410. let Spaces = this.allUnRelatISP.map(t => {
  411. if (t.Outline) {
  412. text.push(t.RoomLocalName || t.RoomName)
  413. return {
  414. IspaceId: t.RoomID,
  415. RoomLocalName: t.RoomLocalName || t.RoomName,
  416. Outline: [t.Outline],
  417. BuildingId: this.buildFloor[0],
  418. FloorId: this.buildFloor[1],
  419. Height: t.Height || 0
  420. }
  421. } else {
  422. return undefined
  423. }
  424. }).filter(item => item);
  425. if (Spaces.length) {
  426. this.$confirm(
  427. "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
  428. "<p>涉及的空间:</p>" +
  429. "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
  430. text.toString() +
  431. "</p>",
  432. "提示", {
  433. dangerouslyUseHTMLString: true,
  434. confirmButtonText: "确定",
  435. cancelButtonText: "取消",
  436. type: "warning"
  437. }
  438. ).then(() => {
  439. this.groupCreateDialogVis = false;
  440. this.canvasLoading = true;
  441. this.groupCreateBSP(Spaces)
  442. }).catch(() => {
  443. this.$message({
  444. type: "info",
  445. message: "已取消批量创建"
  446. });
  447. });
  448. } else {
  449. this.$message('没有未关联的元空间')
  450. }
  451. },
  452. // 创建新的业务空间
  453. createNewZone() {
  454. let arr = this.scene.getSelectedSpaces();
  455. if (arr.length) {
  456. let tempArr = [];
  457. arr.map(t => {
  458. tempArr.push(t.data.Name);
  459. })
  460. this.$refs.createBSP.showDialog(tempArr.toString());
  461. } else {
  462. this.$message.warning('请至少选择一个空间');
  463. }
  464. },
  465. // 创建新的业务空间-弹窗返回确认创建
  466. createRoom(val) {
  467. let zoneObj = { Outline: [], Height: 0 }, IspaceIdList = [];
  468. let selectSpaces = this.scene.getSelectedSpaces();
  469. selectSpaces.map(t => {
  470. zoneObj.Outline.push(t.data.OutLine);
  471. if (this.BIMIDToSID[t.data.SourceId]) {
  472. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  473. }
  474. if (t.data.Height && (zoneObj.Height == 0 || t.data.Height < zoneObj.Height)) {
  475. zoneObj.Height = t.data.Height;
  476. }
  477. })
  478. // 如果有划分,求交集
  479. if (this.scene.cutItem || this.scene.sceneMark) {
  480. zoneObj.Outline = [];
  481. let arr = this.scene.getIntersect();
  482. arr.map(t => {
  483. let temp = t.map(item => {
  484. return {
  485. X: item.x,
  486. Y: -item.y,
  487. Z: 0
  488. }
  489. })
  490. zoneObj.Outline.push([temp]);
  491. })
  492. }
  493. if (!zoneObj.Outline.length) {
  494. zoneObj.Outline = null;
  495. }
  496. zoneObj.RoomLocalName = val;
  497. zoneObj.BuildingId = this.buildFloor[0];
  498. zoneObj.FloorId = this.buildFloor[1];
  499. this.createSingleBSP(zoneObj, IspaceIdList)
  500. },
  501. // 从未关联平面图的业务空间中选择--按钮返回关联信号
  502. createFromUnrelated(BSP) {
  503. BSP.Outline = [];
  504. BSP.Height = 0;
  505. let arr = this.scene.getSelectedSpaces(), IspaceIdList = [];
  506. arr.map(t => {
  507. BSP.Outline.push(t.data.OutLine);
  508. if (this.BIMIDToSID[t.data.SourceId]) {
  509. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  510. }
  511. if (t.Height && (BSP.Height == 0 || t.Height < BSP.Height)) {
  512. BSP.Height = t.Height;
  513. }
  514. })
  515. this.updateBSPOutline(BSP, IspaceIdList)
  516. },
  517. // 编辑空间详情
  518. editeSpaceDetail() {
  519. let item = this.curZoneItem.data;
  520. let query = {
  521. RoomID: item.RoomID,
  522. zone: this.tab.code,
  523. isMyTab: 1,
  524. buildFloorSelectd: this.buildFloor
  525. }
  526. this.$router.push({
  527. path: "/ledger/spaceDetail",
  528. query: query
  529. })
  530. },
  531. // 重新划分业务空间
  532. refactorBSP() {
  533. this.config.isEdit = true;
  534. this.config.groupSelect = false;
  535. this.config.divide = true;
  536. this.type = 4;
  537. // 设置空间可选
  538. this.scene.isSpaceSelectable = true;
  539. // 将已关联的设置不可选,并将当前选的隐藏
  540. this.scene.isZoneSelectable = false;
  541. this.curZoneItem.visible = false;
  542. // 将当前业务空间的每个元素添加到场景中并选中
  543. this.scene.addAllLikeSpace(this.curZoneItem.data.OutLine);
  544. },
  545. // 重新划分--保存
  546. saveRefactorBSP() {
  547. let selectSpace = this.scene.getSelectedSpaces();
  548. let selectLikeSpace = this.scene.getSelectedLikeSpace();
  549. //更新业务空间
  550. let zoneObj = { Outline: [], Height: 0 }, IspaceIdList = [];
  551. // 空间
  552. selectSpace.map(t => {
  553. zoneObj.Outline.push(t.data.OutLine);
  554. if (this.BIMIDToSID[t.data.SourceId]) {
  555. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  556. }
  557. if (t.Height && (zoneObj.Height == 0 || t.Height < zoneObj.Height)) {
  558. zoneObj.Height = t.Height;
  559. }
  560. })
  561. // 类空间
  562. selectLikeSpace.map(t => {
  563. zoneObj.Outline.push(t.data);
  564. })
  565. // 如果有划分,求交集
  566. if (this.scene.cutItem || this.scene.sceneMark) {
  567. zoneObj.Outline = [];
  568. let spaceIntersect = this.scene.getIntersect();
  569. spaceIntersect.map(t => {
  570. let temp = t.map(item => {
  571. return {
  572. X: item.x,
  573. Y: -item.y,
  574. Z: 0
  575. }
  576. })
  577. zoneObj.Outline.push([temp]);
  578. })
  579. let likeSpaceIntersect = this.scene.getLikeIntersect();
  580. likeSpaceIntersect.map(t => {
  581. let temp = t.map(item => {
  582. return {
  583. X: item.x,
  584. Y: -item.y,
  585. Z: 0
  586. }
  587. })
  588. zoneObj.Outline.push([temp]);
  589. })
  590. }
  591. if (!zoneObj.Outline.length) {
  592. zoneObj.Outline = null;
  593. }
  594. zoneObj.RoomID = this.curZoneItem.data.RoomID;
  595. this.updateBSPOutline(zoneObj, IspaceIdList)
  596. },
  597. // 批量创建所选业务空间
  598. groupCreateZone() {
  599. let arr = this.scene.getSelectedSpaces();
  600. let spaces = arr.map(t => {
  601. return {
  602. IspaceId: this.BIMIDToSID[t.data.SourceId],
  603. RoomLocalName: t.data.Name,
  604. Outline: [t.data.OutLine],
  605. BuildingId: this.buildFloor[0],
  606. FloorId: this.buildFloor[1],
  607. Height: t.data.Height || 0
  608. }
  609. })
  610. if (spaces.length) {
  611. this.canvasLoading = true;
  612. this.groupCreateBSP(spaces)
  613. } else {
  614. this.$message.warning('未选择空间');
  615. }
  616. },
  617. // 更新业务空间和元空间的关系
  618. relationInBSPandISP(SpaceId, IspaceIdList) {
  619. let pa = {
  620. data: { SpaceId: SpaceId, IspaceIdList: IspaceIdList },
  621. type: this.tab.code
  622. }
  623. createRelateInZoneAndISp(pa, res => {
  624. this.$message.success('创建成功');
  625. this.init(2);
  626. })
  627. },
  628. // 批量更新业务空间和元空间的关系
  629. groupCreRelaZoneAndISp(Spaces) {
  630. Spaces = Spaces.filter(item => item.IspaceId);
  631. if (Spaces.length) {
  632. let param = {
  633. data: {
  634. Content: Spaces
  635. },
  636. type: this.tab.code
  637. }
  638. groupCreRelaZoneAndISp(param, res => {
  639. this.$message.success('创建成功')
  640. this.canvasLoading = false;
  641. this.init(2)
  642. })
  643. } else {
  644. this.$message.success('创建成功')
  645. this.canvasLoading = false;
  646. this.init(2)
  647. }
  648. },
  649. // 批量创建
  650. groupCreateBSP(spaces) {
  651. spaces = spaces.map(t => {
  652. t.BIMLocation = this.getAverageVal(t.Outline);
  653. return t;
  654. })
  655. let pa = {
  656. zone: this.tab.code,
  657. data: {
  658. Content: spaces
  659. }
  660. }
  661. createZone(pa, res => {
  662. res.EntityList.map(t => {
  663. spaces = spaces.map(item => {
  664. if (t.RoomLocalName == item.RoomLocalName) {
  665. item.SpaceId = t.RoomID
  666. }
  667. return item;
  668. })
  669. })
  670. this.groupCreRelaZoneAndISp(spaces)
  671. })
  672. },
  673. // 单个创建
  674. createSingleBSP(space, IspaceIdList) {
  675. space.BIMLocation = space.Outline ? this.getAverageVal(space.Outline) : null;
  676. let pa = {
  677. zone: this.tab.code,
  678. data: {
  679. Content: [space]
  680. }
  681. }
  682. createZone(pa, res => {
  683. this.relationInBSPandISP(res.EntityList[0].RoomID, IspaceIdList)
  684. })
  685. },
  686. // 更新业务空间区域
  687. updateBSPOutline(zoneObj, IspaceIdList) {
  688. zoneObj.BIMLocation = zoneObj.Outline ? this.getAverageVal(zoneObj.Outline) : null;
  689. let pa = {
  690. zone: this.tab.code,
  691. data: {
  692. Content: [zoneObj],
  693. Projection: ['Outline', 'BIMLocation']
  694. },
  695. }
  696. updateZone(pa, res => {
  697. this.relationInBSPandISP(zoneObj.RoomID, IspaceIdList)
  698. })
  699. },
  700. // 查询未关联平面图的业务空间(项目下+当前分区)
  701. getBSPunrelaISP() {
  702. let pa = {
  703. zone: this.tab.code,
  704. data: {
  705. Filters: `Outline isNull`
  706. }
  707. }
  708. countZone(pa, res => {
  709. this.num = res.Count;
  710. })
  711. },
  712. // 计算平均值 作为业务空间BIMLocation
  713. getAverageVal(Outline) {
  714. let X = 0, Y = 0, Z = 0, len = 0;
  715. Outline.map(t => {
  716. if (t[0]) {
  717. t[0].map(item => {
  718. X += item.X;
  719. Y += item.Y;
  720. Z += item.Z;
  721. })
  722. len += t[0].length
  723. }
  724. })
  725. X = (X / len).toFixed(2);
  726. Y = (Y / len).toFixed(2);
  727. Z = (Z / len).toFixed(2);
  728. return `${X},${Y},${Z}`
  729. },
  730. // canvas 获取焦点
  731. focus() {
  732. document.getElementById(`floorCanvas`).focus()
  733. },
  734. // 清除canvas
  735. clearGraphy() {
  736. if (this.view) {
  737. this.view.scene = null;
  738. return
  739. }
  740. this.view = new FloorView('floorCanvas')
  741. },
  742. // 工具栏操作
  743. // 吸附
  744. changeAbsorb(isAbsorbing) {
  745. this.scene.isAbsorbing = isAbsorbing;
  746. },
  747. // 框选
  748. groupSelect() {
  749. this.scene.isRectSelection = true;
  750. },
  751. // 适配底图到窗口
  752. fit() {
  753. this.view.fitSceneToView()
  754. },
  755. // 保存为png
  756. savePng() {
  757. this.view.saveImage(`${this.buildFloor[1]}.png`, 'png');
  758. },
  759. // 保存为svg
  760. saveSvg() {
  761. this.view.saveSceneSvg(`${this.buildFloor[1]}.svg`, 6400, 4800);
  762. },
  763. // 保存json
  764. saveJson() {
  765. this.view.saveFloorJson(`${this.buildFloor[1]}.json`)
  766. },
  767. // 切割划分
  768. divide() {
  769. this.scene.isCutting = true;
  770. },
  771. // 清除切割划分
  772. clearDivide() {
  773. this.scene.clearCut();
  774. },
  775. // 撤销
  776. undo() {
  777. },
  778. // 反撤销
  779. redo() { },
  780. // 缩放
  781. scale(val) {
  782. if (!this.view) {
  783. return;
  784. }
  785. let scale = this.view.scale;
  786. this.view.scaleByPoint(val / scale, this.canvasWidth / 2, this.canvasHeight / 2);
  787. },
  788. },
  789. filters: {
  790. cutString: function (str, len) {
  791. //length属性读出来的汉字长度为1
  792. if (!!str && typeof str == "string" && str.length > len) {
  793. return str.substring(0, len) + "...";
  794. } else {
  795. return str || "--";
  796. }
  797. }
  798. },
  799. watch: {
  800. projectId() {
  801. this.FloorMap = '';
  802. this.tab = {};
  803. },
  804. "view.scale": {
  805. handler(n) {
  806. if (this.$refs.canvasFun) {
  807. this.$refs.canvasFun.sliderVal = n * 10 / this.view.minScale;
  808. }
  809. }
  810. },
  811. "scene.isRectSelection": {
  812. handler(n) {
  813. if (!n) {
  814. this.$refs.canvasFun.active = '';
  815. }
  816. }
  817. },
  818. "scene.isCutting": {
  819. handler(n) {
  820. if (!n) {
  821. this.$refs.canvasFun.active = '';
  822. this.$refs.canvasFun.isSwitch = false;
  823. this.scene.isAbsorbing = false;
  824. }
  825. }
  826. },
  827. }
  828. }
  829. </script>
  830. <style lang="less" scoped>
  831. #graphy {
  832. position: relative;
  833. width: 100%;
  834. height: calc(100% - 56px);
  835. .canvas-box {
  836. width: 100%;
  837. height: 100%;
  838. }
  839. .buttons-box {
  840. position: absolute;
  841. top: 0;
  842. width: 100%;
  843. z-index: 999;
  844. & > div {
  845. float: left;
  846. }
  847. /deep/ .el-autocomplete {
  848. display: block;
  849. width: 320px;
  850. margin-right: 10px;
  851. }
  852. .button-group button,
  853. .button-group .el-dropdown {
  854. display: block;
  855. float: left;
  856. }
  857. .my-autocomplete {
  858. li {
  859. line-height: normal;
  860. padding: 7px;
  861. .name {
  862. text-overflow: ellipsis;
  863. overflow: hidden;
  864. }
  865. .addr {
  866. font-size: 12px;
  867. color: #b4b4b4;
  868. }
  869. .highlighted .addr {
  870. color: #ddd;
  871. }
  872. }
  873. }
  874. }
  875. .canvas-actions-box {
  876. position: absolute;
  877. bottom: 20px;
  878. left: 50%;
  879. transform: translateX(-50%);
  880. z-index: 999;
  881. }
  882. }
  883. </style>