Эх сурвалжийг харах

fix:修复部分数据集返回数据不统一导致数据渲染异常问题

liu.shiyi 1 жил өмнө
parent
commit
4ceec570fb

+ 20 - 13
data-room-ui/packages/BigScreenDesign/DataViewDialog/index.vue

@@ -83,18 +83,7 @@ export default {
     getDataList (config) {
       this.loading = true
       if (config.type === 'customComponent' && (!config.dataSource.businessKey)) {
-        const list = config.option.data
-        this.columnData = (Object.keys(list[0])).map((key) => {
-          return {
-            aggregate: '',
-            alias: key,
-            originalColumn: key,
-            remark: key,
-            tableName: '',
-            type: 'varchar'
-          }
-        })
-        this.dataList = list
+        this.getDataByOption(config)
         this.loading = false
       } else {
         const params = {
@@ -108,13 +97,31 @@ export default {
         }
         getUpdateChartInfo(params).then(res => {
           this.loading = false
-          this.dataList = res.data || []
+          if (Array.isArray(res.data)) {
+            this.dataList = res.data || []
+          } else {
+            this.getDataByOption(config)
+          }
           this.columnData = res.columnData || []
         }).catch(err => { console.log(err) }).finally(() => {
           this.loading = false
         })
       }
     },
+    getDataByOption (config) {
+      const list = config.option.data || []
+      this.columnData = list && list.length ? (Object.keys(list[0])).map((key) => {
+        return {
+          aggregate: '',
+          alias: key,
+          originalColumn: key,
+          remark: key,
+          tableName: '',
+          type: 'varchar'
+        }
+      }) : []
+      this.dataList = list
+    },
     getLabel (col) {
       return col.remark || col.originalColumn
     },