Browse Source

动态源;设备关系过滤

zhaoyk 2 years ago
parent
commit
5fe25bff74

+ 9 - 2
adm_comp/src/components/FilterPanel.vue

@@ -100,11 +100,18 @@
 			this.relatedObjOptions = [];
 			if(this.relatedObjs) {
 				for(const obj of this.relatedObjs) {
+					let val = obj.id;
+					let label = obj.name != null ? obj.name : obj.id;
 					if(obj.compType == 'mainPipe'){
-						this.relatedObjOptions.push({value: 'mainPipe:' + obj.id, label: '干管:' + (obj.name != null ? obj.name : obj.id)});
+						val = 'mainPipe:' + val;
+						label = '干管:' + label;
 					} else if(obj.compType == 'container') {
-						//TODO
+						val = 'container:' + val;
+						label = '容器:' + label;
 					}
+					if(obj.dynTarget)
+						label = '<动态源>' + label;
+					this.relatedObjOptions.push({value: val, label: label});
 				}
 			}
 		}

+ 79 - 1
adm_comp/src/lib/DiagramModel.ts

@@ -20,6 +20,36 @@ export class Template {
 	
 	scatteredContainers: Array<Container>;
 	
+	static getContainerById(id: string, template: Template): Container {
+		return Container.getContainerById(id, template.frame);
+	}
+	
+	static getMainPipeById(id: string, template: Template): MainPipe {
+		if(template.mainPipes){
+			for(const mp of template.mainPipes){
+				if(mp.id == id)
+					return mp;
+			}
+		}
+		return null;
+	}
+	
+	static getContainers(template: Template): Array<Container> {
+		const result = new Array<Container>();
+		Template.doGetContainers(template.frame, result);
+		return result;
+	}
+	
+	private static doGetContainers(con: Container, result: Array<Container>){
+		result.push(con);
+		if(con.children && con.children.length > 0){
+			con.children.forEach(comp => {
+				if(comp.compType == 'container')
+					Template.doGetContainers(<Container>comp, result);
+			});
+		}
+	}
+	
 	static findRelatedMainPipes(con: Container, template: Template): Array<MainPipe> {
 		const mps = new Array<MainPipe>();
 		while(true) {
@@ -27,7 +57,7 @@ export class Template {
 				break;
 			
 			for(const mp of template.mainPipes) {
-				if(mp.relatedContainers && mp.relatedContainers.indexOf(con.id) >= 0){
+				if(mp.bindEquipment && mp.relatedContainers && mp.relatedContainers.indexOf(con.id) >= 0){
 					if(mps.indexOf(mp) < 0) {
 						mps.push(mp);	
 					}
@@ -39,6 +69,33 @@ export class Template {
 		return mps;
 	}
 	
+	static findDynSrcs(el: any, template: Template, ignoreEl: any, srcs: Array<string>){
+		if(el.compType == 'mainPipe') {
+			const mp = <MainPipe>el;
+			const relCons = mp.relatedContainers;
+			if(relCons && relCons.length > 0) {
+				for(const conId of relCons) {
+					const relCon = Template.getContainerById(conId, template);
+					if(relCon)
+						Template.findDynSrcs(relCon, template, ignoreEl, srcs);	
+				}
+			}
+		} else if(el.compType == 'container') {
+			const con = <Container>el;
+			if(con.dynGroup) {
+				var srcObj;
+				if(con.dynGroup.dynSourceType == 'container')
+					srcObj = Template.getContainerById(con.dynGroup.dynSource, template);
+				else if(con.dynGroup.dynSourceType == 'mainPipe')
+					srcObj = Template.getMainPipeById(con.dynGroup.dynSource, template);
+				if(srcObj && srcObj != ignoreEl && srcs.indexOf(srcObj) < 0)
+					srcs.push(srcObj);	
+			}
+			if(con.parent)
+				Template.findDynSrcs(con.parent, template, ignoreEl, srcs);
+		}
+	}
+	
 	static clearParent(template: Template){
 		Template.clearConParent(template.frame);
 	}
@@ -91,6 +148,8 @@ export class Container extends Comp {
 	
 	props: Object;
 	
+	dynTarget: string;
+	
 	static getEquipBoxes(con: Container, arr?: Array<Container>){
 		if(!arr)
 			arr = new Array<Container>();
@@ -116,6 +175,21 @@ export class Container extends Comp {
 		return arr;
 	}
 	
+	static getContainerById(id: string, con: Container): Container {
+		if(con.id == id)
+			return con;
+		if(con.children && con.children.length > 0){
+			for(const c of con.children) {
+				if(c.compType == 'container') {
+					const rtn = Container.getContainerById(id, <Container>c);
+					if(rtn != null)
+						return rtn;	
+				}
+			}
+		}
+		return null;
+	}
+	
 }
 
 export class DataFilter {
@@ -148,6 +222,8 @@ export class DynGroup {
 
 	dynSource: string;
 	
+	dynSourceType: string;
+	
 	labelPosition: string;
 
 }
@@ -170,6 +246,8 @@ export class MainPipe {
 	
 	locationPath: Array<Array<Point>>;
 			
+	dynTarget: string;
+	
 }
 
 export class Legend {

+ 19 - 3
adm_comp/src/lib/TemplateEditor.ts

@@ -61,6 +61,8 @@ export class TemplateEditor extends Editor {
 		if(this.templateData.scatteredContainers)
 			this.templateData.scatteredContainers.forEach(con => this.util.prepareParent(con));
 
+		const sel = this.getSelComp();
+
 		//绘制排列定位容器		
 		this.drawContainer(root);
 		
@@ -85,12 +87,21 @@ export class TemplateEditor extends Editor {
 				let lw = 1;
 				let ld = [];
 				
-				if(this.getSelComp() == item) { //选中状态
+				if(sel == item) { //选中状态
 					lw = 2;
 					if(this.tmpMainPipe) { //重新绘制该干管
 						ld = [5, 5];
 						color = '#ff5500';
 					}
+				} else {
+					const relWithSel = sel && sel.compType == 'container' && item.relatedContainers && item.relatedContainers.indexOf(sel.id) >= 0;
+					if(relWithSel){
+						if(item.dynTarget == sel.id)
+							color = "#48d800";
+						else
+							color = "rgba(127, 127, 0)";
+						lw = 2;
+					}
 				}
 					
 				this.ctx.strokeStyle = color;
@@ -160,9 +171,15 @@ export class TemplateEditor extends Editor {
 			this.refPoints[con.id] = ContainerRefPoint.getRefPoints(con.id, location, con.size);
 				
 		const equip = con.equipmentTypes && con.equipmentTypes.length > 0;
-		const color = equip ? (!liberty ? "#000000" : "#2a7652") : (!liberty ? "#9b9ea3": "#42B983");
+		let color = equip ? (!liberty ? "#000000" : "#2a7652") : (!liberty ? "#9b9ea3": "#42B983");
 		const dash = equip ? [] : [3, 2];
 		
+		const selComp = this.getSelComp();
+		if(selComp && selComp.compType == 'container' && selComp.id == con.dynTarget){
+			//当前选中容器的动态源
+			color = "#48d800";
+		}
+		
 		this.ctx.lineWidth = 1;
 		this.ctx.setLineDash(dash);
 		this.ctx.strokeStyle = color;
@@ -171,7 +188,6 @@ export class TemplateEditor extends Editor {
 		this.ctx.rect(location.x, location.y, con.size.x, con.size.y);	
 		this.ctx.stroke();
 		
-		const selComp = this.getSelComp();
 		if(selComp == con) {
 			this.ctx.fillStyle = "rgba(0, 127, 255, 0.1)";
 			this.ctx.fill();

+ 36 - 9
adm_comp/src/views/DiagramTemplate.vue

@@ -775,12 +775,35 @@
 		editFilter(){
 			const sel = this.editor.getSelComp();
 			this.dataFilter = sel.dataFilter != null ? sel.dataFilter : {};//为null时赋一个新对象,触发子组件watch
-			if(sel.compType == 'container') {
-				this.filterRelatedObjs = Template.findRelatedMainPipes(sel, this.currentTemplate);
-			} else {
-				this.filterRelatedObjs = [];
+			const relObjs = [];
+			const normalCons = [];
+			if(!sel.dynTarget) {
+				if(sel.compType == 'container') {
+					relObjs.push(...Template.findRelatedMainPipes(sel, this.currentTemplate));
+					
+					const arr: any[] = Template.getContainers(this.currentTemplate);
+					arr.forEach(item => {
+						if(item.equipmentTypes != null && item.equipmentTypes.length > 0 && item.id != sel.id)
+							normalCons.push(item);
+					});
+				} else if(sel.compType == 'mainPipe') {
+					if(sel.relatedContainers) {
+						for(const conId of sel.relatedContainers){
+							const con = this.editor.getConById(conId);
+							if(con)
+								relObjs.push(con);
+						}
+					}
+				}
 			}
 			
+			Template.findDynSrcs(sel, this.currentTemplate, sel, relObjs);
+			
+			if(normalCons.length > 0)
+				relObjs.push(...normalCons);
+			
+			this.filterRelatedObjs = relObjs;
+			
 			this.dlgFilterVisible = true;
 		}
 		
@@ -844,14 +867,14 @@
 			const props:any = {};
 			if(sel.dynGroup) {
 				props.enableDynGroup = true;
-				props.dynSource = sel.dynGroup.dynSource;
+				props.dynSource = sel.dynGroup.dynSourceType + ':' + sel.dynGroup.dynSource;
 				props.labelPosition = sel.dynGroup.labelPosition;
 			} else {
 				props.enableDynGroup = false;
 			}
 			this.propsData = props;
 			
-			this.dynSourceOptions = [{value:'floor', label: '楼层'}, {value:'building', label: '建筑'}];
+			this.dynSourceOptions = [{value:'group:floor', label: '楼层(按设备统计)'}, {value:'data:floor', label: '楼层(全部)'}, {value:'group:building', label: '建筑(按设备统计)'}, {value:'data:building', label: '建筑(全部)'}];
 			if(this.currentTemplate.mainPipes){
 				for(const mp of this.currentTemplate.mainPipes) {
 					if(mp.bindEquipment && mp.relatedContainers && mp.relatedContainers.indexOf(sel.id) >= 0){
@@ -861,7 +884,7 @@
 			}
 			const equipBoxes: any[] = Container.getEquipBoxes(sel);
 			for(const box of equipBoxes) {
-				this.dynSourceOptions.push({value: 'containerElement:' + box.id, label: '容器中设备:' + (box.name != null ? box.name : box.id)});
+				this.dynSourceOptions.push({value: 'container:' + box.id, label: '容器中设备:' + (box.name != null ? box.name : box.id)});
 			}
 			
 			this.dlgDynGroupVisible = true;
@@ -880,8 +903,12 @@
 			var dynGroup: any;
 			if(!this.propsData.enableDynGroup)
 				dynGroup = null;
-			else
-				dynGroup = this.propsData;
+			else {
+				dynGroup = {labelPosition: this.propsData.labelPosition};
+				const arr = this.propsData.dynSource.split(":");
+				dynGroup.dynSourceType = arr[0];
+				dynGroup.dynSource = arr[1];
+			}
 			const params:any = {currentCompId: this.editor.getSelComp().id, templateId: this.currentTemplate.id, dynGroup: dynGroup};
 			this.callAction('modifyDynGroup', params);
 		}