graphy.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  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"></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. console.log('数据解析异常');
  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. return {
  437. RoomLocalName: t.localName || t.name,
  438. OutLine: t.outline,
  439. RoomID: t.id,
  440. Color: colorArr[i % colorArr.length],
  441. Infected: t.state
  442. }
  443. }).filter(item => item)
  444. try {
  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.fit();
  451. } catch (err) {
  452. console.log(err, '------------');
  453. console.log(this)
  454. }
  455. this.canvasLoading = false;
  456. }
  457. })
  458. },
  459. // canvas点击事件
  460. canvasClick(item, event) {
  461. console.log(item)
  462. console.log(event)
  463. if (this.type == 4) {//重新划分
  464. } else if (this.type == 5) {//批量
  465. } else {
  466. if (item instanceof SpaceItem && item.selectable) {
  467. if (this.spaceHeight == 0) {
  468. this.spaceHeight = item.data.Height > 1000 ? item.data.Height / 1000 : item.data.Height
  469. }
  470. if (this.type == 2) {
  471. this.scene.clearZoneSelection();
  472. }
  473. this.type = 3;
  474. this.curZoneItem = {};
  475. }
  476. if (item instanceof ZoneItem && item.selectable) {
  477. if (this.type == 3) {
  478. this.scene.clearSpaceSelection();
  479. }
  480. this.zoneDisable = false;
  481. this.curZoneItem = item;
  482. this.scene.clearZoneSelection();
  483. item.selected = true;
  484. this.$emit('copyID', this.curZoneItem.data.RoomID)
  485. }
  486. }
  487. },
  488. // 编辑平面图
  489. editGraphy() {
  490. this.type = 3;
  491. this.config.isEdit = true;
  492. this.config.groupSelect = false;
  493. this.config.divide = true;
  494. this.scene.isSpaceSelectable = true;
  495. // 设置业务空间不可选
  496. this.scene.isZoneSelectable = false
  497. this.view._needDraw = true;
  498. },
  499. // 查看未关联的业务空间--flag--查看-or-选择
  500. lookUnrelatBSpace(flag) {
  501. this.isAction = flag;
  502. let arr = this.scene.getSelectedSpaces();
  503. if (flag && !arr.length) {
  504. this.$message.warning('请至少选择一个空间');
  505. return;
  506. }
  507. // this.$refs.unRelateBSP.showDialog(this.buildFloor);
  508. this.$refs.unRelateBSP.showDialog();
  509. },
  510. // 取消(所有取消公用)
  511. cancelGraphy() {
  512. this.init(2);
  513. this.$emit('copyID', '')
  514. },
  515. // 批量创建业务空间弹窗
  516. handleCommand(command) {
  517. this.groupCreateDialogVis = true;
  518. },
  519. // 创建弹窗确认
  520. confirm() {
  521. if (this.groupCreateType == 1) {
  522. this.groupCreateBSpace()
  523. } else if (this.groupCreateType == 2) {
  524. this.type = 5;
  525. this.config.isEdit = true;
  526. this.config.groupSelect = true;
  527. this.config.divide = false;
  528. this.groupCreateDialogVis = false;
  529. // 清空选中空间
  530. this.scene.clearSpaceSelection();
  531. // 设置空间可选
  532. this.scene.isSpaceSelectable = true;
  533. // 设置业务空间不可选
  534. this.scene.isZoneSelectable = false;
  535. // 刷新
  536. this.view.update()
  537. }
  538. },
  539. // 根据未关联元空间批量创建业务空间
  540. groupCreateBSpace() {
  541. let text = []
  542. let Spaces = this.allUnRelatISP.map(t => {
  543. if (t.outline) {
  544. let area = 0;
  545. if (t.outline[0]) {
  546. area = this.getarea(t.outline[0]);
  547. if (t.outline.length > 1) {
  548. for (let i = 1; i < t.outline.length; i++) {
  549. let temp = this.getarea(t.outline[i]);
  550. area = area - temp
  551. }
  552. }
  553. area = (area / 1000000).toFixed(2);
  554. if (area < (this.areaValue / 100)) {
  555. return undefined
  556. }
  557. } else {
  558. return undefined;
  559. }
  560. text.push(t.localName || t.name)
  561. let obj = {
  562. ispaceId: t.id,
  563. localName: t.localName || t.name,
  564. outline: [t.outline],
  565. buildingId: this.buildFloor[0],
  566. floorId: this.buildFloor[1],
  567. height: this.spaceHeight
  568. }
  569. if (t.customParam) {
  570. obj.customParam = t.customParam
  571. }
  572. // 2020-12-20 演示用 -start
  573. if (t.infos) {
  574. obj.infos = {}
  575. if (t.infos.roomLocalFuncTypeID) {
  576. obj.infos.roomLocalFuncTypeID = t.infos.roomLocalFuncTypeID
  577. }
  578. if (t.infos.roomLocalFuncTypeName) {
  579. obj.infos.roomLocalFuncTypeName = t.infos.roomLocalFuncTypeName
  580. }
  581. }
  582. // 2020-12-20 演示用 -end
  583. return obj;
  584. } else {
  585. return undefined
  586. }
  587. }).filter(item => item);
  588. if (Spaces.length) {
  589. this.$confirm(
  590. "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
  591. "<p>涉及的空间:</p>" +
  592. "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
  593. text.toString() +
  594. "</p>",
  595. "提示", {
  596. dangerouslyUseHTMLString: true,
  597. confirmButtonText: "确定",
  598. cancelButtonText: "取消",
  599. type: "warning"
  600. }
  601. ).then(() => {
  602. this.groupCreateDialogVis = false;
  603. this.canvasLoading = true;
  604. this.groupCreateBSP(Spaces)
  605. }).catch(() => {
  606. this.$message({
  607. type: "info",
  608. message: "已取消批量创建"
  609. });
  610. });
  611. } else {
  612. this.$message('没有未关联的空间')
  613. }
  614. },
  615. // 创建新的业务空间
  616. createNewZone() {
  617. let arr = this.scene.getSelectedSpaces();
  618. if (arr.length) {
  619. let tempArr = [];
  620. arr.map(t => {
  621. if (this.BIMIDToSIName[t.data.SourceId]) {
  622. tempArr.push(this.BIMIDToSIName[t.data.SourceId]);
  623. }
  624. })
  625. this.$refs.createBSP.showDialog(tempArr.toString());
  626. } else {
  627. this.$message.warning('请至少选择一个空间');
  628. }
  629. },
  630. // 根据图创建新的业务空间-弹窗返回确认创建
  631. createRoom(val) {
  632. const zoneObj = { outline: [], height: 0 }, IspaceIdList = [];
  633. let spaces = {};
  634. try {
  635. if (this.scene.cutItem || this.scene.sceneMark) {
  636. // 如果有划分,求交集
  637. // 格式为Poly(先与业务空间求差集)
  638. const obj = this.scene.getZoneDifference(true);
  639. // 差集与楼层平面图或用户划分区域求交集
  640. spaces = this.scene.getPloyIntersect(obj)
  641. } else {
  642. // 格式为SPoint[]
  643. spaces = this.scene.getZoneDifference();
  644. }
  645. for (let key in spaces) {
  646. spaces[key] = spaces[key].map(t => {
  647. let temp = t.map(item => {
  648. return {
  649. X: 1 * item.x.toFixed(2),
  650. Y: -item.y.toFixed(2),
  651. Z: 0
  652. }
  653. })
  654. return temp;
  655. })
  656. let newarr = this.makeMaxAreaFirst(spaces[key])
  657. zoneObj.outline.push(newarr);
  658. let curISP = this.sourceIdToISP[key];
  659. if (curISP) {
  660. curISP && IspaceIdList.push(curISP.id);
  661. zoneObj.height = this.spaceHeight;
  662. // 2020-12-20 演示用 -start
  663. console.log(curISP);
  664. if (curISP.infos) {
  665. zoneObj.infos = {}
  666. if (curISP.infos.roomLocalFuncTypeID) {
  667. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  668. }
  669. if (curISP.infos.roomLocalFuncTypeName) {
  670. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  671. }
  672. }
  673. // 2020-12-20 演示用 -end
  674. }
  675. }
  676. } catch (err) {
  677. console.log(err)
  678. let selectSpaces = this.scene.getSelectedSpaces();
  679. selectSpaces.map(t => {
  680. zoneObj.outline.push(t.data.OutLine);
  681. let key = t.data.SourceId;
  682. let curISP = this.sourceIdToISP[key];
  683. if (curISP) {
  684. IspaceIdList.push(curISP.id);
  685. zoneObj.height = this.spaceHeight;
  686. // 2020-12-20 演示用 -start
  687. console.log(curISP);
  688. if (curISP.infos) {
  689. zoneObj.infos = {}
  690. if (curISP.infos.roomLocalFuncTypeID) {
  691. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  692. }
  693. if (curISP.infos.roomLocalFuncTypeName) {
  694. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  695. }
  696. }
  697. // 2020-12-20 演示用 -end
  698. }
  699. })
  700. // 如果有划分,求交集
  701. if (this.scene.cutItem || this.scene.sceneMark) {
  702. zoneObj.outline = [];
  703. let arr = this.scene.getIntersect();
  704. arr.map(t => {
  705. let temp = t.map(item => {
  706. return {
  707. X: 1 * item.x,
  708. Y: -item.y,
  709. Z: 0
  710. }
  711. })
  712. zoneObj.outline.push([temp]);
  713. })
  714. }
  715. }
  716. // 至此
  717. if (!zoneObj.outline.length) {
  718. zoneObj.outline = null;
  719. }
  720. zoneObj.localName = val;
  721. zoneObj.buildingId = this.buildFloor[0];
  722. zoneObj.floorId = this.buildFloor[1];
  723. this.createSingleBSP(zoneObj, IspaceIdList)
  724. },
  725. // 根据图从未关联平面图的业务空间中选择--按钮返回关联信号
  726. createFromUnrelated(zoneObj) {
  727. zoneObj.outline = [];
  728. zoneObj.height = 0;
  729. let spaces = {}, IspaceIdList = [];
  730. try {
  731. if (this.scene.cutItem || this.scene.sceneMark) {
  732. // 如果有划分,求交集
  733. // 格式为Poly(先与业务空间求差集)
  734. const obj = this.scene.getZoneDifference(true);
  735. // 差集与楼层平面图或用户划分区域求交集
  736. spaces = this.scene.getPloyIntersect(obj)
  737. } else {
  738. // 格式为SPoint[]
  739. spaces = this.scene.getZoneDifference();
  740. }
  741. for (let key in spaces) {
  742. spaces[key] = spaces[key].map(t => {
  743. let temp = t.map(item => {
  744. return {
  745. X: 1 * item.x.toFixed(2),
  746. Y: -item.y.toFixed(2),
  747. Z: 0
  748. }
  749. })
  750. return temp;
  751. })
  752. let newarr = this.makeMaxAreaFirst(spaces[key])
  753. zoneObj.outline.push(newarr);
  754. let curISP = this.sourceIdToISP[key];
  755. if (curISP) {
  756. curISP && IspaceIdList.push(curISP.id);
  757. zoneObj.height = this.spaceHeight;
  758. // 2020-12-20 演示用 -start
  759. if (curISP.infos) {
  760. zoneObj.infos = {}
  761. if (curISP.infos.roomLocalFuncTypeID) {
  762. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  763. }
  764. if (curISP.infos.roomLocalFuncTypeName) {
  765. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  766. }
  767. }
  768. // 2020-12-20 演示用 -end
  769. }
  770. }
  771. } catch (err) {
  772. console.log(err);
  773. let selectSpaces = this.scene.getSelectedSpaces();
  774. selectSpaces.map(t => {
  775. zoneObj.outline.push(t.data.outLine);
  776. let key = t.data.sourceId;
  777. let curISP = this.sourceIdToISP[key];
  778. if (curISP) {
  779. curISP && IspaceIdList.push(curISP.id);
  780. zoneObj.height = this.spaceHeight;
  781. // 2020-12-20 演示用 -start
  782. if (curISP.infos) {
  783. zoneObj.infos = {}
  784. if (curISP.infos.roomLocalFuncTypeID) {
  785. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  786. }
  787. if (curISP.infos.roomLocalFuncTypeName) {
  788. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  789. }
  790. }
  791. // 2020-12-20 演示用 -end
  792. }
  793. })
  794. // 如果有划分,求交集
  795. if (this.scene.cutItem || this.scene.sceneMark) {
  796. zoneObj.outline = [];
  797. let arr = this.scene.getIntersect();
  798. arr.map(t => {
  799. let temp = t.map(item => {
  800. return {
  801. X: 1 * item.x,
  802. Y: -item.y,
  803. Z: 0
  804. }
  805. })
  806. zoneObj.outline.push([temp]);
  807. })
  808. }
  809. }
  810. if (!zoneObj.outline.length) {
  811. zoneObj.outline = null;
  812. }
  813. this.updateBSPOutline(zoneObj, IspaceIdList)
  814. },
  815. // 编辑空间详情
  816. editeSpaceDetail() {
  817. let item = this.curZoneItem.data;
  818. let query = {
  819. RoomID: item.RoomID,
  820. zone: this.tab.code,
  821. isMyTab: 1,
  822. buildFloorSelectd: this.buildFloor
  823. }
  824. this.$router.push({
  825. path: "/ledger/spaceDetail",
  826. query: query
  827. })
  828. },
  829. // 重新划分业务空间
  830. refactorBSP() {
  831. this.config.isEdit = true;
  832. this.config.groupSelect = false;
  833. this.config.divide = true;
  834. this.type = 4;
  835. // 设置空间可选
  836. this.scene.isSpaceSelectable = true;
  837. // 将已关联的设置不可选,并将当前选的隐藏
  838. this.scene.isZoneSelectable = false;
  839. this.curZoneItem.visible = false;
  840. // 将当前业务空间的每个元素添加到场景中并选中
  841. this.scene.addAllLikeSpace(this.curZoneItem.data.OutLine);
  842. },
  843. // 确认业务空间
  844. confirmZoneSpace() {
  845. let ObjectType = this.tab.code
  846. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  847. let space = {
  848. id: this.curZoneItem.data.RoomID,
  849. state: 0,
  850. classCode: ObjectType
  851. }
  852. let pa = {
  853. content: [space],
  854. }
  855. zoneUpdate(pa, res => {
  856. this.curZoneItem.isInfected = false;
  857. this.$emit('updateState');
  858. this.$message.success('更新成功');
  859. })
  860. },
  861. // 保存并确认业务空间
  862. confirmAndSave() {
  863. this.confirmAndSaveFlag = true;
  864. this.saveRefactorBSP();
  865. },
  866. // 重新划分--保存
  867. saveRefactorBSP() {
  868. let selectSpace = this.scene.getSelectedSpaces();
  869. let selectLikeSpace = this.scene.getSelectedLikeSpace();
  870. //更新业务空间
  871. let zoneObj = { outline: [], height: 0, state: this.confirmAndSaveFlag ? 0 : this.curZoneItem.isInfected ? 1 : 0 }, IspaceIdList = [];
  872. // 空间
  873. selectSpace.map(t => {
  874. zoneObj.outline.push(t.data.OutLine);
  875. if (this.BIMIDToSID[t.data.SourceId]) {
  876. IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
  877. }
  878. // 2020-12-20 演示用 -start
  879. if (this.sourceIdToISP[t.data.sourceId] && this.sourceIdToISP[t.data.sourceId].infos) {
  880. zoneObj.infos = {};
  881. if (this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID) {
  882. zoneObj.infos.roomLocalFuncTypeID = this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID
  883. }
  884. if (this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName) {
  885. zoneObj.infos.roomLocalFuncTypeName = this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName
  886. }
  887. }
  888. // 2020-12-20 演示用 -end
  889. zoneObj.height = this.spaceHeight
  890. })
  891. // 类空间
  892. selectLikeSpace.map(t => {
  893. zoneObj.outline.push(t.data);
  894. })
  895. // 如果有划分,求交集
  896. if (this.scene.cutItem || this.scene.sceneMark) {
  897. zoneObj.outline = [];
  898. let spaceIntersect = this.scene.getIntersect();
  899. spaceIntersect.map(t => {
  900. let temp = t.map(item => {
  901. return {
  902. X: item.x,
  903. Y: -item.y,
  904. Z: 0
  905. }
  906. })
  907. zoneObj.outline.push([temp]);
  908. })
  909. let likeSpaceIntersect = this.scene.getLikeIntersect();
  910. likeSpaceIntersect.map(t => {
  911. let temp = t.map(item => {
  912. return {
  913. X: item.x,
  914. Y: -item.y,
  915. Z: 0
  916. }
  917. })
  918. zoneObj.outline.push([temp]);
  919. })
  920. }
  921. if (!zoneObj.outline.length) {
  922. zoneObj.outline = null;
  923. }
  924. zoneObj.id = this.curZoneItem.data.RoomID;
  925. this.updateBSPOutline(zoneObj, IspaceIdList)
  926. },
  927. // 根据图批量创建所选业务空间
  928. groupCreateZone() {
  929. let arr = this.scene.getSelectedSpaces();
  930. let createSpaces = [], spaces = {};
  931. try {
  932. if (this.scene.cutItem || this.scene.sceneMark) {
  933. // 如果有划分,求交集
  934. // 格式为Poly(先与业务空间求差集)
  935. const obj = this.scene.getZoneDifference(true);
  936. // 差集与楼层平面图或用户划分区域求交集
  937. spaces = this.scene.getPloyIntersect(obj)
  938. } else {
  939. // 格式为SPoint[]
  940. spaces = this.scene.getZoneDifference();
  941. }
  942. for (let key in spaces) {
  943. let zoneObj = { outline: [], height: 0 }
  944. spaces[key] = spaces[key].map(t => {
  945. let temp = t.map(item => {
  946. return {
  947. X: 1 * item.x.toFixed(2),
  948. Y: -item.y.toFixed(2),
  949. Z: 0
  950. }
  951. })
  952. return temp;
  953. })
  954. let newarr = this.makeMaxAreaFirst(spaces[key])
  955. zoneObj.outline.push(newarr);
  956. if (!zoneObj.outline.length) {
  957. continue
  958. }
  959. //计算面积
  960. let area = 0, line = zoneObj.outline;
  961. for (let i = 0; i < line.length; i++) {
  962. for (let j = 0; j < line[i].length; j++) {
  963. if (j == 0) {
  964. area += this.getarea(line[i][0]);
  965. } else {
  966. area -= this.getarea(line[i][j]);
  967. }
  968. }
  969. }
  970. area = (area / 1000000).toFixed(2);
  971. if (area < (this.areaValue / 100)) {
  972. continue
  973. }
  974. //生成空间对象
  975. let curISP = this.sourceIdToISP[key];
  976. if (curISP) {
  977. zoneObj.height = this.spaceHeight;
  978. // zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
  979. zoneObj.ispaceId = curISP.id;
  980. zoneObj.localName = curISP.localName || '';
  981. // 2020-12-20 演示用 -start
  982. if (curISP.infos) {
  983. zoneObj.infos = {}
  984. if (curISP.infos.roomLocalFuncTypeID) {
  985. zoneObj.infos.roomLocalFuncTypeID = curISP.infos.roomLocalFuncTypeID
  986. }
  987. if (curISP.infos.roomLocalFuncTypeName) {
  988. zoneObj.infos.roomLocalFuncTypeName = curISP.infos.roomLocalFuncTypeName
  989. }
  990. }
  991. // 2020-12-20 演示用 -end
  992. }
  993. zoneObj.buildingId = this.buildFloor[0];
  994. zoneObj.floorId = this.buildFloor[1];
  995. createSpaces.push(zoneObj);
  996. }
  997. } catch (err) {
  998. console.log(err)
  999. let createSpaces = [];
  1000. // 如果有划分,求交集
  1001. if (this.scene.cutItem || this.scene.sceneMark) {
  1002. let outlines = this.scene.getIntersectInSpace();
  1003. for (let k in outlines) {
  1004. outlines[k] = outlines[k].map(t => {
  1005. t = t.map(item => {
  1006. item = item.map(j => {
  1007. return { X: j.x, Y: -j.y, Z: 0 }
  1008. })
  1009. return item
  1010. })
  1011. return t;
  1012. })
  1013. }
  1014. createSpaces = arr.map(t => {
  1015. let line = outlines[t.data.SourceId];
  1016. if (!line || !line.length) {
  1017. return undefined
  1018. } else {
  1019. let area = 0;
  1020. for (let i = 0; i < line.length; i++) {
  1021. for (let j = 0; j < line[i].length; j++) {
  1022. if (j == 0) {
  1023. area += this.getarea(line[i][0]);
  1024. } else {
  1025. area -= this.getarea(line[i][j]);
  1026. }
  1027. }
  1028. }
  1029. area = (area / 1000000).toFixed(2);
  1030. if (area < (this.areaValue / 100)) {
  1031. return undefined;
  1032. }
  1033. }
  1034. return {
  1035. ispaceId: this.BIMIDToSID[t.data.sourceId],
  1036. localName: this.BIMIDToSIName[t.data.sourceId] || '',
  1037. outline: line,
  1038. buildingId: this.buildFloor[0],
  1039. floorId: this.buildFloor[1],
  1040. height: this.spaceHeight,
  1041. // 2020-12-20 演示用 -start
  1042. infos: {
  1043. roomLocalFuncTypeID: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID || '' : '',
  1044. roomLocalFuncTypeName: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName || '' : ''
  1045. }
  1046. // 2020-12-20 演示用 -end
  1047. }
  1048. }).filter(item => item)
  1049. } else {
  1050. createSpaces = arr.map(t => {
  1051. let line = t.data.outLine;
  1052. if (!line || !line.length) {
  1053. return undefined
  1054. } else {
  1055. let area = this.getarea(line[0]);
  1056. if (line.length > 1) {
  1057. for (let i = 1; i < line.length; i++) {
  1058. area -= this.getarea(line[i]);
  1059. }
  1060. }
  1061. area = (area / 1000000).toFixed(2);
  1062. if (area < (this.areaValue / 100)) {
  1063. return undefined;
  1064. }
  1065. }
  1066. return {
  1067. ispaceId: this.BIMIDToSID[t.data.sourceId],
  1068. localName: this.BIMIDToSIName[t.data.sourceId] || '',
  1069. outline: [line],
  1070. buildingId: this.buildFloor[0],
  1071. floorId: this.buildFloor[1],
  1072. height: this.spaceHeight,
  1073. // 2020-12-20 演示用 -start
  1074. infos: {
  1075. roomLocalFuncTypeID: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeID || '' : '',
  1076. roomLocalFuncTypeName: this.sourceIdToISP[t.data.sourceId].infos ? this.sourceIdToISP[t.data.sourceId].infos.roomLocalFuncTypeName || '' : ''
  1077. }
  1078. // 2020-12-20 演示用 -end
  1079. }
  1080. }).filter(item => item);
  1081. }
  1082. }
  1083. if (createSpaces.length) {
  1084. this.canvasLoading = true;
  1085. this.groupCreateBSP(createSpaces)
  1086. } else {
  1087. this.$message.warning('未选择空间');
  1088. }
  1089. },
  1090. // 更新业务空间和元空间的关系
  1091. relationInBSPandISP(SpaceId, IspaceIdList) {
  1092. let ObjectType = this.tab.code;
  1093. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1094. let pa = {
  1095. data: { spaceId: SpaceId, ispaceIdList: IspaceIdList },
  1096. type: ObjectType
  1097. }
  1098. createRelateInZoneAndISp(pa, res => {
  1099. this.$message.success('创建成功');
  1100. this.init(2);
  1101. if (this.confirmAndSaveFlag) {
  1102. this.confirmAndSaveFlag = false;
  1103. this.curZoneItem.selected = false;
  1104. this.curZoneItem = {};
  1105. this.$emit('updateState');
  1106. }
  1107. })
  1108. },
  1109. // 批量更新业务空间和元空间的关系
  1110. groupCreRelaZoneAndISp(Spaces) {
  1111. Spaces = Spaces.filter(item => item.ispaceId);
  1112. let ObjectType = this.tab.code;
  1113. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1114. if (Spaces.length) {
  1115. let param = {
  1116. data: {
  1117. content: Spaces
  1118. },
  1119. type: ObjectType
  1120. }
  1121. groupCreRelaZoneAndISp(param, res => {
  1122. this.$message.success('创建成功')
  1123. this.canvasLoading = false;
  1124. this.init(2)
  1125. })
  1126. } else {
  1127. this.$message.success('创建成功')
  1128. this.canvasLoading = false;
  1129. this.init(2)
  1130. }
  1131. },
  1132. // 批量创建
  1133. groupCreateBSP(spaces) {
  1134. let ObjectType = this.tab.code;
  1135. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1136. spaces = spaces.map(t => {
  1137. t.classCode = ObjectType;
  1138. t.bimLocation = this.getAverageVal(t.outline);
  1139. return t;
  1140. })
  1141. let pa = {
  1142. content: spaces,
  1143. }
  1144. zoneCreate(pa, res => {
  1145. res.entityList.map(t => {
  1146. spaces = spaces.map(item => {
  1147. if (t.localName == item.localName) {
  1148. item.spaceId = t.id
  1149. }
  1150. return item;
  1151. })
  1152. })
  1153. this.groupCreRelaZoneAndISp(spaces)
  1154. })
  1155. },
  1156. // 单个创建
  1157. createSingleBSP(space, IspaceIdList) {
  1158. let ObjectType = this.tab.code;
  1159. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1160. space.bimLocation = space.outline ? this.getAverageVal(space.outline) : null;
  1161. space.classCode = ObjectType;
  1162. let pa = {
  1163. content: [space]
  1164. }
  1165. zoneCreate(pa, res => {
  1166. this.relationInBSPandISP(res.entityList[0].id, IspaceIdList)
  1167. })
  1168. },
  1169. // 更新业务空间区域
  1170. updateBSPOutline(zoneObj, IspaceIdList) {
  1171. let ObjectType = this.tab.code;
  1172. // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
  1173. zoneObj.bimLocation = zoneObj.outline ? this.getAverageVal(zoneObj.outline) : null;
  1174. zoneObj.classCode = ObjectType;
  1175. zoneObj.buildingId = this.buildFloor[0];
  1176. zoneObj.floorId = this.buildFloor[1];
  1177. let pa = {
  1178. content: [zoneObj],
  1179. }
  1180. if (!zoneObj.outline) {
  1181. pa.nullItems = ['outline']
  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>