|
@@ -32,12 +32,11 @@ const getSheetApi = () => {
|
|
|
for (let i in reportChartList) {
|
|
|
insertEChartInfo(reportChartList[i]);
|
|
|
}
|
|
|
-
|
|
|
// 绘制基础数据项
|
|
|
drawBaseInfo(baseItem)
|
|
|
// 绘制数据值
|
|
|
drawTableData(reportTableItemList,
|
|
|
- reportTableType, json.data)
|
|
|
+ reportTableType, json.data, tableData.data[0].data)
|
|
|
task = setInterval(function() {
|
|
|
if (taskStatus) {
|
|
|
let status = true;
|
|
@@ -149,96 +148,179 @@ function drawBaseInfo(baseData) {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-function drawTableData(tableItemList, type, tableInfo) {
|
|
|
- if (!tableItemList || tableItemList.length == 0) {
|
|
|
- updateLocalExcelContent()
|
|
|
- return
|
|
|
- }
|
|
|
- // 事件驱动报表
|
|
|
- if (type == 2 || type == 4) {
|
|
|
- tableItemList.forEach((tableItem, i) => {
|
|
|
- if (i == 0) {
|
|
|
- let valueTimeList = tableItem.valueTimeList ? tableItem.valueTimeList.split(',') : []
|
|
|
- valueTimeList = withDateFormatLength(valueTimeList)
|
|
|
- let xAxis = tableItem.xaxis
|
|
|
- let yAxis = tableItem.yaxis - 1
|
|
|
- if (valueTimeList.length == 0) {
|
|
|
- luckysheet.setCellValue(xAxis, yAxis, '')
|
|
|
- } else {
|
|
|
- valueTimeList.forEach((v, j) => {
|
|
|
- luckysheet.setCellValue(xAxis + j, yAxis, v)
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- let valueList = tableItem.valueList ? tableItem.valueList
|
|
|
- .split(',') : []
|
|
|
- let xAxis = tableItem.xaxis
|
|
|
- let yAxis = tableItem.yaxis
|
|
|
- if (valueList.length == 0) {
|
|
|
- luckysheet.setCellValue(xAxis, yAxis, '')
|
|
|
- } else {
|
|
|
- valueList.forEach((v, j) => {
|
|
|
- luckysheet.setCellValue(xAxis + j, yAxis,
|
|
|
- v)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- updateLocalExcelContent()
|
|
|
- return
|
|
|
- }
|
|
|
- // 设备报表
|
|
|
- if (type == 5 || type == 6) {
|
|
|
- tableItemList.forEach((tableItem, i) => {
|
|
|
- let standby = tableItem.standby ? JSON.parse(tableItem.standby) : {}
|
|
|
- let dataIndex = standby.index != null ? standby.index : -1
|
|
|
- let valueList = tableItem.valueList ? tableItem.valueList.split(',') : []
|
|
|
- let xAxis = tableItem.xaxis
|
|
|
- let yAxis = tableItem.yaxis
|
|
|
- // 序号、时间处理
|
|
|
- if (tableItem.timeItemType == 0) { // 序号、开始时间
|
|
|
- let valueIndexList = tableItem.valueIndexList ? tableItem.valueIndexList.split(',') : []
|
|
|
- deviceReportUpdateData('${index}', valueIndexList, false)
|
|
|
- let valueTimeList = tableItem.valueTimeList ? tableItem.valueTimeList.split(',') : []
|
|
|
- valueTimeList = withDateFormatLength(valueTimeList)
|
|
|
- deviceReportUpdateData('${startTime}', valueTimeList, false)
|
|
|
- }
|
|
|
- if (tableItem.timeItemType == 1) { // 结束时间
|
|
|
- let valueTimeList = tableItem.valueTimeList ? tableItem.valueTimeList.split(',') : []
|
|
|
- valueTimeList = withDateFormatLength(valueTimeList)
|
|
|
- deviceReportUpdateData('${stopTime}', valueTimeList, tableInfo.isGenCountTime == 1)
|
|
|
- }
|
|
|
- if (valueList.length == 0) {
|
|
|
- luckysheet.setCellValue(xAxis, yAxis, '')
|
|
|
- } else {
|
|
|
- valueList.forEach((v, j) => {
|
|
|
- luckysheet.setCellValue(xAxis + j, yAxis, v)
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- updateLocalExcelContent()
|
|
|
- return
|
|
|
- }
|
|
|
- // 其余报表信息
|
|
|
- tableItemList.forEach((tableItem, i) => {
|
|
|
- // let standby = tableItem.standby ? JSON.parse(tableItem.standby) :
|
|
|
- // {}
|
|
|
- // let dataIndex = standby.index != null ? standby.index : -1
|
|
|
- let valueList = tableItem.valueList ? tableItem.valueList.split(
|
|
|
- ',') : []
|
|
|
- // let val = (dataIndex == -1 || (dataIndex + 1) > valueList
|
|
|
- // .length) ?
|
|
|
- // cqcyCode['invalidData'] : valueList[dataIndex]
|
|
|
- let xAxis = tableItem.xaxis
|
|
|
- let yAxis = tableItem.yaxis
|
|
|
- if (valueList.length == 0) {
|
|
|
- luckysheet.setCellValue(xAxis, yAxis, '')
|
|
|
+function drawTableData(tableItemList, type, tableInfo, sheData) {
|
|
|
+ // if (!tableItemList || tableItemList.length == 0) {
|
|
|
+ // // this.updateLocalExcelContent();
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // 事件驱动报表
|
|
|
+ if (type == 2 || type == 4) {
|
|
|
+ setSheetDatas(tableItemList, luckysheet, type, null, sheData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 设备报表
|
|
|
+ if (type == 5 || type == 6) {
|
|
|
+ setSheetDatas(tableItemList, luckysheet, type, tableInfo.isGenCountTime, sheData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ setSheetDatas(tableItemList, luckysheet, null, null, sheData);
|
|
|
+}
|
|
|
+
|
|
|
+function setSheetDatas(tableItemList, luckysheet, type, isGenCountTime, sheData) {
|
|
|
+ console.log(type)
|
|
|
+ let arr = initArrays(tableItemList, type, isGenCountTime, sheData)
|
|
|
+
|
|
|
+ console.log("A1:" + toExcelColumn(arr[0].length) + arr.length)
|
|
|
+ setTimeout(function () {
|
|
|
+
|
|
|
+ luckysheet.setRangeValue(arr, {range: "A1:" + toExcelColumn(arr[0].length) + arr.length})
|
|
|
+
|
|
|
+ },100)
|
|
|
+}
|
|
|
+
|
|
|
+Array.min = function(array) {
|
|
|
+ return Math.min.apply(Math, array)
|
|
|
+}
|
|
|
+// 最大值
|
|
|
+Array.max = function (array) {
|
|
|
+ return Math.max.apply(Math, array)
|
|
|
+}
|
|
|
+function initArrays(tableItemList, type, isGenCountTime, sheData) {
|
|
|
+ // 纵向 reportTableType = 1
|
|
|
+ let arr = {}
|
|
|
+ let yAdd = 0;
|
|
|
+ let xAdd = 0;
|
|
|
+ let valueTimeList = null;
|
|
|
+ let startTimes = [];
|
|
|
+ let endTimes = [];
|
|
|
+ for (let i = 0; i < tableItemList.length; i++) {
|
|
|
+ let tableItem = tableItemList[i];
|
|
|
+ let standby = JSON.parse(tableItem.standby)
|
|
|
+ let fieldType = standby.fieldType ? standby.fieldType: 2
|
|
|
+ let valueList = tableItem.valueList ?
|
|
|
+ tableItem.valueList.split(",") : [];
|
|
|
+ let xAxis = tableItem.xaxis;
|
|
|
+ let yAxis = tableItem.yaxis;
|
|
|
+ let xAxis2 = tableItem.yaxis;
|
|
|
+ let yAxis2 = tableItem.xaxis;
|
|
|
+ if (fieldType == 1) {
|
|
|
+ for (var j = 0; j < valueList.length; j++) {
|
|
|
+ arr[(yAxis2 + j)+ "_" + xAxis2] = valueList[j]
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (var j = 0; j < valueList.length; j++) {
|
|
|
+ arr[xAxis + "_" + (yAxis + j)] = valueList[j]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i == 0 && (type == 2 || type == 4)) {
|
|
|
+ valueTimeList = tableItem.valueTimeList
|
|
|
+ ? tableItem.valueTimeList.split(",")
|
|
|
+ : [];
|
|
|
+ valueTimeList = withDateFormatLength(valueTimeList);
|
|
|
+ yAdd = yAxis2
|
|
|
+ }
|
|
|
+ if (type == 5 || type == 6) {
|
|
|
+ yAdd = yAxis2
|
|
|
+ if (i == 0) {
|
|
|
+ xAdd = xAxis2
|
|
|
+ }
|
|
|
+ let valueTimeList = tableItem.valueTimeList
|
|
|
+ ? tableItem.valueTimeList.split(",")
|
|
|
+ : [];
|
|
|
+ valueTimeList = withDateFormatLength(valueTimeList);
|
|
|
+ if (tableItem.timeItemType == 0) {
|
|
|
+ // 开始时间
|
|
|
+ startTimes = withDateFormatLength(valueTimeList);
|
|
|
+
|
|
|
+ }
|
|
|
+ if (tableItem.timeItemType == 1) {
|
|
|
+ // 结束时间
|
|
|
+ endTimes = withDateFormatLength(valueTimeList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let x = 0;
|
|
|
+ let y = 0;
|
|
|
+ for (let key in arr) {
|
|
|
+ let str = key.split("_");
|
|
|
+ if (y < parseInt(str[0])) {
|
|
|
+ y = parseInt(str[0])
|
|
|
+ }
|
|
|
+ if (x < parseInt(str[1])) {
|
|
|
+ x = parseInt(str[1])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let aIndex = isGenCountTime == 1 ? 1: 0;
|
|
|
+ let array = []
|
|
|
+ console.log(sheData)
|
|
|
+ for (var i = 0; i < sheData.length; i++) {
|
|
|
+ let row = sheData[i]
|
|
|
+ for (var j = 0; j < row.length; j++) {
|
|
|
+ if (arr[i + "_" + j]) {
|
|
|
+ row[j] = (arr[i + "_" + j])
|
|
|
+ } else {
|
|
|
+ if (j == yAdd - 1 && (type == 2 || type == 4)) {
|
|
|
+ if (i >= yAdd) {
|
|
|
+
|
|
|
+ row[j] = (valueTimeList[i - yAdd])
|
|
|
+ } else {
|
|
|
+ row[j] = changeValStr(row[j])
|
|
|
+ }
|
|
|
+ } else if (type == 5 || type == 6) {
|
|
|
+ if (i >= yAdd) {
|
|
|
+ if (j == xAdd - 3 - aIndex) {
|
|
|
+ // 序号列
|
|
|
+ row[j] = (i - yAdd < startTimes.length ? i - yAdd + 1 : "")
|
|
|
+ } else if (j == xAdd - 2 - aIndex) {
|
|
|
+ // 开始时间
|
|
|
+ row[j] = (i - yAdd < startTimes.length ? startTimes[i - yAdd] : "")
|
|
|
+ } else if (j == xAdd - 1 - aIndex) {
|
|
|
+ // 开始时间
|
|
|
+ row[j] = (i - yAdd < endTimes.length ? endTimes[i - yAdd] : "")
|
|
|
+ } else if(isGenCountTime == 1 && j == xAdd - 1 && row[j - 2] && row[j - 1]) {
|
|
|
+ // 计算时间
|
|
|
+ const time = calculateMinutes(row[j - 2], row[j - 1]);
|
|
|
+ row[j] = (time)
|
|
|
+ } else {
|
|
|
+ row[j] = changeValStr(row[j])
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ row[j] = changeValStr(row[j])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ row[j] = changeValStr(row[j])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ array.push(row)
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(array)
|
|
|
+ return array
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+function changeValStr(str) {
|
|
|
+ if (str) {
|
|
|
+ if ((str + "").startsWith("${")) {
|
|
|
+ return "";
|
|
|
} else {
|
|
|
- valueList.forEach((v, j) => {
|
|
|
- luckysheet.setCellValue(xAxis + j, yAxis, v)
|
|
|
- })
|
|
|
+ if (str.v && str.v.startsWith("${")) {
|
|
|
+ return "";
|
|
|
+ } else {
|
|
|
+ if (JSON.stringify(str).startsWith("${")) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- updateLocalExcelContent()
|
|
|
+ return str;
|
|
|
+ } else {
|
|
|
+ return str;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function insertEChartInfo(chart) {
|