Browse Source

加了点注释

mw_666 3 years ago
parent
commit
9c25b605c9
1 changed files with 26 additions and 54 deletions
  1. 26 54
      src/views/report/ExportExcel.vue

+ 26 - 54
src/views/report/ExportExcel.vue

@@ -69,19 +69,14 @@
 		data() {
 			const that = this;
 			return {
-				single:false,
-				rqChecked:true,
-				sjChecked:true,
-				checkList: [],
-				tableIdArr: [], //放checkbox的id数组
-				tableData: [],
-				value1: [],
-				inputVal: [],
-				inputInterval: 1800,
-				options: [],
-				value2: [],
-				startTs: [],
-				endTs: [],
+				single:false,//单击导出状态【点击后,用于判断其状态,为true时,loading显示】
+				rqChecked:true,//日期单击checkbox状态【为true时,下方任意日期选择与当前选择同步】
+				sjChecked:true,//时间间隔checkbox状态【为true时,下方任意时间选择与当前选择同步】
+				tableData: [],//表格数据
+				value1: [],//日期数组,默认一个月的,当用户改变某一个时,找到对应下标去改数据
+				inputVal: [],//时间同上
+				startTs: [],//起始时间,通过下标去找对应的时间
+				endTs: [],//结束时间
 				muBan: {
 					type1: ['数据时间', 'scada风速(m/s)', 'scada功率(kW)', '是否故障(故障=1,不故障=0)', '是否限电(限电=1,不限电=0)'],
 					type2: [
@@ -90,19 +85,19 @@
 						['数据时间', '轮毂高度平均风速(m/s)', '轮毂高度平均风向(°)', '温度(℃)', '压强(hPa)', '湿度(%)']
 					],
 				},
-				templateId: 1,
-				stations: [],
-				paths: [],
-				pathName: [],
+				templateId: 1,//模板默认为1
+				stations: [],//场站名
+				paths: [],//excel的所有数据,最终给zip传
+				pathName: [],//excel的名字
 				zipNames: [],
-				tempArrayS: [],
+				tempArrayS: [],//模板2时,遍历里面的数据
 			}
 		},
 		created() {
 			this.tableVal();
 		},
 		methods: {
-			value1Change(index){
+			value1Change(index){//日期数组,默认一个月的,当用户改变某一个时,找到对应下标去改数据
 				if(this.rqChecked){
 					var date = this.value1[index];
 					this.value1 = [];
@@ -127,12 +122,13 @@
 			sjCheck(){
 				this.sjChecked=event.target.checked
 			},
-			typeClick(a){
+			typeClick(a){//模板切换,改变按钮颜色
 				this.templateId = a;
 			},
-			thisExport(index) {
+			thisExport(index) {//当前导出,index为下标
 				let that = this;
 				that.single = true;
+				// 下面的是通过下标找到对应的数据,请求ajax
 				that.time(index, that.value1[index]);
 				that.stations[index] = that.tableData[index].value;
 				that.allExportF(0, index);
@@ -144,30 +140,19 @@
 					subUrl: "export/databases",
 					success(res) {
 						if (res.code === 200) {
-							const arr = [];
-							const arr2 = [];
 							const arr3 = [];
 							const arr4 = [];
 							var data = []; //项目列表
 							res.data.forEach((item,index) => {
 								const value = Object.keys(item)[0];
-								arr.push({
-									value: value,
-									label: item[value]
-								})
-								arr2.push(value + '/' + item[value]);
 								arr3.push(value);
 								arr4.push(item[value]);
-
 								data.push({
 									fdc: item[value],
 									value: value,
 								});
 								that.inputVal.push(1800);
-								that.checkList.push(index);
 							})
-							that.options = arr;
-							that.value2 = arr2;
 							that.stations = arr3;
 							that.zipNames = arr4;
 							that.tableData = data;
@@ -191,16 +176,13 @@
 					this.time(index, [start, end]);
 				})
 			},
-			handleCommand(command) {
-				this.templateId = command;
-			},
-			formatJson(filterVal, jsonData) {
+			formatJson(filterVal, jsonData) {//模板1时,转数据格式
 				return jsonData.map(v => filterVal.map(j => v[j]));
 			},
-			allExport() {
+			allExport() {//一键导出
 				this.allExportF(0);
 			},
-			allExportF(_index, thisIndex) {
+			allExportF(_index, thisIndex) {//_index递归递增,thisIndex单击导出【下标】
 				BASE.showLoading({text:'正在导出,请耐心等待...'});
 				const that = this;
 				if (that.stations[_index]) {
@@ -216,13 +198,13 @@
 						},
 						success(res) {
 							if (res.code == 200) {
-								if (thisIndex!=undefined) {
-									if (that.templateId == 1) {
+								if (thisIndex!=undefined) {//一键导出
+									if (that.templateId == 1) {//模板1
 										that.export(res.data, 0, that.zipNames[thisIndex]);
-									} else if (that.templateId == 2) {
+									} else if (that.templateId == 2) {//模板2
 										that.exportMuban2(res.data, 0, that.zipNames[thisIndex]);
 									}
-								} else {
+								} else {//单击导出
 									if (that.templateId == 1) {
 										that.export(res.data, 0, that.zipNames[_index], ++_index);
 									} else if (that.templateId == 2) {
@@ -235,6 +217,7 @@
 				}
 			},
 			export (data, _index, zipName, deepIndex) {
+				// deepIndex判断单击或一键
 				const that = this;
 				let tHeader = that.muBan['type' + that.templateId];
 				var dataKey = Object.keys(data);
@@ -253,7 +236,6 @@
 						tempObject = {};
 					})
 
-					// 上面的index、nickName、name是tableData里对象的属性key值
 					data[key][0].forEach((ele, index) => {
 						filterVal.push(index);
 					});
@@ -304,7 +286,6 @@
 						tempObject = {};
 					})
 
-					// 上面的index、nickName、name是tableData里对象的属性key值
 					that.tempArrayS.push(tempArray);
 					_index++;
 					if (dataKey.length == that.tempArrayS.length) {
@@ -397,19 +378,10 @@
 						}
 					})
 			},
-			time(index, val) {
+			time(index, val) {//时间转时间戳
 				this.startTs[index] = Date.parse(new Date(val[0]));
 				this.endTs[index] = Date.parse(new Date(val[1]) + 86400000);
 			},
-			changeSelect(val) {
-				this.stations = [];
-				this.zipNames = [];
-				val.forEach(ele => {
-					var key = ele.split('/');
-					this.stations.push(key[0]);
-					this.zipNames.push(key[1]);
-				})
-			},
 		},
 	}
 </script>