12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712 |
- <template>
- <div id="graphy" ref="graphy" v-loading="canvasLoading">
- <!-- <div v-show="!FloorMap">
- <div
- class="center"
- style="height: 400px; padding-top: 182px; box-sizing: border-box;text-align: center; margin: 0 auto;"
- >
- <i class="icon-wushuju iconfont"></i>
- 请选择建筑楼层
- </div>
- </div> -->
- <div
- class="middle_sty"
- style="height: 91%; text-align: center"
- v-show="!FloorMap"
- >
- <p>
- <i class="icon-wushuju iconfont"></i>
- 请选择建筑楼层
- </p>
- </div>
- <div class="canvas-box" v-show="FloorMap">
- <canvas
- id="floorCanvas"
- :width="canvasWidth"
- :height="canvasHeight"
- ref="canvas"
- tabindex="0"
- ></canvas>
- <!-- 初始两个按钮 -->
- <el-row class="buttons-box">
- <!-- 平面图其他分区 -->
- <!-- <div style="margin-right:10px;width: 100%;margin-bottom: 10px" v-if="showOtherFlag">
- <el-button type="primary" @click="addZoneBtn">添加分区</el-button>
- <el-select v-model="OtherValue" placeholder="请选择分区类型" @change="changeOtherZone">
- <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
- </el-option>
- </el-select>
- </div> -->
- <div>
- <el-autocomplete
- popper-class="my-autocomplete"
- v-model="search"
- :fetch-suggestions="querySearch"
- placeholder="输入平面图中已有的业务空间名称进行查找"
- width="180px"
- @select="handleSelect"
- >
- <i class="el-icon-search el-input__icon" slot="suffix"></i>
- <template slot-scope="{ item }">
- <div
- class="name"
- style="
- position: relative;
- padding-right: 40px;
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
- "
- :title="item.data.RoomLocalName"
- >
- {{ item.data.RoomLocalName }}
- <span
- class="addr"
- style="position: absolute; right: 0; color: #409eff"
- >定位</span
- >
- </div>
- </template>
- </el-autocomplete>
- </div>
- <div class="button-group">
- <!-- 默认操作模式 -->
- <div v-show="type == 1">
- <el-dropdown
- split-button
- type="primary"
- @click="editGraphy"
- @command="handleCommand"
- >
- 创建业务空间
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item command="groupCreateBSpace"
- >批量创建业务空间</el-dropdown-item
- >
- </el-dropdown-menu>
- </el-dropdown>
- <!-- 点击已经关联的业务空间 -->
- <el-button
- type="primary"
- plain
- @click="refactorBSP"
- :disabled="zoneDisable"
- style="margin-left: 10px"
- >重新划分业务空间</el-button
- >
- <el-button
- type="primary"
- @click="editeSpaceDetail"
- :disabled="zoneDisable"
- >查看空间详情</el-button
- >
- <el-button
- type="danger"
- plain
- @click="deleteZone"
- :disabled="zoneDisable"
- >删除</el-button
- >
- <el-button
- type="primary"
- plain
- @click="confirmZoneSpace"
- :disabled="
- zoneDisable || (!zoneDisable && !curZoneItem.isInfected)
- "
- >确认业务空间
- </el-button>
- <el-button plain @click="cancelGraphy" v-show="!zoneDisable"
- >取 消</el-button
- >
- </div>
- <!-- 点击已经关联的业务空间 -->
- <!-- <div v-show="type==2">
- </div> -->
- <!-- 点击未关联的业务空间 -->
- <div v-show="type == 3">
- <el-button plain @click="createNewZone"
- >创建单个全新的业务空间</el-button
- >
- <el-button plain @click="lookUnrelatBSpace(true)"
- >从未关联平面图的业务空间中选择</el-button
- >
- <el-button plain @click="cancelGraphy">取 消</el-button>
- </div>
- <!-- 重新划分业务空间 -->
- <div v-show="type == 4">
- <el-button plain @click="cancelGraphy">取 消</el-button>
- <el-button type="primary" @click="saveRefactorBSP">保存</el-button>
- <el-button
- type="primary"
- v-show="curZoneItem.isInfected"
- @click="confirmAndSave"
- >保存并确认业务空间</el-button
- >
- </div>
- <!-- 批量创建所选业务空间 -->
- <div v-if="type == 5">
- <el-button type="primary" @click.prevent.once="groupCreateZone"
- >批量创建所选业务空间</el-button
- >
- <el-button plain @click="cancelGraphy">取 消</el-button>
- </div>
- <div style="position: absolute; right: 10px">
- <el-button type="text" @click="lookUnrelatBSpace(false)"
- >未关联平面图的业务空间 {{ num }} 条</el-button
- >
- </div>
- </div>
- </el-row>
- <!-- 底部操作按钮 -->
- <el-row class="canvas-actions-box">
- <canvasFun
- @fit="fit"
- @savePng="savePng"
- @saveSvg="saveSvg"
- @divide="divide"
- @clearDivide="clearDivide"
- @undo="undo"
- @redo="redo"
- @changeAbsorb="changeAbsorb"
- @scale="scale"
- @groupSelect="groupSelect"
- :config="config"
- ref="canvasFun"
- @saveJson="saveJson"
- ></canvasFun>
- </el-row>
- </div>
- <!-- -->
- <!-- 未关联元空间的业务空间 -->
- <unRelateBSP
- ref="unRelateBSP"
- :isAction="isAction"
- @createFromUnrelated="createFromUnrelated"
- :code="tab.code"
- ></unRelateBSP>
- <!-- 创建新的业务空间 -->
- <createBSP ref="createBSP" @createRoom="createRoom"></createBSP>
- <!-- 批量创建选择弹窗 -->
- <el-dialog
- title="提示"
- :visible.sync="groupCreateDialogVis"
- width="30%"
- :close-on-click-modal="false"
- >
- <div id="autoRelate">
- <p>批量创建面积大于此值的默认空间为业务空间:</p>
- <div style="padding: 10px 20px; margin: 0 0 10px 0">
- <el-slider
- v-model="areaValue"
- :marks="areaMarks"
- :step="10"
- :format-tooltip="(val) => val / 100"
- >
- </el-slider>
- </div>
- <p>请选择批量创建方式:</p>
- <p>
- <el-radio v-model="groupCreateType" :label="1"
- >批量将所有的空白空间创建业务空间</el-radio
- >
- </p>
- <p>
- <el-radio v-model="groupCreateType" :label="2"
- >批量选择空白空间创建业务空间</el-radio
- >
- </p>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button size="small" @click="groupCreateDialogVis = false"
- >取消</el-button
- >
- <el-button size="small" type="primary" @click="confirm">确认</el-button>
- </span>
- </el-dialog>
- <!-- <dialogZone ref="zone" @createSuccess="getOtherType" /> -->
- </div>
- </template>
- <script>
- import canvasFun from "./canvasFun";
- import { mapGetters } from "vuex";
- import { SColor, SPoint } from "@saga-web/draw/lib";
- import {
- DivideFloorScene,
- FloorView,
- Opt,
- SpaceItem,
- ZoneItem,
- } from "@saga-web/cad-engine/lib";
- import { colorArr } from "@/utils/old-adm/spaceColor";
- import unRelateBSP from "./unRelateBSP";
- import createBSP from "./createBSP";
- import logicConfig from "@/logicConfig";
- import { businessSpaceController } from "@/controller/old-adm/businessSpaceController";
- import ScanController from "@/controller/old-adm/ScanController";
- export default {
- components: {
- canvasFun,
- unRelateBSP,
- createBSP,
- // dialogZone
- },
- data() {
- return {
- canvasWidth: 800,
- canvasHeight: 600,
- type: 1, // 默认操作模式
- search: "", //搜索
- buildFloor: ["", ""],
- FloorObj: {}, //楼层对象
- FloorMap: "", //楼层底图
- tab: {},
- config: {
- isEdit: false,
- divide: true,
- groupSelect: true,
- },
- canvasLoading: false,
- view: null,
- scene: null,
- Outline: [], // 当前选中的多个空间组成的轮廓线->三维数组
- businessSpaceList: [], // 所有业务空间
- num: 0, // 未关联元空间的业务空间统计
- BSPRelaISPList: [], // 已关联元空间的业务空间
- // 未关联元空间的业务空间弹窗
- isAction: false,
- curOutline: [],
- BIMIDToSID: {}, //bimid映射元空间id
- BIMIDToSIName: {}, //bimid映射元空间名称
- curZoneItem: {}, //当前选中的业务空间item
- allUnRelatISP: [], //
- zoneList: [], // 业务空间-canvas图中
- groupCreateDialogVis: false, //批量创建业务空间弹窗
- groupCreateType: 1, //批量创建方式
- zoneDisable: true, // 重新划分是否禁用
- sourceIdToISP: {},
- areaValue: 40,
- areaMarks: { 0: "0m²", 100: "1m²" },
- options: [], //其他分区类型
- OtherValue: "",
- showOtherFlag: false, //是否显示其他分区类型添加
- buildFloorName: "", //建筑楼层名称
- spaceHeight: 0,
- isFirstIn: true, // 是否为第一次进入
- tempZoneList: [], // 平面图上所有业务空间
- };
- },
- computed: {
- ...mapGetters("layout", ["projectId", "projects"]),
- projectName() {
- let projectObj = this.projects.find((item) => {
- return item.id == this.projectId;
- });
- return projectObj
- ? projectObj.name
- ? projectObj.name
- : projectObj.id
- : this.projectId;
- },
- },
- created() {
- Opt.sceneMarkColor = new SColor("#ffffff");
- },
- mounted() {
- this.canvasWidth = this.$refs.graphy.offsetWidth - 20;
- this.canvasHeight = this.$refs.graphy.offsetHeight - 20;
- },
- methods: {
- // 初始化
- init(initType) {
- this.type = 1;
- if (this.scene) {
- this.scene.clearSpaceSelection();
- this.scene.clearZoneSelection();
- this.scene.clearCut();
- this.scene.clearLikeSpaces();
- this.zoneDisable = true;
- this.scene.isZoneSelectable = true;
- this.scene.isSpaceSelectable = false;
- }
- if (
- this.buildFloor.indexOf("all") > -1 ||
- this.buildFloor.indexOf("noKnow") > -1
- ) {
- return;
- }
- if (initType == 1) {
- // 底图
- this.getGraphy();
- } else {
- // 业务空间
- this.getBusinessSpace();
- }
- this.config = {
- isEdit: false,
- divide: true,
- groupSelect: true,
- };
- // 获取当前楼层的元空间
- this.getFloorISpace();
- // 查询未关联业务空间的元空间
- this.getISPSPUnrelaBSP();
- // 查询未关联平面图的业务空间
- this.getBSPunrelaISP();
- },
- // 获取当前楼层的元空间-元空间接口不变
- getFloorISpace() {
- let pa = {
- zone: "Ispace",
- data: {
- // Filters: `FloorId='${this.buildFloor[1]}'`,
- pageSize: 2000,
- floorId: this.buildFloor[1],
- },
- };
- ScanController.queryZone(pa, (res) => {
- if (res.message == this.buildFloor[1]) {
- this.BIMIDToSID = {};
- this.BIMIDToSIName = {};
- this.sourceIdToISP = {};
- res.content.map((t) => {
- let key = t.bimId.split(":")[1];
- this.BIMIDToSID[key] = t.id;
- this.BIMIDToSIName[key] = t.localName || t.name;
- this.sourceIdToISP[key] = t;
- });
- }
- });
- },
- //添加其他分区
- addZoneBtn() {
- this.$refs.zone.dialogFormVisible = true;
- },
- // 搜索
- querySearch(queryString, cb) {
- let restaurants = this.zoneList;
- let results = queryString
- ? restaurants.filter(this.createFilter(queryString))
- : restaurants;
- // 调用 callback 返回建议列表的数据
- cb(results);
- },
- // 过滤器
- createFilter(queryString) {
- return (restaurant) => {
- return restaurant.data.RoomLocalName.indexOf(queryString) > -1;
- };
- },
- // 查询选中,定位
- handleSelect(zone) {
- // 清空选中
- this.scene.clearSpaceSelection();
- this.scene.clearZoneSelection();
- // 选中当前
- zone.selected = true;
- this.curZoneItem = zone;
- this.zoneDisable = false;
- this.view.fitSelectedToView(0.1);
- },
- // 父组件调用
- getData(buildFloor, FloorObj, tab) {
- let initType = 1;
- if (FloorObj.id == this.FloorObj.id) {
- initType = 2;
- }
- this.buildFloor = buildFloor;
- this.FloorObj = FloorObj;
- this.FloorMap = FloorObj.infos ? FloorObj.infos.floorMap : "";
- this.tab = tab;
- this.buildFloorName = `${FloorObj.buildName}-${FloorObj.label}`;
- console.log(arguments);
- if (tab.code == "OtherZone") {
- // 其他分区
- this.showOtherFlag = true;
- // this.getOtherType();
- // this.OtherValue = (localStorage.getItem('otherZone')) || ''
- } else {
- this.showOtherFlag = false;
- }
- this.init(initType);
- },
- // 其他分区类型查询
- // getOtherType() {
- // let pa = {
- // Cascade: [{ Filters: `ProjectId='${this.projectId}'` }],
- // Filters: `Code="OtherZone"`
- // }
- // queryAllZoneType(pa, res => {
- // if (res.content[0].zoneType && res.content[0].zoneType.length) {
- // this.options = res.content[0].zoneType.map(t => {
- // t.value = t.code;
- // t.label = t.name;
- // return t;
- // })
- // } else {
- // this.options = []
- // }
- // })
- // },
- // 其他类型下拉change
- changeOtherZone(val) {
- this.init(2);
- },
- // 获取未绑定业务空间的元空间
- getISPSPUnrelaBSP() {
- let pa = {
- data: {
- pageSize: 1000,
- floorId: this.buildFloor[1],
- },
- objectType: this.tab.code,
- // objectType: this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code
- };
- businessSpaceController.getIspNotInSpace(pa, (res) => {
- // 类型需要重新获取,直接取pa.objecttype有问题
- let tempType = this.tab.code;
- // let tempType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code
- if (res.floorId == this.buildFloor[1] && res.zoneType == tempType) {
- this.allUnRelatISP = res.content;
- }
- });
- },
- // 获取底图
- getGraphy() {
- let that = this;
- that.clearGraphy();
- if (!this.FloorMap) {
- return;
- }
- that.scene = new DivideFloorScene();
- that.canvasLoading = true;
- const temp = this.FloorMap.split(".")[1];
- if (
- temp &&
- (temp.toLowerCase() == "png" || temp.toLowerCase() == "jpg")
- ) {
- that.scene.loadImg(
- `/image-service/common/image_get?systemId=dataPlatform&key=${this.FloorMap}`,
- (res) => {
- this.getGraphtSuc(res);
- }
- );
- } else {
- that.scene
- .loadUrl(
- `/image-service/common/file_get?systemId=revit&key=${this.FloorMap}`
- )
- .then((res) => {
- this.getGraphtSuc(res);
- });
- }
- },
- getGraphtSuc(res) {
- let that = this;
- that.canvasLoading = false;
- if (res == "error") {
- this.FloorMap = "";
- console.log("数据解析异常");
- return;
- }
- that.view.scene = that.scene;
- // 蒙版
- if (this.FloorObj.outline) {
- let newArr = this.FloorObj.outline.map((t) => {
- return new SPoint(t.X, t.Y);
- });
- this.scene.addSceneMark(newArr);
- }
- this.scene.isSpaceSelectable = false;
- // 绘制业务空间
- that.getBusinessSpace();
- that.fit();
- that.view.minScale = that.view.scale;
- if (that.$refs.canvasFun) {
- that.$refs.canvasFun.everyScale = that.view.scale;
- }
- },
- // 获取当前分区下的业务空间
- getBusinessSpace(pageNumber = 1) {
- this.canvasLoading = true;
- // 其他分区 已删除在其他分区下添加子分区
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- let ObjectType = this.tab.code;
- let pa = {
- // cascader: [{name: 'spaceOutline'}],
- zoneType: ObjectType,
- filters: `not id isNull`,
- orders: "createTime desc, id asc",
- pageSize: 10000,
- pageNumber: pageNumber,
- };
- if (this.buildFloor.length && this.buildFloor.length > 1) {
- pa.BuildingId = this.buildFloor[0];
- pa.FloorId = this.buildFloor[1];
- }
- // zoneQuery
- // zoneQueryOutline
- ScanController.zoneQueryOutline(pa, (res) => {
- if (res.total > res.pageNumber * res.pageSize) {
- const pn = res.pageNumber + 1;
- this.tempZoneList = this.tempZoneList.concat(res.content);
- this.getBusinessSpace(pn);
- } else {
- res.content = res.content.concat(this.tempZoneList);
- this.getBusSpaceSuc(res);
- this.tempZoneList = [];
- }
- });
- },
- getBusSpaceSuc(res) {
- console.log(res, "all");
- // 类型需要重新获取,直接取pa.ZoneType
- // 其他分区已删除 在其他分区下添加子分区
- // let tempType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- let tempType = this.tab.code;
- if (res.floorId == this.buildFloor[1] && res.zoneType == tempType) {
- // 所有业务空间
- this.businessSpaceList = res.content;
- // 已关联元空间的业务空间
- this.BSPRelaISPList = [];
- res.content.map((t) => {
- if (t.outline && t.outline.length) {
- this.BSPRelaISPList.push(t);
- }
- });
- // 绘制业务空间
- let tempArr = this.BSPRelaISPList.map((t, i) => {
- return {
- RoomLocalName: t.localName || t.name,
- OutLine: t.outline,
- RoomID: t.id,
- Color: colorArr[i % colorArr.length],
- Infected: t.state,
- };
- }).filter((item) => item);
- try {
- this.scene.removeAllZone();
- this.scene.addZoneList(tempArr);
- this.scene.click(this, this.canvasClick);
- this.zoneList = this.scene.zoneList;
- this.view._needDraw = true;
- if (this.isFirstIn) {
- this.fit();
- this.isFirstIn = false;
- }
- } catch (err) {
- console.log(err, "------------");
- console.log(this);
- }
- this.canvasLoading = false;
- }
- },
- // canvas点击事件
- canvasClick(item, event) {
- console.log(item);
- console.log(event);
- if (this.type == 4) {
- //重新划分
- } else if (this.type == 5) {
- //批量
- } else {
- if (item instanceof SpaceItem && item.selectable) {
- if (this.spaceHeight == 0) {
- this.spaceHeight =
- item.data.Height > 1000
- ? item.data.Height / 1000
- : item.data.Height;
- }
- if (this.type == 2) {
- this.scene.clearZoneSelection();
- }
- this.type = 3;
- this.curZoneItem = {};
- }
- if (item instanceof ZoneItem && item.selectable) {
- if (this.type == 3) {
- this.scene.clearSpaceSelection();
- }
- this.zoneDisable = false;
- this.curZoneItem = item;
- this.scene.clearZoneSelection();
- item.selected = true;
- this.$emit("copyID", this.curZoneItem.data.RoomID);
- }
- }
- },
- // 编辑平面图
- editGraphy() {
- this.type = 3;
- this.config.isEdit = true;
- this.config.groupSelect = false;
- this.config.divide = true;
- this.scene.isSpaceSelectable = true;
- // 设置业务空间不可选
- this.scene.isZoneSelectable = false;
- this.view._needDraw = true;
- },
- // 查看未关联的业务空间--flag--查看-or-选择
- lookUnrelatBSpace(flag) {
- this.isAction = flag;
- let arr = this.scene.getSelectedSpaces();
- if (flag && !arr.length) {
- this.$message.warning("请至少选择一个空间");
- return;
- }
- // this.$refs.unRelateBSP.showDialog(this.buildFloor);
- this.$refs.unRelateBSP.showDialog();
- },
- // 取消(所有取消公用)
- cancelGraphy() {
- this.init(2);
- this.$emit("copyID", "");
- },
- // 批量创建业务空间弹窗
- handleCommand(command) {
- this.groupCreateDialogVis = true;
- },
- // 创建弹窗确认
- confirm() {
- if (this.groupCreateType == 1) {
- this.groupCreateBSpace();
- } else if (this.groupCreateType == 2) {
- this.type = 5;
- this.config.isEdit = true;
- this.config.groupSelect = true;
- this.config.divide = false;
- this.groupCreateDialogVis = false;
- // 清空选中空间
- this.scene.clearSpaceSelection();
- // 设置空间可选
- this.scene.isSpaceSelectable = true;
- // 设置业务空间不可选
- this.scene.isZoneSelectable = false;
- // 刷新
- this.view.update();
- }
- },
- // 根据未关联元空间批量创建业务空间
- groupCreateBSpace() {
- let text = [];
- let Spaces = this.allUnRelatISP
- .map((t) => {
- if (t.outline) {
- let area = 0;
- if (t.outline[0]) {
- area = this.getarea(t.outline[0]);
- if (t.outline.length > 1) {
- for (let i = 1; i < t.outline.length; i++) {
- let temp = this.getarea(t.outline[i]);
- area = area - temp;
- }
- }
- area = (area / 1000000).toFixed(2);
- if (area < this.areaValue / 100) {
- return undefined;
- }
- } else {
- return undefined;
- }
- text.push(t.localName || t.name);
- let obj = {
- ispaceId: t.id,
- localName: t.localName || t.name,
- outline: [t.outline],
- buildingId: this.buildFloor[0],
- floorId: this.buildFloor[1],
- height: this.spaceHeight,
- };
- if (t.customParam) {
- obj.customParam = t.customParam;
- }
- // 2020-12-20 演示用 -start
- if (t.infos) {
- obj.infos = {};
- if (t.infos.roomLocalFuncTypeID) {
- obj.infos.roomLocalFuncTypeID = t.infos.roomLocalFuncTypeID;
- }
- if (t.infos.roomLocalFuncTypeName) {
- obj.infos.roomLocalFuncTypeName = t.infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- return obj;
- } else {
- return undefined;
- }
- })
- .filter((item) => item);
- if (Spaces.length) {
- this.$confirm(
- "<p>确定根据未关联业务空间的空间批量创建业务空间</p>" +
- "<p>涉及的空间:</p>" +
- "<p style='line-height:20px;max-height:60px;overflow-y:auto;'>" +
- text.toString() +
- "</p>",
- "提示",
- {
- dangerouslyUseHTMLString: true,
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning",
- }
- )
- .then(() => {
- this.groupCreateDialogVis = false;
- this.canvasLoading = true;
- this.groupCreateBSP(Spaces);
- })
- .catch(() => {
- this.$message({
- type: "info",
- message: "已取消批量创建",
- });
- });
- } else {
- this.$message("没有未关联的空间");
- }
- },
- // 创建新的业务空间
- createNewZone() {
- let arr = this.scene.getSelectedSpaces();
- if (arr.length) {
- let tempArr = [];
- arr.map((t) => {
- if (this.BIMIDToSIName[t.data.SourceId]) {
- tempArr.push(this.BIMIDToSIName[t.data.SourceId]);
- }
- });
- this.$refs.createBSP.showDialog(tempArr.toString());
- } else {
- this.$message.warning("请至少选择一个空间");
- }
- },
- // 根据图创建新的业务空间-弹窗返回确认创建
- createRoom(val) {
- const zoneObj = { outline: [], height: 0 },
- IspaceIdList = [];
- let spaces = {};
- try {
- if (this.scene.cutItem || this.scene.sceneMark) {
- // 如果有划分,求交集
- // 格式为Poly(先与业务空间求差集)
- const obj = this.scene.getZoneDifference(true);
- // 差集与楼层平面图或用户划分区域求交集
- spaces = this.scene.getPloyIntersect(obj);
- } else {
- // 格式为SPoint[]
- spaces = this.scene.getZoneDifference();
- }
- for (let key in spaces) {
- spaces[key] = spaces[key].map((t) => {
- let temp = t.map((item) => {
- return {
- X: 1 * item.x.toFixed(2),
- Y: -item.y.toFixed(2),
- Z: 0,
- };
- });
- return temp;
- });
- let newarr = this.makeMaxAreaFirst(spaces[key]);
- zoneObj.outline.push(newarr);
- let curISP = this.sourceIdToISP[key];
- if (curISP) {
- curISP && IspaceIdList.push(curISP.id);
- zoneObj.height = this.spaceHeight;
- // 2020-12-20 演示用 -start
- console.log(curISP);
- if (curISP.infos) {
- zoneObj.infos = {};
- if (curISP.infos.roomLocalFuncTypeID) {
- zoneObj.infos.roomLocalFuncTypeID =
- curISP.infos.roomLocalFuncTypeID;
- }
- if (curISP.infos.roomLocalFuncTypeName) {
- zoneObj.infos.roomLocalFuncTypeName =
- curISP.infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- }
- }
- } catch (err) {
- console.log(err);
- let selectSpaces = this.scene.getSelectedSpaces();
- selectSpaces.map((t) => {
- zoneObj.outline.push(t.data.OutLine);
- let key = t.data.SourceId;
- let curISP = this.sourceIdToISP[key];
- if (curISP) {
- IspaceIdList.push(curISP.id);
- zoneObj.height = this.spaceHeight;
- // 2020-12-20 演示用 -start
- console.log(curISP);
- if (curISP.infos) {
- zoneObj.infos = {};
- if (curISP.infos.roomLocalFuncTypeID) {
- zoneObj.infos.roomLocalFuncTypeID =
- curISP.infos.roomLocalFuncTypeID;
- }
- if (curISP.infos.roomLocalFuncTypeName) {
- zoneObj.infos.roomLocalFuncTypeName =
- curISP.infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- }
- });
- // 如果有划分,求交集
- if (this.scene.cutItem || this.scene.sceneMark) {
- zoneObj.outline = [];
- let arr = this.scene.getIntersect();
- arr.map((t) => {
- let temp = t.map((item) => {
- return {
- X: 1 * item.x,
- Y: -item.y,
- Z: 0,
- };
- });
- zoneObj.outline.push([temp]);
- });
- }
- }
- // 至此
- if (!zoneObj.outline.length) {
- zoneObj.outline = null;
- }
- zoneObj.localName = val;
- zoneObj.buildingId = this.buildFloor[0];
- zoneObj.floorId = this.buildFloor[1];
- this.createSingleBSP(zoneObj, IspaceIdList);
- },
- // 根据图从未关联平面图的业务空间中选择--按钮返回关联信号
- createFromUnrelated(zoneObj) {
- zoneObj.outline = [];
- zoneObj.height = 0;
- let spaces = {},
- IspaceIdList = [];
- try {
- if (this.scene.cutItem || this.scene.sceneMark) {
- // 如果有划分,求交集
- // 格式为Poly(先与业务空间求差集)
- const obj = this.scene.getZoneDifference(true);
- // 差集与楼层平面图或用户划分区域求交集
- spaces = this.scene.getPloyIntersect(obj);
- } else {
- // 格式为SPoint[]
- spaces = this.scene.getZoneDifference();
- }
- for (let key in spaces) {
- spaces[key] = spaces[key].map((t) => {
- let temp = t.map((item) => {
- return {
- X: 1 * item.x.toFixed(2),
- Y: -item.y.toFixed(2),
- Z: 0,
- };
- });
- return temp;
- });
- let newarr = this.makeMaxAreaFirst(spaces[key]);
- zoneObj.outline.push(newarr);
- let curISP = this.sourceIdToISP[key];
- if (curISP) {
- curISP && IspaceIdList.push(curISP.id);
- zoneObj.height = this.spaceHeight;
- // 2020-12-20 演示用 -start
- if (curISP.infos) {
- zoneObj.infos = {};
- if (curISP.infos.roomLocalFuncTypeID) {
- zoneObj.infos.roomLocalFuncTypeID =
- curISP.infos.roomLocalFuncTypeID;
- }
- if (curISP.infos.roomLocalFuncTypeName) {
- zoneObj.infos.roomLocalFuncTypeName =
- curISP.infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- }
- }
- } catch (err) {
- console.log(err);
- let selectSpaces = this.scene.getSelectedSpaces();
- console.log(selectSpaces);
- selectSpaces.map((t) => {
- zoneObj.outline.push(t.data.OutLine);
- let key = t.data.SourceId;
- let curISP = this.sourceIdToISP[key];
- if (curISP) {
- curISP && IspaceIdList.push(curISP.id);
- zoneObj.height = this.spaceHeight;
- // 2020-12-20 演示用 -start
- if (curISP.infos) {
- zoneObj.infos = {};
- if (curISP.infos.roomLocalFuncTypeID) {
- zoneObj.infos.roomLocalFuncTypeID =
- curISP.infos.roomLocalFuncTypeID;
- }
- if (curISP.infos.roomLocalFuncTypeName) {
- zoneObj.infos.roomLocalFuncTypeName =
- curISP.infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- }
- });
- // 如果有划分,求交集
- if (this.scene.cutItem || this.scene.sceneMark) {
- zoneObj.outline = [];
- let arr = this.scene.getIntersect();
- arr.map((t) => {
- let temp = t.map((item) => {
- return {
- X: 1 * item.x,
- Y: -item.y,
- Z: 0,
- };
- });
- zoneObj.outline.push([temp]);
- });
- }
- }
- if (!zoneObj.outline.length) {
- zoneObj.outline = null;
- }
- this.updateBSPOutline(zoneObj, IspaceIdList);
- },
- // 编辑空间详情
- editeSpaceDetail() {
- let item = this.curZoneItem.data;
- let query = {
- RoomID: item.RoomID,
- zone: this.tab.code,
- isMyTab: 1,
- buildFloorSelectd: this.buildFloor,
- };
- this.$router.push({
- path: "/ledger/spaceDetail",
- query: query,
- });
- },
- // 重新划分业务空间
- refactorBSP() {
- this.config.isEdit = true;
- this.config.groupSelect = false;
- this.config.divide = true;
- this.type = 4;
- // 设置空间可选
- this.scene.isSpaceSelectable = true;
- // 将已关联的设置不可选,并将当前选的隐藏
- this.scene.isZoneSelectable = false;
- this.curZoneItem.visible = false;
- // 将当前业务空间的每个元素添加到场景中并选中
- this.scene.addAllLikeSpace(this.curZoneItem.data.OutLine);
- },
- // 确认业务空间
- confirmZoneSpace() {
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- let space = {
- id: this.curZoneItem.data.RoomID,
- state: 0,
- classCode: ObjectType,
- };
- let pa = {
- content: [space],
- };
- ScanController.zoneUpdate(pa, (res) => {
- this.curZoneItem.isInfected = false;
- switch (res.result) {
- case logicConfig.resultObj.success:
- this.$emit("updateState");
- this.$message.success("更新成功");
- break;
- default:
- this.$message.error("更新失败");
- break;
- }
- });
- },
- // 保存并确认业务空间
- confirmAndSave() {
- this.confirmAndSaveFlag = true;
- this.saveRefactorBSP();
- },
- // 重新划分--保存
- saveRefactorBSP() {
- let selectSpace = this.scene.getSelectedSpaces();
- let selectLikeSpace = this.scene.getSelectedLikeSpace();
- //更新业务空间
- let zoneObj = {
- outline: [],
- height: 0,
- state: this.confirmAndSaveFlag
- ? 0
- : this.curZoneItem.isInfected
- ? 1
- : 0,
- },
- IspaceIdList = [];
- // 空间
- selectSpace.map((t) => {
- zoneObj.outline.push(t.data.OutLine);
- if (this.BIMIDToSID[t.data.SourceId]) {
- IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
- }
- // 2020-12-20 演示用 -start
- if (
- this.sourceIdToISP[t.data.SourceId] &&
- this.sourceIdToISP[t.data.SourceId].infos
- ) {
- zoneObj.infos = {};
- if (this.sourceIdToISP[t.data.SourceId].infos.roomLocalFuncTypeID) {
- zoneObj.infos.roomLocalFuncTypeID =
- this.sourceIdToISP[t.data.SourceId].infos.roomLocalFuncTypeID;
- }
- if (this.sourceIdToISP[t.data.SourceId].infos.roomLocalFuncTypeName) {
- zoneObj.infos.roomLocalFuncTypeName =
- this.sourceIdToISP[t.data.SourceId].infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- zoneObj.height = this.spaceHeight;
- });
- // 类空间
- selectLikeSpace.map((t) => {
- zoneObj.outline.push(t.data);
- });
- // 如果有划分,求交集
- if (this.scene.cutItem || this.scene.sceneMark) {
- zoneObj.outline = [];
- let spaceIntersect = this.scene.getIntersect();
- spaceIntersect.map((t) => {
- let temp = t.map((item) => {
- return {
- X: item.x,
- Y: -item.y,
- Z: 0,
- };
- });
- zoneObj.outline.push([temp]);
- });
- let likeSpaceIntersect = this.scene.getLikeIntersect();
- likeSpaceIntersect.map((t) => {
- let temp = t.map((item) => {
- return {
- X: item.x,
- Y: -item.y,
- Z: 0,
- };
- });
- zoneObj.outline.push([temp]);
- });
- }
- if (!zoneObj.outline.length) {
- zoneObj.outline = null;
- }
- zoneObj.id = this.curZoneItem.data.RoomID;
- this.updateBSPOutline(zoneObj, IspaceIdList);
- },
- // 根据图批量创建所选业务空间
- groupCreateZone() {
- let arr = this.scene.getSelectedSpaces();
- let createSpaces = [],
- spaces = {};
- try {
- if (this.scene.cutItem || this.scene.sceneMark) {
- // 如果有划分,求交集
- // 格式为Poly(先与业务空间求差集)
- const obj = this.scene.getZoneDifference(true);
- // 差集与楼层平面图或用户划分区域求交集
- spaces = this.scene.getPloyIntersect(obj);
- } else {
- // 格式为SPoint[]
- spaces = this.scene.getZoneDifference();
- }
- for (let key in spaces) {
- let zoneObj = { outline: [], height: 0 };
- spaces[key] = spaces[key].map((t) => {
- let temp = t.map((item) => {
- return {
- X: 1 * item.x.toFixed(2),
- Y: -item.y.toFixed(2),
- Z: 0,
- };
- });
- return temp;
- });
- let newarr = this.makeMaxAreaFirst(spaces[key]);
- zoneObj.outline.push(newarr);
- if (!zoneObj.outline.length) {
- continue;
- }
- //计算面积
- let area = 0,
- line = zoneObj.outline;
- for (let i = 0; i < line.length; i++) {
- for (let j = 0; j < line[i].length; j++) {
- if (j == 0) {
- area += this.getarea(line[i][0]);
- } else {
- area -= this.getarea(line[i][j]);
- }
- }
- }
- area = (area / 1000000).toFixed(2);
- if (area < this.areaValue / 100) {
- continue;
- }
- //生成空间对象
- let curISP = this.sourceIdToISP[key];
- if (curISP) {
- zoneObj.height = this.spaceHeight;
- // zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
- zoneObj.ispaceId = curISP.id;
- zoneObj.localName = curISP.localName || "";
- // 2020-12-20 演示用 -start
- if (curISP.infos) {
- zoneObj.infos = {};
- if (curISP.infos.roomLocalFuncTypeID) {
- zoneObj.infos.roomLocalFuncTypeID =
- curISP.infos.roomLocalFuncTypeID;
- }
- if (curISP.infos.roomLocalFuncTypeName) {
- zoneObj.infos.roomLocalFuncTypeName =
- curISP.infos.roomLocalFuncTypeName;
- }
- }
- // 2020-12-20 演示用 -end
- }
- zoneObj.buildingId = this.buildFloor[0];
- zoneObj.floorId = this.buildFloor[1];
- createSpaces.push(zoneObj);
- }
- } catch (err) {
- console.log(err);
- // 如果有划分,求交集
- if (this.scene.cutItem || this.scene.sceneMark) {
- let outlines = this.scene.getIntersectInSpace();
- for (let k in outlines) {
- outlines[k] = outlines[k].map((t) => {
- t = t.map((item) => {
- item = item.map((j) => {
- return { X: j.x, Y: -j.y, Z: 0 };
- });
- return item;
- });
- return t;
- });
- }
- createSpaces = arr
- .map((t) => {
- let line = outlines[t.data.SourceId];
- if (!line || !line.length) {
- return undefined;
- } else {
- let area = 0;
- for (let i = 0; i < line.length; i++) {
- for (let j = 0; j < line[i].length; j++) {
- if (j == 0) {
- area += this.getarea(line[i][0]);
- } else {
- area -= this.getarea(line[i][j]);
- }
- }
- }
- area = (area / 1000000).toFixed(2);
- if (area < this.areaValue / 100) {
- return undefined;
- }
- }
- return {
- ispaceId: this.BIMIDToSID[t.data.SourceId],
- localName: this.BIMIDToSIName[t.data.SourceId] || "",
- outline: line,
- buildingId: this.buildFloor[0],
- floorId: this.buildFloor[1],
- height: this.spaceHeight,
- // 2020-12-20 演示用 -start
- infos: {
- roomLocalFuncTypeID: this.sourceIdToISP[t.data.SourceId].infos
- ? this.sourceIdToISP[t.data.SourceId].infos
- .roomLocalFuncTypeID || ""
- : "",
- roomLocalFuncTypeName: this.sourceIdToISP[t.data.SourceId]
- .infos
- ? this.sourceIdToISP[t.data.SourceId].infos
- .roomLocalFuncTypeName || ""
- : "",
- },
- // 2020-12-20 演示用 -end
- };
- })
- .filter((item) => item);
- } else {
- createSpaces = arr
- .map((t) => {
- let line = t.data.OutLine;
- if (!line || !line.length) {
- return undefined;
- } else {
- let area = this.getarea(line[0]);
- if (line.length > 1) {
- for (let i = 1; i < line.length; i++) {
- area -= this.getarea(line[i]);
- }
- }
- area = (area / 1000000).toFixed(2);
- if (area < this.areaValue / 100) {
- return undefined;
- }
- }
- return {
- ispaceId: this.BIMIDToSID[t.data.SourceId],
- localName: this.BIMIDToSIName[t.data.SourceId] || "",
- outline: [line],
- buildingId: this.buildFloor[0],
- floorId: this.buildFloor[1],
- height: this.spaceHeight,
- // 2020-12-20 演示用 -start
- infos: {
- roomLocalFuncTypeID: this.sourceIdToISP[t.data.SourceId].infos
- ? this.sourceIdToISP[t.data.SourceId].infos
- .roomLocalFuncTypeID || ""
- : "",
- roomLocalFuncTypeName: this.sourceIdToISP[t.data.SourceId]
- .infos
- ? this.sourceIdToISP[t.data.SourceId].infos
- .roomLocalFuncTypeName || ""
- : "",
- },
- // 2020-12-20 演示用 -end
- };
- })
- .filter((item) => item);
- }
- }
- if (createSpaces.length) {
- this.canvasLoading = true;
- this.groupCreateBSP(createSpaces);
- } else {
- this.$message.warning("未选择空间");
- }
- },
- // 更新业务空间和元空间的关系
- relationInBSPandISP(SpaceId, IspaceIdList) {
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- let pa = {
- data: { spaceId: SpaceId, ispaceIdList: IspaceIdList },
- type: ObjectType,
- };
- businessSpaceController.createRelateInZoneAndISp(pa, (res) => {
- this.$message.success("创建成功");
- this.init(2);
- if (this.confirmAndSaveFlag) {
- this.confirmAndSaveFlag = false;
- this.curZoneItem.selected = false;
- this.curZoneItem = {};
- this.$emit("updateState");
- }
- });
- },
- // 批量更新业务空间和元空间的关系
- groupCreRelaZoneAndISp(Spaces) {
- Spaces = Spaces.filter((item) => item.ispaceId);
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- if (Spaces.length) {
- let param = {
- data: {
- content: Spaces,
- },
- type: ObjectType,
- };
- businessSpaceController.groupCreRelaZoneAndISp(param, (res) => {
- this.canvasLoading = false;
- switch (res.result) {
- case logicConfig.resultObj.success:
- this.$message.success("创建成功");
- this.init(2);
- break;
- default:
- this.$message.error("创建失败");
- break;
- }
- });
- } else {
- this.$message.success("创建成功");
- this.canvasLoading = false;
- this.init(2);
- }
- },
- // 批量创建
- groupCreateBSP(spaces) {
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- spaces = spaces.map((t) => {
- t.classCode = ObjectType;
- t.bimLocation = this.getAverageVal(t.outline);
- return t;
- });
- let pa = {
- content: spaces,
- };
- ScanController.zoneCreate(pa, (res) => {
- res.entityList.map((t) => {
- spaces = spaces.map((item) => {
- if (t.localName == item.localName) {
- item.spaceId = t.id;
- }
- return item;
- });
- });
- this.groupCreRelaZoneAndISp(spaces);
- });
- },
- // 单个创建
- createSingleBSP(space, IspaceIdList) {
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- space.bimLocation = space.outline
- ? this.getAverageVal(space.outline)
- : null;
- space.classCode = ObjectType;
- let pa = {
- content: [space],
- };
- ScanController.zoneCreate(pa, (res) => {
- this.relationInBSPandISP(res.entityList[0].id, IspaceIdList);
- });
- },
- // 更新业务空间区域
- updateBSPOutline(zoneObj, IspaceIdList) {
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- zoneObj.bimLocation = zoneObj.outline
- ? this.getAverageVal(zoneObj.outline)
- : null;
- zoneObj.classCode = ObjectType;
- zoneObj.buildingId = this.buildFloor[0];
- zoneObj.floorId = this.buildFloor[1];
- let pa = {
- content: [zoneObj],
- };
- if (!zoneObj.outline) {
- zoneObj.nullList = ["outline"];
- }
- ScanController.zoneUpdate(pa, (res) => {
- ScanController.zoneUpdateOutline(pa, (res) => {
- console.log(res);
- });
- this.updateZoneBF(zoneObj, IspaceIdList);
- });
- },
- // 从未关联平面图的业务空间中选择时更新业务空间建筑楼层
- updateZoneBF(zoneObj, IspaceIdList) {
- let pa = [
- {
- type: zoneObj.classCode,
- spaceId: zoneObj.id,
- id: zoneObj.floorId,
- },
- ];
- ScanController.handleZoneUpdateBd(pa, (res) => {
- this.relationInBSPandISP(zoneObj.id, IspaceIdList);
- });
- },
- // 查询未关联平面图的业务空间(项目下+当前分区)
- getBSPunrelaISP() {
- let ObjectType = this.tab.code;
- // let ObjectType = this.tab.code == 'OtherZone' ? this.OtherValue : this.tab.code;
- let pa = {
- Filters: `outline isNull;classCode="${ObjectType}"`,
- };
- businessSpaceController.zoneCount(pa, (res) => {
- this.num = res.count;
- });
- },
- // 计算平均值 作为业务空间BIMLocation
- getAverageVal(Outline) {
- let X = 0,
- Y = 0,
- Z = 0,
- len = 0;
- Outline.map((t) => {
- if (t[0]) {
- t[0].map((item) => {
- X += item.X;
- Y += item.Y;
- Z += item.Z;
- });
- len += t[0].length;
- }
- });
- X = (X / len).toFixed(2);
- Y = (Y / len).toFixed(2);
- Z = (Z / len).toFixed(2);
- return `${X},${Y},${Z}`;
- },
- // 计算面积
- getarea(arr) {
- if (!arr.length) {
- return 0;
- }
- let sum = 0;
- let n = arr.length;
- arr[n] = arr[0];
- for (let i = 1; i <= n; i++) {
- sum += arr[i].X * arr[i - 1].Y - arr[i - 1].X * arr[i].Y;
- }
- return Math.abs(sum / 2);
- },
- // canvas 获取焦点
- focus() {
- document.getElementById(`floorCanvas`).focus();
- },
- // 清除canvas
- clearGraphy() {
- if (this.view) {
- this.view.scene = null;
- return;
- }
- this.view = new FloorView("floorCanvas");
- },
- // 工具栏操作
- // 吸附
- changeAbsorb(isAbsorbing) {
- this.scene.isAbsorbing = isAbsorbing;
- },
- // 框选
- groupSelect() {
- this.scene.isRectSelection = 1;
- },
- // 适配底图到窗口
- fit() {
- if (this.scene.sceneMark) {
- this.view.fitItemToView([this.scene.sceneMark]);
- return;
- }
- this.view.fitSceneToView();
- },
- // 保存为png
- savePng() {
- this.view.saveImage(
- `${this.projectName}-${this.buildFloorName}.png`,
- "png"
- );
- },
- // 保存为svg
- saveSvg() {
- this.view.saveSceneSvg(
- `${this.projectName}-${this.buildFloorName}.svg`,
- 6400,
- 4800
- );
- },
- // 保存json
- saveJson() {
- this.view.saveFloorJson(
- `${this.projectName}-${this.buildFloorName}.json`
- );
- },
- // 切割划分
- divide() {
- this.scene.isCutting = true;
- },
- // 清除切割划分
- clearDivide() {
- this.scene.clearCut();
- },
- // 撤销
- undo() {},
- // 反撤销
- redo() {},
- // 缩放
- scale(val) {
- if (!this.view) {
- return;
- }
- let scale = this.view.scale;
- this.view.scaleByPoint(
- val / scale,
- this.canvasWidth / 2,
- this.canvasHeight / 2
- );
- },
- // 给定多个轮廓线的数据,计算得到面积最大值,并把它放置数组第一项,并将第一项顺时针处理,第一项以后的每一项做逆时针处理
- // list {XYZ}[][]
- makeMaxAreaFirst(list) {
- let arr = [],
- area = 0;
- for (let i = 0; i < list.length; i++) {
- let temp = this.getarea(list[i]);
- if (temp > area) {
- arr.unshift(list[i]);
- } else {
- arr.push(list[i]);
- }
- }
- arr.map((t, i) => {
- if (!i) {
- if (this.clockDir(t) > 0) {
- return t;
- } else {
- return t.reverse();
- }
- } else {
- if (this.clockDir(t) > 0) {
- return t.reverse();
- } else {
- return t;
- }
- }
- });
- return arr;
- },
- // 数组为顺时针or逆时针 顺时针非负 逆时针为 负
- clockDir(pointList) {
- let l = pointList.length - 1;
- if (
- pointList[0].x == pointList[l].x &&
- pointList[0].y == pointList[l].y
- ) {
- pointList.splice(l, 1);
- }
- if (pointList.length < 3) {
- return 0;
- }
- let index = 0;
- let len = pointList.length;
- for (let i = 1; i < len; i++) {
- if (pointList[i].X > pointList[index].X) {
- index = i;
- }
- }
- let p1 = pointList[index == 0 ? len - 1 : index - 1];
- let p2 = pointList[index];
- let p3 = pointList[(index + 1) % len];
- return (p2.X - p1.X) * (p3.Y - p2.Y) - (p2.Y - p1.Y) * (p3.X - p2.X);
- },
- // 删除业务空间
- deleteZone() {
- if (this.curZoneItem) {
- const item = this.curZoneItem.data;
- const pa = [{ id: item.RoomID }];
- ScanController.zoneDelete(pa, (res) => {
- this.init(2);
- });
- }
- },
- },
- filters: {
- cutString: function (str, len) {
- //length属性读出来的汉字长度为1
- if (!!str && typeof str == "string" && str.length > len) {
- return str.substring(0, len) + "...";
- } else {
- return str || "--";
- }
- },
- },
- watch: {
- projectId() {
- this.FloorMap = "";
- this.tab = {};
- },
- "view.scale": {
- handler(n) {
- if (this.$refs.canvasFun) {
- let s = (n * 10) / this.view.minScale;
- this.$refs.canvasFun.sliderVal = s > 1000 ? 1000 : s;
- }
- },
- },
- "scene.isRectSelection": {
- handler(n) {
- if (!n) {
- this.$refs.canvasFun.active = "";
- }
- },
- },
- "scene.isCutting": {
- handler(n) {
- if (!n) {
- this.$refs.canvasFun.active = "";
- this.$refs.canvasFun.isSwitch = false;
- this.scene.isAbsorbing = false;
- }
- },
- },
- },
- };
- </script>
- <style lang="less" scoped>
- #graphy {
- position: relative;
- width: 100%;
- box-sizing: border-box;
- padding: 0 10px 10px;
- height: calc(100% - 56px);
- .canvas-box {
- width: 100%;
- height: 100%;
- }
- .buttons-box {
- position: absolute;
- top: 0;
- left: 0;
- padding: 0 10px;
- width: 100%;
- z-index: 999;
- & > div {
- float: left;
- }
- /deep/ .el-autocomplete {
- display: inline-block;
- width: 320px;
- margin-right: 10px;
- }
- .button-group button,
- .button-group .el-dropdown {
- display: block;
- float: left;
- }
- .my-autocomplete {
- li {
- line-height: normal;
- padding: 7px;
- .name {
- text-overflow: ellipsis;
- overflow: hidden;
- }
- .addr {
- font-size: 12px;
- color: #b4b4b4;
- }
- .highlighted .addr {
- color: #ddd;
- }
- }
- }
- }
- .canvas-actions-box {
- position: absolute;
- bottom: 60px;
- left: 50%;
- transform: translateX(-50%);
- z-index: 99;
- }
- #autoRelate {
- /deep/ .el-slider__marks-text:nth-child(2) {
- width: 25px;
- }
- }
- }
- </style>
|