123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967 |
- <template>
- <div id="graphy" ref="graphy">
- <div v-show="!FloorMap">
- <div class="center" style="height: 400px;padding-top:182px;box-sizing:border-box;">
- <i class="icon-wushuju iconfont"></i>
- 暂无数据
- </div>
- </div>
- <div class="canvas-box" v-show="FloorMap" v-loading="canvasLoading">
- <canvas id="floorCanvas" :width="canvasWidth" :height="canvasHeight" ref="canvas" tabindex="0"></canvas>
- <!-- 初始两个按钮 -->
- <el-row class="buttons-box">
- <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" @click="handleSelect"></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 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>
- </div>
- <!-- 批量创建所选业务空间 -->
- <div v-show="type==5">
- <el-button type="primary" @click="groupCreateZone">批量创建所选业务空间</el-button>
- <el-button plain @click="cancelGraphy">取 消</el-button>
- </div>
- </div>
- <div style="position: absolute;right: 0;">
- <el-button type="text" @click="lookUnrelatBSpace(false)">未关联平面图的业务空间 {{num}} 条</el-button>
- </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%">
- <div id="autoRelate">
- <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>
- </div>
- </template>
- <script>
- import canvasFun from "./canvasFun"
- import { mapGetters, mapActions } from "vuex";
- import { SColor, SPoint } from "@saga-web/draw/lib";
- import { DivideFloorScene, SpaceItem, ZoneItem, FloorView } from "@saga-web/cad-engine/lib";
- import { colorArr } from "@/utils/spaceColor"
- import unRelateBSP from "./unRelateBSP";
- import createBSP from "./createBSP";
- import {
- buildingQuery,
- queryZone,
- updateZone,
- createZone,
- countZone,
- getIspNotInSpace,
- createRelateInZoneAndISp,
- groupCreRelaZoneAndISp
- } from "@/api/scan/request"
- export default {
- components: {
- canvasFun,
- unRelateBSP,
- createBSP
- },
- 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: {}
- }
- },
- computed: {
- ...mapGetters('layout', ['projectId'])
- },
- created() { },
- mounted() {
- this.canvasWidth = this.$refs.graphy.offsetWidth;
- this.canvasHeight = this.$refs.graphy.offsetHeight;
- },
- 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: 1000
- }
- }
- queryZone(pa, res => {
- this.BIMIDToSID = {}
- this.BIMIDToSIName = {}
- this.sourceIdToISP = {}
- res.Content.map(t => {
- let key = t.BIMID.split(":")[1];
- this.BIMIDToSID[key] = t.RoomID;
- this.BIMIDToSIName[key] = t.RoomLocalName || t.RoomName;
- this.sourceIdToISP[key] = t;
- })
- })
- },
- // 搜索
- 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();
- },
- // 父组件调用
- getData(buildFloor, FloorObj, tab) {
- let initType = 1;
- if (FloorObj.FloorID == this.FloorObj.FloorID) {
- initType = 2;
- }
- this.buildFloor = buildFloor;
- this.FloorObj = FloorObj;
- this.FloorMap = FloorObj.StructureInfo ? FloorObj.StructureInfo.FloorMap : ''
- this.tab = tab;
- console.log(arguments)
- this.init(initType);
- },
- // 获取未绑定业务空间的元空间
- getISPSPUnrelaBSP() {
- let pa = {
- data: {
- Filters: `FloorId='${this.buildFloor[1]}'`,
- PageSize: 1000
- },
- objectType: this.tab.code
- }
- this.allUnRelatISP = []
- getIspNotInSpace(pa, res => {
- this.allUnRelatISP = res.Content;
- })
- },
- // 获取底图
- getGraphy() {
- let that = this;
- that.clearGraphy()
- that.scene = new DivideFloorScene();
- that.canvasLoading = true;
- that.scene.loadUrl(`/image-service/common/file_get?systemId=revit&key=${this.FloorMap}`).then(res => {
- that.canvasLoading = false;
- if (res == 'error') {
- this.FloorMap = '';
- this.$message.warning('数据解析异常');
- 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.view.fitSceneToView();
- that.view.minScale = that.view.scale;
- if (that.$refs.canvasFun) {
- that.$refs.canvasFun.everyScale = that.view.scale;
- }
- })
- },
- // 获取当前分区下的业务空间
- getBusinessSpace() {
- this.canvasLoading = true
- let pa = {
- zone: this.tab.code,
- data: {
- Filters: ``,
- Orders: "createTime desc, RoomID asc",
- PageSize: 1000
- }
- }
- if (this.buildFloor.length && this.buildFloor.length > 1) {
- pa.data.Filters = `BuildingId='${this.buildFloor[0]}';FloorId='${this.buildFloor[1]}'`
- }
- queryZone(pa, res => {
- // 所有业务空间
- 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) => {
- if (t.FloorId == this.buildFloor[1] && t.ObjectType == this.tab.code) {
- return {
- RoomLocalName: t.RoomLocalName,
- OutLine: t.Outline,
- RoomID: t.RoomID,
- Color: colorArr[i % colorArr.length],
- }
- } else {
- console.log('internet slow')
- return undefined;
- }
- }).filter(item => item)
- this.scene.removeAllZone();
- this.scene.addZoneList(tempArr);
- this.scene.click(this, this.canvasClick);
- this.zoneList = this.scene.zoneList;
- 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.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
- },
- // 查看未关联的业务空间--flag--查看-or-选择
- lookUnrelatBSpace(flag) {
- this.isAction = flag;
- let arr = this.scene.getSelectedSpaces();
- if (flag && !arr.length) {
- this.$message.warning('请至少选择一个空间');
- return;
- }
- this.$refs.unRelateBSP.showDialog();
- },
- // 取消(所有取消公用)
- cancelGraphy() {
- this.init(2);
- },
- // 批量创建业务空间弹窗
- 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;
- }
- },
- // 根据未关联元空间批量创建业务空间
- groupCreateBSpace() {
- let text = []
- let Spaces = this.allUnRelatISP.map(t => {
- if (t.Outline) {
- text.push(t.RoomLocalName || t.RoomName)
- return {
- IspaceId: t.RoomID,
- RoomLocalName: t.RoomLocalName || t.RoomName,
- Outline: [t.Outline],
- BuildingId: this.buildFloor[0],
- FloorId: this.buildFloor[1],
- Height: t.Height || 0
- }
- } 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 => {
- 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 = {};
- // 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].map(t => {
- // let temp = t.map(item => {
- // return {
- // X: 1*item.x.toFixed(2),
- // Y: -item.y.toFixed(2),
- // Z: 0
- // }
- // })
- // zoneObj.Outline.push([temp]);
- // })
- // let curISP = this.sourceIdToISP[key];
- // curISP && IspaceIdList.push(curISP.RoomID);
- // zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
- // }
- // 数据计算导致浏览器奔溃,临时注释
- let zoneObj = { Outline: [], Height: 0 }, IspaceIdList = [];
- let selectSpaces = this.scene.getSelectedSpaces();
- selectSpaces.map(t => {
- zoneObj.Outline.push(t.data.OutLine);
- let key = t.data.SourceId;
- let curISP = this.sourceIdToISP[key];
- curISP && IspaceIdList.push(curISP.RoomID);
- zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
- })
- // 如果有划分,求交集
- 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.RoomLocalName = 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 = [];
- 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].map(t => {
- let temp = t.map(item => {
- return {
- X: 1 * item.x.toFixed(2),
- Y: -item.y.toFixed(2),
- Z: 0
- }
- })
- zoneObj.Outline.push([temp]);
- })
- let curISP = this.sourceIdToISP[key];
- curISP && IspaceIdList.push(curISP.RoomID);
- zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
- }
- 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);
- },
- // 重新划分--保存
- saveRefactorBSP() {
- let selectSpace = this.scene.getSelectedSpaces();
- let selectLikeSpace = this.scene.getSelectedLikeSpace();
- //更新业务空间
- let zoneObj = { Outline: [], Height: 0 }, IspaceIdList = [];
- // 空间
- selectSpace.map(t => {
- zoneObj.Outline.push(t.data.OutLine);
- if (this.BIMIDToSID[t.data.SourceId]) {
- IspaceIdList.push(this.BIMIDToSID[t.data.SourceId]);
- }
- if (t.Height && (zoneObj.Height == 0 || t.Height < zoneObj.Height)) {
- zoneObj.Height = t.Height > 100 ? (t.Height / 1000).toFixed(2) : t.Height;
- }
- })
- // 类空间
- 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.RoomID = this.curZoneItem.data.RoomID;
- this.updateBSPOutline(zoneObj, IspaceIdList)
- },
- // 根据图批量创建所选业务空间
- groupCreateZone() {
- let arr = this.scene.getSelectedSpaces();
- let createSpaces = [], spaces = {};
- 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].map(t => {
- let temp = t.map(item => {
- return {
- X: 1 * item.x.toFixed(2),
- Y: -item.y.toFixed(2),
- Z: 0
- }
- })
- zoneObj.Outline.push([temp]);
- })
- if (!zoneObj.Outline.length) {
- continue
- }
- let curISP = this.sourceIdToISP[key];
- zoneObj.Height = zoneObj.Height == 0 ? curISP.Height : zoneObj.Height > curISP.Height ? curISP.Height : zoneObj.Height;
- zoneObj.IspaceId = curISP.RoomID;
- zoneObj.RoomLocalName = curISP.RoomLocalName;
- zoneObj.BuildingId = this.buildFloor[0];
- zoneObj.FloorId = this.buildFloor[1];
- createSpaces.push(zoneObj);
- }
- if (createSpaces.length) {
- this.canvasLoading = true;
- this.groupCreateBSP(createSpaces)
- } else {
- this.$message.warning('未选择空间');
- }
- },
- // 更新业务空间和元空间的关系
- relationInBSPandISP(SpaceId, IspaceIdList) {
- let pa = {
- data: { SpaceId: SpaceId, IspaceIdList: IspaceIdList },
- type: this.tab.code
- }
- createRelateInZoneAndISp(pa, res => {
- this.$message.success('创建成功');
- this.init(2);
- })
- },
- // 批量更新业务空间和元空间的关系
- groupCreRelaZoneAndISp(Spaces) {
- Spaces = Spaces.filter(item => item.IspaceId);
- if (Spaces.length) {
- let param = {
- data: {
- Content: Spaces
- },
- type: this.tab.code
- }
- groupCreRelaZoneAndISp(param, res => {
- this.$message.success('创建成功')
- this.canvasLoading = false;
- this.init(2)
- })
- } else {
- this.$message.success('创建成功')
- this.canvasLoading = false;
- this.init(2)
- }
- },
- // 批量创建
- groupCreateBSP(spaces) {
- spaces = spaces.map(t => {
- t.BIMLocation = this.getAverageVal(t.Outline);
- return t;
- })
- let pa = {
- zone: this.tab.code,
- data: {
- Content: spaces
- }
- }
- createZone(pa, res => {
- res.EntityList.map(t => {
- spaces = spaces.map(item => {
- if (t.RoomLocalName == item.RoomLocalName) {
- item.SpaceId = t.RoomID
- }
- return item;
- })
- })
- this.groupCreRelaZoneAndISp(spaces)
- })
- },
- // 单个创建
- createSingleBSP(space, IspaceIdList) {
- space.BIMLocation = space.Outline ? this.getAverageVal(space.Outline) : null;
- let pa = {
- zone: this.tab.code,
- data: {
- Content: [space]
- }
- }
- createZone(pa, res => {
- this.relationInBSPandISP(res.EntityList[0].RoomID, IspaceIdList)
- })
- },
- // 更新业务空间区域
- updateBSPOutline(zoneObj, IspaceIdList) {
- zoneObj.BIMLocation = zoneObj.Outline ? this.getAverageVal(zoneObj.Outline) : null;
- let pa = {
- zone: this.tab.code,
- data: {
- Content: [zoneObj],
- Projection: ['Outline', 'BIMLocation']
- },
- }
- updateZone(pa, res => {
- this.relationInBSPandISP(zoneObj.RoomID, IspaceIdList)
- })
- },
- // 查询未关联平面图的业务空间(项目下+当前分区)
- getBSPunrelaISP() {
- let pa = {
- zone: this.tab.code,
- data: {
- Filters: `Outline isNull`
- }
- }
- countZone(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}`
- },
- // 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() {
- this.view.fitSceneToView()
- },
- // 保存为png
- savePng() {
- this.view.saveImage(`${this.buildFloor[1]}.png`, 'png');
- },
- // 保存为svg
- saveSvg() {
- this.view.saveSceneSvg(`${this.buildFloor[1]}.svg`, 6400, 4800);
- },
- // 保存json
- saveJson() {
- this.view.saveFloorJson(`${this.buildFloor[1]}.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);
- },
- },
- 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%;
- height: calc(100% - 56px);
- .canvas-box {
- width: 100%;
- height: 100%;
- }
- .buttons-box {
- position: absolute;
- top: 0;
- width: 100%;
- z-index: 999;
- & > div {
- float: left;
- }
- /deep/ .el-autocomplete {
- display: 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: 20px;
- left: 50%;
- transform: translateX(-50%);
- z-index: 999;
- }
- }
- </style>
|