graphy.vue 30 KB

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