graphy.vue 28 KB

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