Ver código fonte

feat:基础组件代码重构

liu.shiyi 2 anos atrás
pai
commit
84a2d76f7f

+ 3 - 0
data-room-ui/packages/BasicComponents/CurrentTime/index.vue

@@ -56,6 +56,9 @@ export default {
     }
   },
   methods: {
+    changeStyle (config) {
+      this.getCurrentTime(config.dateFormat)
+    },
     // 实时显示当前系统时间
     getCurrentTime (dateFormat) {
       if (this.timer) {

+ 1 - 10
data-room-ui/packages/BasicComponents/DigitalFlop/index.vue

@@ -94,10 +94,9 @@ export default {
   },
   watch: {},
   mounted () {
-    this.chartInit()
   },
   methods: {
-    buildOption (config, data) {
+    dataFormatting (config, data) {
       let dataList = ''
       if (data.data instanceof Array) {
         dataList = config.dataSource.dimensionField
@@ -111,14 +110,6 @@ export default {
         data: dataList
       }
       return config
-    },
-    updateData () {
-      this.getCurrentOption().then(({ data, config }) => {
-        if (data.success) {
-          const _config = this.buildOption(config, data)
-          this.config.option.data = _config.option.data
-        }
-      })
     }
   }
 }

+ 5 - 1
data-room-ui/packages/BasicComponents/HorizontalLine/index.vue

@@ -48,7 +48,11 @@ export default {
   },
   watch: {},
   mounted () {},
-  methods: {}
+  methods: {
+    // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错
+    changeStyle () {
+    }
+  }
 }
 </script>
 

+ 4 - 1
data-room-ui/packages/BasicComponents/IframeChart/index.vue

@@ -42,9 +42,12 @@ export default {
   },
   watch: {},
   mounted () {
-    this.newUrl = this.replaceUrlVariables(this.config.url)
+    this.changeStyle()
   },
   methods: {
+    changeStyle (config) {
+      this.newUrl = this.replaceUrlVariables(this.config.url)
+    },
     replaceUrlVariables (url) {
       const variableRegex = /\${([A-Za-z0-9_.]+)}/g
       const variables = {}

+ 1 - 6
data-room-ui/packages/BasicComponents/LinkChart/index.vue

@@ -58,17 +58,12 @@ export default {
         }
       }
     },
-    buildOption (config, data) {
+    dataFormatting (config, data) {
       // 文本数据配置原则:选择数据集则以后端返回的数据为主,否则以设置面板中标题设置为准
       if (config.dataSource.businessKey) {
         config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
       }
       return config
-    },
-    updateData () {
-      this.getCurrentOption().then(({ data, config }) => {
-        this.config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
-      })
     }
   }
 }

+ 5 - 1
data-room-ui/packages/BasicComponents/Picture/index.vue

@@ -50,7 +50,11 @@ export default {
   computed: {},
   watch: {},
   mounted () {},
-  methods: {}
+  methods: {
+    // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错
+    changeStyle () {
+    }
+  }
 }
 </script>
 

+ 1 - 8
data-room-ui/packages/BasicComponents/ScreenScrollBoard/index.vue

@@ -48,7 +48,7 @@ export default {
     this.chartInit()
   },
   methods: {
-    buildOption (config, data) {
+    dataFormatting (config, data) {
       const header = []
       const dataList = []
       const alignList = []
@@ -105,13 +105,6 @@ export default {
         align: [...alignList]
       }
       return config
-    },
-    updateData () {
-      this.getCurrentOption().then(({ data, config }) => {
-        const _config = this.buildOption(config, data)
-        this.option.data = _config.option.data
-        this.updateKey++
-      })
     }
 
   }

+ 1 - 9
data-room-ui/packages/BasicComponents/ScreenScrollRanking/index.vue

@@ -47,10 +47,9 @@ export default {
   watch: {
   },
   mounted () {
-    this.chartInit()
   },
   methods: {
-    buildOption (config, data) {
+    dataFormatting (config, data) {
       const dataSourseList = []
       data.data.forEach(item => {
         dataSourseList.push({ name: item[config.dataSource.dimensionField || 'name'], value: item[config.dataSource.metricField || 'sum(num)'] })
@@ -60,13 +59,6 @@ export default {
         data: dataSourseList
       }
       return config
-    },
-    updateData () {
-      this.getCurrentOption().then(({ data, config }) => {
-        const _config = this.buildOption(config, data)
-        this.option.data = _config.option.data
-        this.updateKey++
-      })
     }
 
   }

+ 6 - 11
data-room-ui/packages/BasicComponents/Tables/index.vue

@@ -14,6 +14,7 @@
       :header-cell-style="headerCellStyle"
       :cell-style="cellStyle"
       :row-class-name="tableRowClassName"
+      @row-click="rowClick"
     >
       <el-table-column
         v-for="(col, index) in config.option.columnData"
@@ -112,6 +113,10 @@ export default {
     this.initStyle()
   },
   methods: {
+    // 表格点击事件
+    rowClick (row) {
+      this.linkage(row)
+    },
     initStyle () {
       if (this.customTheme === 'custom') {
         this.headerCellStyleToObj()
@@ -174,7 +179,7 @@ export default {
     tableRowClassName ({ row, rowIndex }) {
       return rowIndex % 2 === 0 ? `even-row${this.config.code}` : `odd-row${this.config.code}`
     },
-    buildOption (config, data) {
+    dataFormatting (config, data) {
       config.option.tableData = data?.data
       const filteredData = {}
       const columnData = data?.columnData || {}
@@ -192,16 +197,6 @@ export default {
       }
       return config
     },
-    // 更新数据
-    updateData () {
-      this.getCurrentOption().then(({ data, config }) => {
-        if (data.success) {
-          this.config.option.tableData = data?.data
-          this.config.option.columnData = data?.columnData || {}
-          this.$refs.table.doLayout()
-        }
-      })
-    },
     // 将样式字符串转成对象, 用于自定义主题,表格头部样式
     headerCellStyleToObj () {
       const str = this.themeJson.themeCss

+ 1 - 7
data-room-ui/packages/BasicComponents/Texts/index.vue

@@ -36,18 +36,12 @@ export default {
     this.chartInit()
   },
   methods: {
-    buildOption (config, data) {
+    dataFormatting (config, data) {
       // 文本数据配置原则:选择数据集则以后端返回的数据为主,否则以设置面板中标题设置为准
       if (config.dataSource.businessKey) {
         config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
       }
       return config
-    },
-    // 仅更新数据
-    updateData () {
-      this.getCurrentOption().then(({ data, config }) => {
-        this.config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
-      })
     }
   }
 }

+ 7 - 4
data-room-ui/packages/BasicComponents/TimeCountDown/index.vue

@@ -83,10 +83,7 @@ export default {
     }
   },
   mounted () {
-    this.config.endTime = this.config.endTime
-      ? new Date(this.config.endTime).getTime()
-      : new Date().getTime() + 3 * 3600 * 1000 * 24 - 1000
-    this.getTime()
+    this.changeStyle()
   },
   // 销毁定时器
   destroyed () {
@@ -96,6 +93,12 @@ export default {
   },
 
   methods: {
+    changeStyle (config) {
+      this.config.endTime = this.config.endTime
+        ? new Date(this.config.endTime).getTime()
+        : new Date().getTime() + 3 * 3600 * 1000 * 24 - 1000
+      this.getTime()
+    },
     getTime () {
       if (this.timer) {
         clearInterval(this.timer)

+ 5 - 1
data-room-ui/packages/BasicComponents/VerticalLine/index.vue

@@ -48,7 +48,11 @@ export default {
   },
   watch: {},
   mounted () {},
-  methods: {}
+  methods: {
+    // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错
+    changeStyle () {
+    }
+  }
 }
 </script>
 

+ 5 - 1
data-room-ui/packages/BasicComponents/Video/index.vue

@@ -77,7 +77,11 @@ export default {
 
   watch: {},
   mounted () {},
-  methods: {}
+  methods: {
+    // 由于静态组件没有混入公共函数,所以需要定义一个changeStyle方法,以免报错
+    changeStyle () {
+    }
+  }
 }
 </script>
 

+ 1 - 1
data-room-ui/packages/js/mixins/commonMixins.js

@@ -24,7 +24,7 @@ export default {
     }
   },
   mounted () {
-    if (!['digitalFlop', 'screenScrollRanking', 'screenScrollBoard', 'tables'].includes(this.config.type)) {
+    if (!['tables'].includes(this.config.type)) {
       this.chartInit()
     }
     this.watchCacheData()