graphy.vue 38 KB

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