graphy.vue 48 KB

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