graphy.vue 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  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-show="type==5">
  75. <el-button type="primary" @click="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. this.scene.removeAllZone();
  446. this.scene.addZoneList(tempArr);
  447. this.scene.click(this, this.canvasClick);
  448. this.zoneList = this.scene.zoneList;
  449. this.view._needDraw = true;
  450. this.canvasLoading = false;
  451. }
  452. })
  453. },
  454. // canvas点击事件
  455. canvasClick(item, event) {
  456. console.log(item)
  457. console.log(event)
  458. if (this.type == 4) {//重新划分
  459. } else if (this.type == 5) {//批量
  460. } else {
  461. if (item instanceof SpaceItem && item.selectable) {
  462. if (this.spaceHeight == 0) {
  463. this.spaceHeight = item.data.Height > 1000 ? item.data.Height / 1000 : item.data.Height
  464. }
  465. if (this.type == 2) {
  466. this.scene.clearZoneSelection();
  467. }
  468. this.type = 3;
  469. this.curZoneItem = {};
  470. }
  471. if (item instanceof ZoneItem && item.selectable) {
  472. if (this.type == 3) {
  473. this.scene.clearSpaceSelection();
  474. }
  475. this.zoneDisable = false;
  476. this.curZoneItem = item;
  477. this.scene.clearZoneSelection();
  478. item.selected = true;
  479. this.$emit('copyID', this.curZoneItem.data.RoomID)
  480. }
  481. }
  482. },
  483. // 编辑平面图
  484. editGraphy() {
  485. this.type = 3;
  486. this.config.isEdit = true;
  487. this.config.groupSelect = false;
  488. this.config.divide = true;
  489. this.scene.isSpaceSelectable = true;
  490. // 设置业务空间不可选
  491. this.scene.isZoneSelectable = false
  492. this.view._needDraw = true;
  493. },
  494. // 查看未关联的业务空间--flag--查看-or-选择
  495. lookUnrelatBSpace(flag) {
  496. this.isAction = flag;
  497. let arr = this.scene.getSelectedSpaces();
  498. if (flag && !arr.length) {
  499. this.$message.warning('请至少选择一个空间');
  500. return;
  501. }
  502. // this.$refs.unRelateBSP.showDialog(this.buildFloor);
  503. this.$refs.unRelateBSP.showDialog();
  504. },
  505. // 取消(所有取消公用)
  506. cancelGraphy() {
  507. this.init(2);
  508. this.$emit('copyID', '')
  509. },
  510. // 批量创建业务空间弹窗
  511. handleCommand(command) {
  512. this.groupCreateDialogVis = true;
  513. },
  514. // 创建弹窗确认
  515. confirm() {
  516. if (this.groupCreateType == 1) {
  517. this.groupCreateBSpace()
  518. } else if (this.groupCreateType == 2) {
  519. this.type = 5;
  520. this.config.isEdit = true;
  521. this.config.groupSelect = true;
  522. this.config.divide = false;
  523. this.groupCreateDialogVis = false;
  524. // 清空选中空间
  525. this.scene.clearSpaceSelection();
  526. // 设置空间可选
  527. this.scene.isSpaceSelectable = true;
  528. // 设置业务空间不可选
  529. this.scene.isZoneSelectable = false;
  530. }
  531. },
  532. // 根据未关联元空间批量创建业务空间
  533. groupCreateBSpace() {
  534. let text = []
  535. let Spaces = this.allUnRelatISP.map(t => {
  536. if (t.outline) {
  537. let area = 0;
  538. if (t.outline[0]) {
  539. area = this.getarea(t.outline[0]);
  540. if (t.outline.length > 1) {
  541. for (let i = 1; i < t.outline.length; i++) {
  542. let temp = this.getarea(t.outline[i]);
  543. area = area - temp
  544. }
  545. }
  546. area = (area / 1000000).toFixed(2);
  547. if (area < (this.areaValue / 100)) {
  548. return undefined
  549. }
  550. } else {
  551. return undefined;
  552. }
  553. text.push(t.localName || t.name)
  554. let obj = {
  555. ispaceId: t.id,
  556. localName: t.localName || t.name,
  557. outline: [t.outline],
  558. buildingId: this.buildFloor[0],
  559. floorId: this.buildFloor[1],
  560. height: this.spaceHeight
  561. }
  562. if (t.customParam) {
  563. obj.customParam = t.customParam
  564. }
  565. // 2020-12-20 演示用 -start
  566. if (t.infos) {
  567. obj.infos = {}
  568. if (t.infos.roomLocalFuncTypeID) {
  569. obj.infos.roomLocalFuncTypeID = t.infos.roomLocalFuncTypeID
  570. }
  571. if (t.infos.roomLocalFuncTypeName) {
  572. obj.infos.roomLocalFuncTypeName = t.infos.roomLocalFuncTypeName
  573. }
  574. }
  575. // 2020-12-20 演示用 -end
  576. return obj;
  577. } else {
  578. return undefined
  579. }
  580. }).filter(item => item);
  581. if (Spaces.length) {
  582. this.$confirm(
  583. "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
  584. "<p>涉及的空间:</p>" +
  585. "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
  586. text.toString() +
  587. "</p>",
  588. "提示", {
  589. dangerouslyUseHTMLString: true,
  590. confirmButtonText: "确定",
  591. cancelButtonText: "取消",
  592. type: "warning"
  593. }
  594. ).then(() => {
  595. this.groupCreateDialogVis = false;
  596. this.canvasLoading = true;
  597. this.groupCreateBSP(Spaces)
  598. }).catch(() => {
  599. this.$message({
  600. type: "info",
  601. message: "已取消批量创建"
  602. });
  603. });
  604. } else {
  605. this.$message('没有未关联的空间')
  606. }
  607. },
  608. // 创建新的业务空间
  609. createNewZone() {
  610. let arr = this.scene.getSelectedSpaces();
  611. if (arr.length) {
  612. let tempArr = [];
  613. arr.map(t => {
  614. if (this.BIMIDToSIName[t.data.sourceId]) {
  615. tempArr.push(this.BIMIDToSIName[t.data.sourceId]);
  616. }
  617. })
  618. this.$refs.createBSP.showDialog(tempArr.toString());
  619. } else {
  620. this.$message.warning('请至少选择一个空间');
  621. }
  622. },
  623. // 根据图创建新的业务空间-弹窗返回确认创建
  624. createRoom(val) {
  625. const zoneObj = { outline: [], height: 0 }, IspaceIdList = [];
  626. let spaces = {};
  627. try {
  628. if (this.scene.cutItem || this.scene.sceneMark) {
  629. // 如果有划分,求交集
  630. // 格式为Poly(先与业务空间求差集)
  631. const obj = this.scene.getZoneDifference(true);
  632. // 差集与楼层平面图或用户划分区域求交集
  633. spaces = this.scene.getPloyIntersect(obj)
  634. } else {
  635. // 格式为SPoint[]
  636. spaces = this.scene.getZoneDifference();
  637. }
  638. for (let key in spaces) {
  639. spaces[key] = spaces[key].map(t => {
  640. let temp = t.map(item => {
  641. return {
  642. X: 1 * item.x.toFixed(2),
  643. Y: -item.y.toFixed(2),
  644. Z: 0
  645. }
  646. })
  647. return temp;
  648. })
  649. let newarr = this.makeMaxAreaFirst(spaces[key])
  650. zoneObj.outline.push(newarr);
  651. let curISP = this.sourceIdToISP[key];
  652. if (curISP) {
  653. curISP && IspaceIdList.push(curISP.id);
  654. zoneObj.height = this.spaceHeight;
  655. // 2020-12-20 演示用 -start
  656. console.log(curISP);
  657. if (curISP.infos) {
  658. zoneObj.infos = {}
  659. if (curISP.infos.roomLocalFuncTypeID) {
  660. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  661. }
  662. if (curISP.infos.roomLocalFuncTypeName) {
  663. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  664. }
  665. }
  666. // 2020-12-20 演示用 -end
  667. }
  668. }
  669. } catch (err) {
  670. console.log(err)
  671. let selectSpaces = this.scene.getSelectedSpaces();
  672. selectSpaces.map(t => {
  673. zoneObj.outline.push(t.data.outLine);
  674. let key = t.data.sourceId;
  675. let curISP = this.sourceIdToISP[key];
  676. if (curISP) {
  677. IspaceIdList.push(curISP.id);
  678. zoneObj.height = this.spaceHeight;
  679. // 2020-12-20 演示用 -start
  680. console.log(curISP);
  681. if (curISP.infos) {
  682. zoneObj.infos = {}
  683. if (curISP.infos.roomLocalFuncTypeID) {
  684. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  685. }
  686. if (curISP.infos.roomLocalFuncTypeName) {
  687. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  688. }
  689. }
  690. // 2020-12-20 演示用 -end
  691. }
  692. })
  693. // 如果有划分,求交集
  694. if (this.scene.cutItem || this.scene.sceneMark) {
  695. zoneObj.outline = [];
  696. let arr = this.scene.getIntersect();
  697. arr.map(t => {
  698. let temp = t.map(item => {
  699. return {
  700. X: 1 * item.x,
  701. Y: -item.y,
  702. Z: 0
  703. }
  704. })
  705. zoneObj.outline.push([temp]);
  706. })
  707. }
  708. }
  709. // 至此
  710. if (!zoneObj.outline.length) {
  711. zoneObj.outline = null;
  712. }
  713. zoneObj.localName = val;
  714. zoneObj.buildingId = this.buildFloor[0];
  715. zoneObj.floorId = this.buildFloor[1];
  716. this.createSingleBSP(zoneObj, IspaceIdList)
  717. },
  718. // 根据图从未关联平面图的业务空间中选择--按钮返回关联信号
  719. createFromUnrelated(zoneObj) {
  720. zoneObj.outline = [];
  721. zoneObj.height = 0;
  722. let spaces = {}, IspaceIdList = [];
  723. try {
  724. if (this.scene.cutItem || this.scene.sceneMark) {
  725. // 如果有划分,求交集
  726. // 格式为Poly(先与业务空间求差集)
  727. const obj = this.scene.getZoneDifference(true);
  728. // 差集与楼层平面图或用户划分区域求交集
  729. spaces = this.scene.getPloyIntersect(obj)
  730. } else {
  731. // 格式为SPoint[]
  732. spaces = this.scene.getZoneDifference();
  733. }
  734. for (let key in spaces) {
  735. spaces[key] = spaces[key].map(t => {
  736. let temp = t.map(item => {
  737. return {
  738. X: 1 * item.x.toFixed(2),
  739. Y: -item.y.toFixed(2),
  740. Z: 0
  741. }
  742. })
  743. return temp;
  744. })
  745. let newarr = this.makeMaxAreaFirst(spaces[key])
  746. zoneObj.outline.push(newarr);
  747. let curISP = this.sourceIdToISP[key];
  748. if (curISP) {
  749. curISP && IspaceIdList.push(curISP.id);
  750. zoneObj.height = this.spaceHeight;
  751. // 2020-12-20 演示用 -start
  752. if (curISP.infos) {
  753. zoneObj.infos = {}
  754. if (curISP.infos.roomLocalFuncTypeID) {
  755. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  756. }
  757. if (curISP.infos.roomLocalFuncTypeName) {
  758. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  759. }
  760. }
  761. // 2020-12-20 演示用 -end
  762. }
  763. }
  764. } catch (err) {
  765. console.log(err);
  766. let selectSpaces = this.scene.getSelectedSpaces();
  767. selectSpaces.map(t => {
  768. zoneObj.outline.push(t.data.outLine);
  769. let key = t.data.sourceId;
  770. let curISP = this.sourceIdToISP[key];
  771. if (curISP) {
  772. curISP && IspaceIdList.push(curISP.id);
  773. zoneObj.height = this.spaceHeight;
  774. // 2020-12-20 演示用 -start
  775. if (curISP.infos) {
  776. zoneObj.infos = {}
  777. if (curISP.infos.roomLocalFuncTypeID) {
  778. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  779. }
  780. if (curISP.infos.roomLocalFuncTypeName) {
  781. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  782. }
  783. }
  784. // 2020-12-20 演示用 -end
  785. }
  786. })
  787. // 如果有划分,求交集
  788. if (this.scene.cutItem || this.scene.sceneMark) {
  789. zoneObj.outline = [];
  790. let arr = this.scene.getIntersect();
  791. arr.map(t => {
  792. let temp = t.map(item => {
  793. return {
  794. X: 1 * item.x,
  795. Y: -item.y,
  796. Z: 0
  797. }
  798. })
  799. zoneObj.outline.push([temp]);
  800. })
  801. }
  802. }
  803. if (!zoneObj.outline.length) {
  804. zoneObj.outline = null;
  805. }
  806. this.updateBSPOutline(zoneObj, IspaceIdList)
  807. },
  808. // 编辑空间详情
  809. editeSpaceDetail() {
  810. let item = this.curZoneItem.data;
  811. let query = {
  812. RoomID: item.RoomID,
  813. zone: this.tab.code,
  814. isMyTab: 1,
  815. buildFloorSelectd: this.buildFloor
  816. }
  817. this.$router.push({
  818. path: "/ledger/spaceDetail",
  819. query: query
  820. })
  821. },
  822. // 重新划分业务空间
  823. refactorBSP() {
  824. this.config.isEdit = true;
  825. this.config.groupSelect = false;
  826. this.config.divide = true;
  827. this.type = 4;
  828. // 设置空间可选
  829. this.scene.isSpaceSelectable = true;
  830. // 将已关联的设置不可选,并将当前选的隐藏
  831. this.scene.isZoneSelectable = false;
  832. this.curZoneItem.visible = false;
  833. // 将当前业务空间的每个元素添加到场景中并选中
  834. this.scene.addAllLikeSpace(this.curZoneItem.data.OutLine);
  835. },
  836. // 确认业务空间
  837. confirmZoneSpace() {
  838. let ObjectType = this.tab.code
  839. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  840. let space = {
  841. id: this.curZoneItem.data.RoomID,
  842. state: 0,
  843. classCode: ObjectType
  844. }
  845. let pa = {
  846. content: [space],
  847. projection: ['state']
  848. }
  849. zoneUpdate(pa, res => {
  850. this.curZoneItem.isInfected = false;
  851. this.$emit('updateState');
  852. this.$message.success('更新成功');
  853. })
  854. },
  855. // 保存并确认业务空间
  856. confirmAndSave() {
  857. this.confirmAndSaveFlag = true;
  858. this.saveRefactorBSP();
  859. },
  860. // 重新划分--保存
  861. saveRefactorBSP() {
  862. let selectSpace = this.scene.getSelectedSpaces();
  863. let selectLikeSpace = this.scene.getSelectedLikeSpace();
  864. //更新业务空间
  865. let zoneObj = { outline: [], height: 0, state: this.confirmAndSaveFlag ? 0 : this.curZoneItem.isInfected ? 1 : 0 }, IspaceIdList = [];
  866. // 空间
  867. selectSpace.map(t => {
  868. zoneObj.outline.push(t.data.OutLine);
  869. if (this.BIMIDToSID[t.data.SourceId]) {
  870. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  871. }
  872. // 2020-12-20 演示用 -start
  873. if (this.sourceIdToISP[t.data.sourceId] && this.sourceIdToISP[t.data.sourceId].infos) {
  874. zoneObj.infos = {};
  875. if (this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID) {
  876. zoneObj.infos.roomLocalFuncTypeID = this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID
  877. }
  878. if (this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName) {
  879. zoneObj.infos.roomLocalFuncTypeName = this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName
  880. }
  881. }
  882. // 2020-12-20 演示用 -end
  883. zoneObj.height = this.spaceHeight
  884. })
  885. // 类空间
  886. selectLikeSpace.map(t => {
  887. zoneObj.outline.push(t.data);
  888. })
  889. // 如果有划分,求交集
  890. if (this.scene.cutItem || this.scene.sceneMark) {
  891. zoneObj.outline = [];
  892. let spaceIntersect = this.scene.getIntersect();
  893. spaceIntersect.map(t => {
  894. let temp = t.map(item => {
  895. return {
  896. X: item.x,
  897. Y: -item.y,
  898. Z: 0
  899. }
  900. })
  901. zoneObj.outline.push([temp]);
  902. })
  903. let likeSpaceIntersect = this.scene.getLikeIntersect();
  904. likeSpaceIntersect.map(t => {
  905. let temp = t.map(item => {
  906. return {
  907. X: item.x,
  908. Y: -item.y,
  909. Z: 0
  910. }
  911. })
  912. zoneObj.outline.push([temp]);
  913. })
  914. }
  915. if (!zoneObj.outline.length) {
  916. zoneObj.outline = null;
  917. }
  918. zoneObj.id = this.curZoneItem.data.RoomID;
  919. this.updateBSPOutline(zoneObj, IspaceIdList)
  920. },
  921. // 根据图批量创建所选业务空间
  922. groupCreateZone() {
  923. let arr = this.scene.getSelectedSpaces();
  924. let createSpaces = [], spaces = {};
  925. try {
  926. if (this.scene.cutItem || this.scene.sceneMark) {
  927. // 如果有划分,求交集
  928. // 格式为Poly(先与业务空间求差集)
  929. const obj = this.scene.getZoneDifference(true);
  930. // 差集与楼层平面图或用户划分区域求交集
  931. spaces = this.scene.getPloyIntersect(obj)
  932. } else {
  933. // 格式为SPoint[]
  934. spaces = this.scene.getZoneDifference();
  935. }
  936. for (let key in spaces) {
  937. let zoneObj = { outline: [], height: 0 }
  938. spaces[key] = spaces[key].map(t => {
  939. let temp = t.map(item => {
  940. return {
  941. X: 1 * item.x.toFixed(2),
  942. Y: -item.y.toFixed(2),
  943. Z: 0
  944. }
  945. })
  946. return temp;
  947. })
  948. let newarr = this.makeMaxAreaFirst(spaces[key])
  949. zoneObj.outline.push(newarr);
  950. if (!zoneObj.outline.length) {
  951. continue
  952. }
  953. //计算面积
  954. let area = 0, line = zoneObj.outline;
  955. for (let i = 0; i < line.length; i++) {
  956. for (let j = 0; j < line[i].length; j++) {
  957. if (j == 0) {
  958. area += this.getarea(line[i][0]);
  959. } else {
  960. area -= this.getarea(line[i][j]);
  961. }
  962. }
  963. }
  964. area = (area / 1000000).toFixed(2);
  965. if (area < (this.areaValue / 100)) {
  966. continue
  967. }
  968. //生成空间对象
  969. let curISP = this.sourceIdToISP[key];
  970. if (curISP) {
  971. zoneObj.height = this.spaceHeight;
  972. // zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
  973. zoneObj.ispaceId = curISP.id;
  974. zoneObj.localName = curISP.localName || '';
  975. // 2020-12-20 演示用 -start
  976. if (curISP.infos) {
  977. zoneObj.infos = {}
  978. if (curISP.infos.roomLocalFuncTypeID) {
  979. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  980. }
  981. if (curISP.infos.roomLocalFuncTypeName) {
  982. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  983. }
  984. }
  985. // 2020-12-20 演示用 -end
  986. }
  987. zoneObj.buildingId = this.buildFloor[0];
  988. zoneObj.floorId = this.buildFloor[1];
  989. createSpaces.push(zoneObj);
  990. }
  991. } catch (err) {
  992. console.log(err)
  993. let createSpaces = [];
  994. // 如果有划分,求交集
  995. if (this.scene.cutItem || this.scene.sceneMark) {
  996. let outlines = this.scene.getIntersectInSpace();
  997. for (let k in outlines) {
  998. outlines[k] = outlines[k].map(t => {
  999. t = t.map(item => {
  1000. item = item.map(j => {
  1001. return { X: j.x, Y: -j.y, Z: 0 }
  1002. })
  1003. return item
  1004. })
  1005. return t;
  1006. })
  1007. }
  1008. createSpaces = arr.map(t => {
  1009. let line = outlines[t.data.SourceId];
  1010. if (!line || !line.length) {
  1011. return undefined
  1012. } else {
  1013. let area = 0;
  1014. for (let i = 0; i < line.length; i++) {
  1015. for (let j = 0; j < line[i].length; j++) {
  1016. if (j == 0) {
  1017. area += this.getarea(line[i][0]);
  1018. } else {
  1019. area -= this.getarea(line[i][j]);
  1020. }
  1021. }
  1022. }
  1023. area = (area / 1000000).toFixed(2);
  1024. if (area < (this.areaValue / 100)) {
  1025. return undefined;
  1026. }
  1027. }
  1028. return {
  1029. ispaceId: this.BIMIDToSID[t.data.sourceId],
  1030. localName: this.BIMIDToSIName[t.data.sourceId] || '',
  1031. outline: line,
  1032. buildingId: this.buildFloor[0],
  1033. floorId: this.buildFloor[1],
  1034. height: this.spaceHeight,
  1035. // 2020-12-20 演示用 -start
  1036. infos: {
  1037. roomLocalFuncTypeID: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID || '' : '',
  1038. roomLocalFuncTypeName: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName || '' : ''
  1039. }
  1040. // 2020-12-20 演示用 -end
  1041. }
  1042. }).filter(item => item)
  1043. } else {
  1044. createSpaces = arr.map(t => {
  1045. let line = t.data.outLine;
  1046. if (!line || !line.length) {
  1047. return undefined
  1048. } else {
  1049. let area = this.getarea(line[0]);
  1050. if (line.length > 1) {
  1051. for (let i = 1; i < line.length; i++) {
  1052. area -= this.getarea(line[i]);
  1053. }
  1054. }
  1055. area = (area / 1000000).toFixed(2);
  1056. if (area < (this.areaValue / 100)) {
  1057. return undefined;
  1058. }
  1059. }
  1060. return {
  1061. ispaceId: this.BIMIDToSID[t.data.sourceId],
  1062. localName: this.BIMIDToSIName[t.data.sourceId] || '',
  1063. outline: [line],
  1064. buildingId: this.buildFloor[0],
  1065. floorId: this.buildFloor[1],
  1066. height: this.spaceHeight,
  1067. // 2020-12-20 演示用 -start
  1068. infos: {
  1069. roomLocalFuncTypeID: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID || '' : '',
  1070. roomLocalFuncTypeName: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName || '' : ''
  1071. }
  1072. // 2020-12-20 演示用 -end
  1073. }
  1074. }).filter(item => item);
  1075. }
  1076. }
  1077. if (createSpaces.length) {
  1078. this.canvasLoading = true;
  1079. this.groupCreateBSP(createSpaces)
  1080. } else {
  1081. this.$message.warning('未选择空间');
  1082. }
  1083. },
  1084. // 更新业务空间和元空间的关系
  1085. relationInBSPandISP(SpaceId, IspaceIdList) {
  1086. let ObjectType = this.tab.code;
  1087. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1088. let pa = {
  1089. data: { spaceId: SpaceId, ispaceIdList: IspaceIdList },
  1090. type: ObjectType
  1091. }
  1092. createRelateInZoneAndISp(pa, res => {
  1093. this.$message.success('创建成功');
  1094. this.init(2);
  1095. if (this.confirmAndSaveFlag) {
  1096. this.confirmAndSaveFlag = false;
  1097. this.curZoneItem.selected = false;
  1098. this.curZoneItem = {};
  1099. this.$emit('updateState');
  1100. }
  1101. })
  1102. },
  1103. // 批量更新业务空间和元空间的关系
  1104. groupCreRelaZoneAndISp(Spaces) {
  1105. Spaces = Spaces.filter(item => item.ispaceId);
  1106. let ObjectType = this.tab.code;
  1107. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1108. if (Spaces.length) {
  1109. let param = {
  1110. data: {
  1111. content: Spaces
  1112. },
  1113. type: ObjectType
  1114. }
  1115. groupCreRelaZoneAndISp(param, res => {
  1116. this.$message.success('创建成功')
  1117. this.canvasLoading = false;
  1118. this.init(2)
  1119. })
  1120. } else {
  1121. this.$message.success('创建成功')
  1122. this.canvasLoading = false;
  1123. this.init(2)
  1124. }
  1125. },
  1126. // 批量创建
  1127. groupCreateBSP(spaces) {
  1128. let ObjectType = this.tab.code;
  1129. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1130. spaces = spaces.map(t => {
  1131. t.classCode = ObjectType;
  1132. t.bimLocation = this.getAverageVal(t.outline);
  1133. return t;
  1134. })
  1135. let pa = {
  1136. content: spaces,
  1137. }
  1138. zoneCreate(pa, res => {
  1139. res.entityList.map(t => {
  1140. spaces = spaces.map(item => {
  1141. if (t.localName == item.localName) {
  1142. item.spaceId = t.id
  1143. }
  1144. return item;
  1145. })
  1146. })
  1147. this.groupCreRelaZoneAndISp(spaces)
  1148. })
  1149. },
  1150. // 单个创建
  1151. createSingleBSP(space, IspaceIdList) {
  1152. let ObjectType = this.tab.code;
  1153. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1154. space.bimLocation = space.outline ? this.getAverageVal(space.outline) : null;
  1155. space.classCode = ObjectType;
  1156. let pa = {
  1157. content: [space]
  1158. }
  1159. zoneCreate(pa, res => {
  1160. this.relationInBSPandISP(res.entityList[0].id, IspaceIdList)
  1161. })
  1162. },
  1163. // 更新业务空间区域
  1164. updateBSPOutline(zoneObj, IspaceIdList) {
  1165. let ObjectType = this.tab.code;
  1166. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1167. zoneObj.bimLocation = zoneObj.outline ? this.getAverageVal(zoneObj.outline) : null;
  1168. zoneObj.classCode = ObjectType;
  1169. zoneObj.buildingId = this.buildFloor[0];
  1170. zoneObj.floorId = this.buildFloor[1];
  1171. let pa = {
  1172. content: [zoneObj],
  1173. projection: ['bimLocation', 'classCode', 'outline', 'height', 'buildingId', 'floorId']
  1174. }
  1175. zoneUpdate(pa, res => {
  1176. zoneUpdateOutline(pa, res => { console.log(res) })
  1177. this.updateZoneBF(zoneObj, IspaceIdList);
  1178. })
  1179. },
  1180. // 从未关联平面图的业务空间中选择时更新业务空间建筑楼层
  1181. updateZoneBF(zoneObj, IspaceIdList) {
  1182. let pa = [{
  1183. type: zoneObj.classCode,
  1184. spaceId: zoneObj.id,
  1185. id: zoneObj.floorId,
  1186. }]
  1187. handleZoneUpdateBd(pa, res => {
  1188. this.relationInBSPandISP(zoneObj.id, IspaceIdList)
  1189. })
  1190. },
  1191. // 查询未关联平面图的业务空间(项目下+当前分区)
  1192. getBSPunrelaISP() {
  1193. let ObjectType = this.tab.code;
  1194. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1195. let pa = {
  1196. Filters: `outline isNull;classCode="${ObjectType}"`
  1197. }
  1198. zoneCount(pa, res => {
  1199. this.num = res.count;
  1200. })
  1201. },
  1202. // 计算平均值 作为业务空间BIMLocation
  1203. getAverageVal(Outline) {
  1204. let X = 0, Y = 0, Z = 0, len = 0;
  1205. Outline.map(t => {
  1206. if (t[0]) {
  1207. t[0].map(item => {
  1208. X += item.X;
  1209. Y += item.Y;
  1210. Z += item.Z;
  1211. })
  1212. len += t[0].length
  1213. }
  1214. })
  1215. X = (X / len).toFixed(2);
  1216. Y = (Y / len).toFixed(2);
  1217. Z = (Z / len).toFixed(2);
  1218. return `${X},${Y},${Z}`
  1219. },
  1220. // 计算面积
  1221. getarea(arr) {
  1222. if (!arr.length) {
  1223. return 0;
  1224. }
  1225. let sum = 0;
  1226. let n = arr.length;
  1227. arr[n] = arr[0];
  1228. for (let i = 1; i <= n; i++) {
  1229. sum += arr[i].X * arr[i - 1].Y - arr[i - 1].X * arr[i].Y;
  1230. }
  1231. return Math.abs(sum / 2)
  1232. },
  1233. // canvas 获取焦点
  1234. focus() {
  1235. document.getElementById(`floorCanvas`).focus()
  1236. },
  1237. // 清除canvas
  1238. clearGraphy() {
  1239. if (this.view) {
  1240. this.view.scene = null;
  1241. return
  1242. }
  1243. this.view = new FloorView('floorCanvas')
  1244. },
  1245. // 工具栏操作
  1246. // 吸附
  1247. changeAbsorb(isAbsorbing) {
  1248. this.scene.isAbsorbing = isAbsorbing;
  1249. },
  1250. // 框选
  1251. groupSelect() {
  1252. this.scene.isRectSelection = 1;
  1253. },
  1254. // 适配底图到窗口
  1255. fit() {
  1256. if (this.scene.sceneMark) {
  1257. this.view.fitItemToView([this.scene.sceneMark])
  1258. return
  1259. }
  1260. this.view.fitSceneToView()
  1261. },
  1262. // 保存为png
  1263. savePng() {
  1264. this.view.saveImage(`${this.projectName}-${this.buildFloorName}.png`, 'png');
  1265. },
  1266. // 保存为svg
  1267. saveSvg() {
  1268. this.view.saveSceneSvg(`${this.projectName}-${this.buildFloorName}.svg`, 6400, 4800);
  1269. },
  1270. // 保存json
  1271. saveJson() {
  1272. this.view.saveFloorJson(`${this.projectName}-${this.buildFloorName}.json`)
  1273. },
  1274. // 切割划分
  1275. divide() {
  1276. this.scene.isCutting = true;
  1277. },
  1278. // 清除切割划分
  1279. clearDivide() {
  1280. this.scene.clearCut();
  1281. },
  1282. // 撤销
  1283. undo() { },
  1284. // 反撤销
  1285. redo() { },
  1286. // 缩放
  1287. scale(val) {
  1288. if (!this.view) {
  1289. return;
  1290. }
  1291. let scale = this.view.scale;
  1292. this.view.scaleByPoint(val / scale, this.canvasWidth / 2, this.canvasHeight / 2);
  1293. },
  1294. // 给定多个轮廓线的数据,计算得到面积最大值,并把它放置数组第一项,并将第一项顺时针处理,第一项以后的每一项做逆时针处理
  1295. // list {XYZ}[][]
  1296. makeMaxAreaFirst(list) {
  1297. let arr = [], area = 0;
  1298. for (let i = 0; i < list.length; i++) {
  1299. let temp = this.getarea(list[i])
  1300. if (temp > area) {
  1301. arr.unshift(list[i])
  1302. } else {
  1303. arr.push(list[i])
  1304. }
  1305. }
  1306. arr.map((t, i) => {
  1307. if (!i) {
  1308. if (this.clockDir(t) > 0) {
  1309. return t
  1310. } else {
  1311. return t.reverse()
  1312. }
  1313. } else {
  1314. if (this.clockDir(t) > 0) {
  1315. return t.reverse()
  1316. } else {
  1317. return t
  1318. }
  1319. }
  1320. })
  1321. return arr;
  1322. },
  1323. // 数组为顺时针or逆时针 顺时针非负 逆时针为 负
  1324. clockDir(pointList) {
  1325. let l = pointList.length - 1
  1326. if (pointList[0].x == pointList[l].x && pointList[0].y == pointList[l].y) {
  1327. pointList.splice(l, 1);
  1328. }
  1329. if (pointList.length < 3) {
  1330. return 0;
  1331. }
  1332. let index = 0;
  1333. let len = pointList.length;
  1334. for (let i = 1; i < len; i++) {
  1335. if (pointList[i].X > pointList[index].X) {
  1336. index = i;
  1337. }
  1338. }
  1339. let p1 = pointList[index == 0 ? len - 1 : index - 1];
  1340. let p2 = pointList[index];
  1341. let p3 = pointList[(index + 1) % len];
  1342. return (p2.X - p1.X) * (p3.Y - p2.Y) - (p2.Y - p1.Y) * (p3.X - p2.X);
  1343. }
  1344. },
  1345. filters: {
  1346. cutString: function (str, len) {
  1347. //length属性读出来的汉字长度为1
  1348. if (!!str && typeof str == "string" && str.length > len) {
  1349. return str.substring(0, len) + "...";
  1350. } else {
  1351. return str || "--";
  1352. }
  1353. }
  1354. },
  1355. watch: {
  1356. projectId() {
  1357. this.FloorMap = '';
  1358. this.tab = {};
  1359. },
  1360. "view.scale": {
  1361. handler(n) {
  1362. if (this.$refs.canvasFun) {
  1363. let s = n * 10 / this.view.minScale
  1364. this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s;
  1365. }
  1366. }
  1367. },
  1368. "scene.isRectSelection": {
  1369. handler(n) {
  1370. if (!n) {
  1371. this.$refs.canvasFun.active = '';
  1372. }
  1373. }
  1374. },
  1375. "scene.isCutting": {
  1376. handler(n) {
  1377. if (!n) {
  1378. this.$refs.canvasFun.active = '';
  1379. this.$refs.canvasFun.isSwitch = false;
  1380. this.scene.isAbsorbing = false;
  1381. }
  1382. }
  1383. },
  1384. }
  1385. }
  1386. </script>
  1387. <style lang="less" scoped>
  1388. #graphy {
  1389. position: relative;
  1390. width: 100%;
  1391. box-sizing: border-box;
  1392. padding: 0 10px 10px;
  1393. height: calc(100% - 56px);
  1394. .canvas-box {
  1395. width: 100%;
  1396. height: 100%;
  1397. }
  1398. .buttons-box {
  1399. position: absolute;
  1400. top: 0;
  1401. left: 0;
  1402. padding: 0 10px;
  1403. width: 100%;
  1404. z-index: 999;
  1405. & > div {
  1406. float: left;
  1407. }
  1408. /deep/ .el-autocomplete {
  1409. display: inline-block;
  1410. width: 320px;
  1411. margin-right: 10px;
  1412. }
  1413. .button-group button,
  1414. .button-group .el-dropdown {
  1415. display: block;
  1416. float: left;
  1417. }
  1418. .my-autocomplete {
  1419. li {
  1420. line-height: normal;
  1421. padding: 7px;
  1422. .name {
  1423. text-overflow: ellipsis;
  1424. overflow: hidden;
  1425. }
  1426. .addr {
  1427. font-size: 12px;
  1428. color: #b4b4b4;
  1429. }
  1430. .highlighted .addr {
  1431. color: #ddd;
  1432. }
  1433. }
  1434. }
  1435. }
  1436. .canvas-actions-box {
  1437. position: absolute;
  1438. bottom: 60px;
  1439. left: 50%;
  1440. transform: translateX(-50%);
  1441. z-index: 99;
  1442. }
  1443. #autoRelate {
  1444. /deep/ .el-slider__marks-text:nth-child(2) {
  1445. width: 25px;
  1446. }
  1447. }
  1448. }
  1449. </style>