Browse Source

解决统计图无法下载

FinalYu 2 years ago
parent
commit
d0f561a606

+ 33 - 13
chuanyi_client2/src/utils/luckysheettool.js

@@ -1,3 +1,5 @@
+import {showAlertWin} from "@/utils/cqcy";
+
 function setCellSize(l, e, t, o) {
     const {
         cs: r,
@@ -25,7 +27,9 @@ export function insertLuckysheetEChart({
                                            optionData: o,
                                            echarts: r,
                                            luckysheet: c,
-                                           $: n
+                                           $: n,
+                                           _self: _self,
+                                           flag: flag
                                        }) {
     if (!e.option || !t) return;
     const [s, i] = e.pos, u = e.className, f = e.option, {
@@ -38,7 +42,15 @@ export function insertLuckysheetEChart({
         g = [],
         h = [];
     if (a.mc) {
-        if (!String(a.mc.cs) || !String(a.mc.rs)) return void console.error("无效单元");
+        if (!String(a.mc.cs) || !String(a.mc.rs)) {
+            if (_self) {
+                _self.$message({
+                    message: '无效单元!',
+                    type: 'error'
+                })
+            }
+            return void console.error("无效单元");
+        }
         for (; b < a.mc.rs;) g.push(s + b++);
         for (; y < a.mc.cs;) h.push(i + y++)
     } else g.push(s), h.push(i);
@@ -48,10 +60,15 @@ export function insertLuckysheetEChart({
             .reduce((l, e) => l + e, 0),
         w = Object.values(c.getRowHeight(g))
             .reduce((l, e) => l + e, 0);
-    if (j < 80 || w < 80) return void console.error(`单元[${s},${i}]不满足: width >= 80 && height >= 80,调整大小后重试!`);
+    if (j < 80 || w < 80) {
+        if (_self) {
+            luckysheet.cancelRangeMerge()
+            showAlertWin(_self, '所选单元格不满足宽度大于80(默认情况下至少3格)或者高度大于80(默认情况下至少5格),请调整大小后重试!')
+        }
+        return void console.error(`单元[${s},${i}]不满足: width >= 80 && height >= 80,调整大小后重试!`);
+    }
     let x = `<div class="${u}" style="width: ${j}px;height: ${w}px;position: absolute;z-index: 1000;left: ${p}px;top: ${v}px;"></div>`;
-    n(l + " #luckysheet-cell-main")
-        .append(x);
+    n(l + " #luckysheet-cell-main").append(x);
     let S = r.init(document.getElementsByClassName(u)[0]);
     S.setOption(f);
     let k = S.getConnectedDataURL({
@@ -59,12 +76,15 @@ export function insertLuckysheetEChart({
         pixelRatio: 1,
         backgroundColor: "#ffffff"
     });
-    // c.insertImage(k, {
-    //     rowIndex: s,
-    //     colIndex: i,
-    //     cellSize: setCellSize(o, s, i, c),
-    //     success: function () {
-    //         console.log("插入成功")
-    //     }
-    // })
+    if (flag) {
+        n('.' + u).css('display', 'none')
+        c.insertImage(k, {
+            rowIndex: s,
+            colIndex: i,
+            cellSize: setCellSize(o, s, i, c),
+            success: function () {
+                console.log("插入成功")
+            }
+        })
+    }
 }

+ 20 - 10
chuanyi_client2/src/views/my_report/index.vue

@@ -903,9 +903,12 @@ export default {
         'tableDataDtoChList': params,
         'showType': tableData.showType
       }
-      if (this.reportForm && this.reportForm.reportDate && this.reportForm.reportDate.length > 0) {
+      if (this.reportForm.reportDate && this.reportForm.reportDate.length > 0) {
         p.startBelongTime = this.reportForm.reportDate[0]
         p.endBelongTime = this.reportForm.reportDate[1]
+      } else {
+        p.startBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 08:00:00'
+        p.endBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 18:00:00'
       }
 
       this.getTableData(p, (res) => {
@@ -977,26 +980,30 @@ export default {
     },
     /** 向 Excel 插入图表 */
     insertEChartInfo(chart) {
+      let _self = this
       console.log(chart)
       let info = chart.info
       let itemList = chart.item
-      let groupId = null
       let itemArr = []
       for (let i in itemList) {
         let temp = itemList[i]
-        if (i == 0) groupId = temp.itemGroupId
         itemArr.push({
+          'itemGroupId': temp.itemGroupId,
           'id': temp.id,
-          'itemName': temp.itemName,
-          // 'dataModelId': temp.rule.id
+          'itemName': temp.itemName
         })
       }
       let params = {
         'type': info.option.series[0].type,
-        'itemGroup': {
-          'id': groupId,
-          'itemList': itemArr
-        }
+        'chartTimeType': this.reportForm.reportValueFormat,
+        'tableDataDtoChList': itemArr
+      }
+      if (this.reportForm.reportDate && this.reportForm.reportDate.length > 0) {
+        params.startBelongTime = this.reportForm.reportDate[0]
+        params.endBelongTime = this.reportForm.reportDate[1]
+      } else {
+        params.startBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 08:00:00'
+        params.endBelongTime = getNowFormatDate('yyyy-MM-dd') + ' 18:00:00'
       }
       this.getChartData(params, (res) => {
         let result = (res instanceof Array) ? res : []
@@ -1034,6 +1041,7 @@ export default {
           const sheet = luckysheet.getLuckysheetfile()[0]
           let optionData = sheet.data
           try {
+            let flag = true
             insertLuckysheetEChart({
               selector: '#luckysheet',
               info,
@@ -1041,7 +1049,9 @@ export default {
               optionData,
               echarts,
               luckysheet,
-              $
+              $,
+              _self,
+              flag
             })
           } catch (e) {
             console.log(999, e == 'echarts is not defined')

+ 3 - 1
chuanyi_client2/src/views/report_template/index.vue

@@ -881,6 +881,7 @@ export default {
     /** 向 Excel 插入图表 */
     insertEChartTool(info, flag, item, legendType) {
       let _this = this
+      let _self = this
       setTimeout(() => {
         const sheet = luckysheet.getLuckysheetfile()[0]
         let optionData = sheet.data
@@ -892,7 +893,8 @@ export default {
             optionData,
             echarts,
             luckysheet,
-            $
+            $,
+            _self
           })
         } catch (e) {
           console.error(e)

+ 5 - 1
chuanyi_client2/src/views/run_config/index.vue

@@ -1137,6 +1137,7 @@ export default {
     },
     /** 向 Excel 插入图表 */
     insertEChartInfo(chart) {
+      let _self = this
       let info = chart.info
       let itemList = chart.item
       let itemArr = []
@@ -1198,6 +1199,7 @@ export default {
           const sheet = luckysheet.getLuckysheetfile()[0]
           let optionData = sheet.data
           try {
+            let flag = true
             insertLuckysheetEChart({
               selector: '#luckysheet',
               info,
@@ -1205,7 +1207,9 @@ export default {
               optionData,
               echarts,
               luckysheet,
-              $
+              $,
+              _self,
+              flag
             })
           } catch (e) {
             console.log(999, e == 'echarts is not defined')