一、从archivesList.vue 的 toDetail 方法进入页面

<el-tabs v-model="activeName" class="top-tab" @tab-click="handleClick">
	<el-tab-pane label="设备标点" name="equipmentPoint">
		<EquipmentPoint v-if="activeName === 'equipmentPoint'"/>
	</el-tab-pane>
</el-tabs>

v-model的值绑定选项卡的 name值,点击的时候,activeName的值动态改变为选项卡的name值,当到哪一个tab页的时候,就渲染对应的组件

equipmentPoint组件 使用了: <G2MapDetail </G2MapDetail>组件 里面又有三个组件,分别是: Search、Plantu、Floor

Search组件: 获取楼栋下拉框信息: getLouDong()方法 传入unitId,通过findBuildByUnitId接口获取数据 因为unitId是通过archivesList.vue组件传入的,如果直接存到store里面,那么会在刷新页面的时候丢失,所以需要存入localstorage里面:localStorage.setItem("unitId", unitId); 在Search.vue组件里面的mounted方法里面: this.$store.commit('updateShUnitId', localStorage.getItem("unitId"))存到store里面,以后要用到这个unitId,就可以直接使用:var unitId = this.$store.state.shUnitId;获取

<el-col :span="5" class="text-2">
		<label>楼栋:</label>
		<el-select v-model.trim="formInline.area" placeholder="" @change="selectTypeName">
			<el-option v-for="item in areaOpts" :key="item.buildId" :label="item.buildName" :value="item.buildId"></el-option>
		</el-select>
</el-col>

:label="item.buildName":显示的是下拉框里面的值 v-model.trim="formInline.area":显示的是输入框里面的值

点击查询按钮:触发一个searchBtn事件

searchBtn: function () {
	var that = this;
	this.$store.commit('updateZSCurrentBuildname', this.buildName);
	this.$store.commit('updateZSCurrentBuild', this.formInline.area);
	this.$store.commit('updateZSdeviceId', this.formInline.deviceId);
	this.$store.commit('updateZSdeviceTypeId', this.ZS.MONITOR.deviceQueryType);
	this.$emit("searchFloor", {  //向父组件触发一个emit事件searchFloor
		buildId: that.formInline.area,
		unitId:that.$store.state.shUnitId,
		floorId:that.$store.state.ZS.MONITOR.currentFloor,
		deviceId: that.formInline.deviceId,
		deviceTypeIds:that.ZS.MONITOR.deviceQueryType
	})
}

Floor组件: 默认会初始调用:getFloorListByBuildId,里面有一个commit,that.$store.commit('updateZSCurrentFloorObj', Math.random()); 这样,会触发**Plantu组件:**里面的watch,然后会调用里面的 addPicToMap(picUrl, buildId, floorId)方法 主要是获取floorArr,楼层信息 使用getFloorListByBuildId方法, 当有buildId的时候【这种情况属于点击查询按钮】,直接调用getFloorInfoByUnitIdAndBuildId接口,传入unitId和buildId,获取楼层信息,floorData = data[key];填充floorArr 当没有buildId的时候【这种情况属于,刚刚打开页面的情况,没有点击搜索按钮】,先通过findBuildByUnitId接口,传入unitId,获取buildId,默认为data.data[0].buildId,第一层楼,然后在调用getFloorInfoByUnitIdAndBuildId接口获取楼层信息

Plantu组件: 初始调用addPicToMap(picUrl, buildId, floorId)方法 然后,调用loadEquipmentPoint方法 设备标点: that.drawPoint(equip['longitude'], equip['latitude'], iconUrl, equip); 地图上有地图和设备点,设备点是标上去的,地图只是一张图片而已 picUrl就是底层图片地图

picUrl从哪里来的呢? Floor组件,里面有 that.$emit("changeFloorPic", floorData && JSON.stringify(floorData) != '{}' ? floorData : data[0]);方法, 父组件G2MapDetail.vue接收:v-on:changeFloorPic="changeFloorPic" 改变floorObj Plantu里面使用prop接收floorObj,然后在watch里面改变地图的图片 这几天修复的标点bug,主要属于数据不全的情况下导致的,比如没有图纸等等 没有图纸,导致没有图层容器

if(!_this.$refs.myplantu.ZS.MONITOR.deviceLayer){
	//创建元素图层
		var elementLayer = new _this.gs2.lys.ElementLayer();
		_this.$refs.myplantu.ZS.MONITOR.floor_g2map.addLayer(elementLayer);
		_this.$refs.myplantu.ZS.MONITOR.deviceLayer = elementLayer; //全局标点使用

		//创建tooltip管理
		_this.$refs.myplantu.ZS.MONITOR.floor_tooltipWare = new _this.gs2.ext.TooltipWare({
			excluseLayerIds: elementLayer.getLayerId(),
			map: _this.$refs.myplantu.ZS.MONITOR.floor_g2map
		});
}else{
	 _this.$refs.myplantu.ZS.MONITOR.deviceLayer.clear();
}

没有元素图层就先创建一个,有的话就先清空,很牛逼!

加载图层,知情书有img.onload方法,在没有图纸的情况下,使用img.onerror方法 然后,由于清除图层会有缓存,所以在图纸路径后面加了一个随机数作为清缓存,这样使得图纸可以马上出现

that.ZS.MONITOR.floor_imageLayer = new that.gs2.lys.ImageLayer({
	imageType: 702,
	extent: [
		0,
		0,
		w,
		h
	], //图片范围,请按照坐标系的范围给出,此为3857的坐标系范围        
	url: picUrl+"?" + Math.random() // 图层服务 url
});

'$store.state.floorDetailObj': function (newVal, oldVal) {
      
		if (this.floorObj ) {
			var nowUrl = "";
			if(this.floorObj.floorAreaImg){
					 nowUrl = api.forent_url.pic_url + "/floorImage/" + this.floorObj.floorAreaImg;
			}else{
				 nowUrl = api.forent_url.pic_url + "/floorImage/blank.png";
			}


			this.addPicToMap(nowUrl, 

			this.$store.state.ZS.MONITOR.currentBuild,
			(this.$store.state.ZS.MONITOR.currentFloor ? this.$store.state.ZS.MONITOR.currentFloor : this.floorObj.floorId)
			);
		}
		if (this.ZS.MONITOR.floor_tooltipWare) this.ZS.MONITOR.floor_tooltipWare.clear();

	},

有图纸的情况下,使用图纸,没图纸的情况下,使用默认图层,一张白纸

纵观这次修改bug,主要原因是因为没有图纸,导致报错,导致代码没法继续往下走,所以,要修改的部分主要集中在图纸不存在的情况下,怎么做捕获错误以及相对应的处理

二、代码执行顺序,页面刚刚打开时候的执行顺序 1、plantu.vue this.getIconConfig();方法 2、floor.vue getFloorListByBuildId方法,这里面的一段代码:that.$store.commit('updateZSCurrentFloorObj', Math.random());触发了plantu里面的watch监听:'$store.state.floorDetailObj',

if (this.floorObj ) {
	var nowUrl = "";
	if(this.floorObj.floorAreaImg){
			 nowUrl = api.forent_url.pic_url + "/floorImage/" + this.floorObj.floorAreaImg;
	}else{
		 nowUrl = api.forent_url.pic_url + "/floorImage/blank.png";
	}
	this.addPicToMap(nowUrl, 
	this.$store.state.ZS.MONITOR.currentBuild,
	(this.$store.state.ZS.MONITOR.currentFloor ? this.$store.state.ZS.MONITOR.currentFloor : this.floorObj.floorId)
	);
}

从而调用了plantu里面的addPicToMap方法,

3、plantu.vue addPicToMap方法 4、plantu.vue loadDevice方法,调用了getEquipmentListByFloorId方法,=》取得了左边设备坐标的信息,传到了表格里面 同时,这里面有个回调函数loadEquipmentPoint 5、plantu.vue loadEquipmentPoint方法 里面的这个方法是that.drawPoint(equip['longitude'], equip['latitude'], iconUrl, equip);在图纸上进行设备标点 6、至此完结。

三、点击搜索,页面代码的执行顺序 1、点击搜索,获取搜索参数,触发父组件G2MapDetail.vue,的searchFloor方法

分2种情况:第一次进来,肯定没有图纸和点设备等信息,所以需要一步步的获取 第二次进来,因为是搜索,区别只是点的设备信息的不同,所以不需要获取楼层信息和平面图信息,只需要获取到点设备的信息即可

ZS.MONITOR.deviceLayer是各种图纸、点等元素的根本载体

1.1、当前缓存里面的buildId不等于参数传过来的buildId,更改缓存里面的buildId,然后执行floor.vue里面的getFloorListByBuildId方法

that.floorArr = data; 取得楼层数据 【注】:楼栋有多个楼层,每个楼层自带自己的平面图url that.$store.commit('updateZSCurrentFloor',data[0].floorId); 存当前楼层的id that.$store.commit('updateZSCurrentFloorObj', Math.random());
触发:'$store.state.floorDetailObj'的改变,在plantu里面有监听这个,这个一旦改变,会对页面的表格数据、平面图、设备点进行重新绘画及数据改变,使用的是方法:addPicToMap(),传三个参数:picUrl, buildId, floorId that.$emit("changeFloorPic", floorData && JSON.stringify(floorData) != '{}' ? floorData : data[0]);

1.2、当前缓存里面的buildId等于参数传过来的buildId,调接口getDeviceListByCondition 说明已经打开过页面,且图纸设备数据都已经渲染过了,所以需要 如果有图纸,先清空,然后再重新绘制, 如果没有图纸,先创建图纸模板容器

if(!_this.$refs.myplantu.ZS.MONITOR.deviceLayer){  //没有图层,先创建
	//创建元素图层
		var elementLayer = new _this.gs2.lys.ElementLayer();
		_this.$refs.myplantu.ZS.MONITOR.floor_g2map.addLayer(elementLayer);
		_this.$refs.myplantu.ZS.MONITOR.deviceLayer = elementLayer; //全局标点使用

		//创建tooltip管理
		_this.$refs.myplantu.ZS.MONITOR.floor_tooltipWare = new _this.gs2.ext.TooltipWare({
			excluseLayerIds: elementLayer.getLayerId(),
			map: _this.$refs.myplantu.ZS.MONITOR.floor_g2map
		});
}else{
	 _this.$refs.myplantu.ZS.MONITOR.deviceLayer.clear();  //有图层,清空
}
_this.$refs.myplantu.ZS.MONITOR.floor_tooltipWare.clear();
_this.$refs.myplantu.loadEquipmentPoint(data.data);

调方法loadEquipmentPoint,加载楼层设备点信息

四、表格需要加个自定义属性prop="laLoopLaPoint" 这种写法不行:

<el-table-column
	prop="laLoopLaPoint"
	label="回路点位"
	:show-overflow-tooltip="true"
	width="100">
</el-table-column>

然后在tableData里面添加自定义属性laLoopLaPoint是不行的 正确写法:

<el-table-column
	label="回路点位"
	:show-overflow-tooltip="true"
	width="100">
	<template slot-scope="scope">
		 {{ scope.row.laLoop + '-'+ scope.row.laPoint}}
	</template>
</el-table-column>