graphy.vue 44 KB

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