feat:基础组件代码重构

main
liu.shiyi 2 years ago
parent 1115de732c
commit 84a2d76f7f

@ -56,6 +56,9 @@ export default {
} }
}, },
methods: { methods: {
changeStyle (config) {
this.getCurrentTime(config.dateFormat)
},
// //
getCurrentTime (dateFormat) { getCurrentTime (dateFormat) {
if (this.timer) { if (this.timer) {

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

@ -48,7 +48,11 @@ export default {
}, },
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: {} methods: {
// changeStyle
changeStyle () {
}
}
} }
</script> </script>

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

@ -58,17 +58,12 @@ export default {
} }
} }
}, },
buildOption (config, data) { dataFormatting (config, data) {
// //
if (config.dataSource.businessKey) { if (config.dataSource.businessKey) {
config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据' config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
} }
return config return config
},
updateData () {
this.getCurrentOption().then(({ data, config }) => {
this.config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
})
} }
} }
} }

@ -50,7 +50,11 @@ export default {
computed: {}, computed: {},
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: {} methods: {
// changeStyle
changeStyle () {
}
}
} }
</script> </script>

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

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

@ -14,6 +14,7 @@
:header-cell-style="headerCellStyle" :header-cell-style="headerCellStyle"
:cell-style="cellStyle" :cell-style="cellStyle"
:row-class-name="tableRowClassName" :row-class-name="tableRowClassName"
@row-click="rowClick"
> >
<el-table-column <el-table-column
v-for="(col, index) in config.option.columnData" v-for="(col, index) in config.option.columnData"
@ -112,6 +113,10 @@ export default {
this.initStyle() this.initStyle()
}, },
methods: { methods: {
//
rowClick (row) {
this.linkage(row)
},
initStyle () { initStyle () {
if (this.customTheme === 'custom') { if (this.customTheme === 'custom') {
this.headerCellStyleToObj() this.headerCellStyleToObj()
@ -174,7 +179,7 @@ export default {
tableRowClassName ({ row, rowIndex }) { tableRowClassName ({ row, rowIndex }) {
return rowIndex % 2 === 0 ? `even-row${this.config.code}` : `odd-row${this.config.code}` 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 config.option.tableData = data?.data
const filteredData = {} const filteredData = {}
const columnData = data?.columnData || {} const columnData = data?.columnData || {}
@ -192,16 +197,6 @@ export default {
} }
return config 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 () { headerCellStyleToObj () {
const str = this.themeJson.themeCss const str = this.themeJson.themeCss

@ -36,18 +36,12 @@ export default {
this.chartInit() this.chartInit()
}, },
methods: { methods: {
buildOption (config, data) { dataFormatting (config, data) {
// //
if (config.dataSource.businessKey) { if (config.dataSource.businessKey) {
config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据' config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
} }
return config return config
},
//
updateData () {
this.getCurrentOption().then(({ data, config }) => {
this.config.customize.title = data && data.data && data.data.length ? data.data[0][config.dataSource.metricField] : '暂无数据'
})
} }
} }
} }

@ -83,10 +83,7 @@ export default {
} }
}, },
mounted () { mounted () {
this.config.endTime = this.config.endTime this.changeStyle()
? new Date(this.config.endTime).getTime()
: new Date().getTime() + 3 * 3600 * 1000 * 24 - 1000
this.getTime()
}, },
// //
destroyed () { destroyed () {
@ -96,6 +93,12 @@ export default {
}, },
methods: { 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 () { getTime () {
if (this.timer) { if (this.timer) {
clearInterval(this.timer) clearInterval(this.timer)

@ -48,7 +48,11 @@ export default {
}, },
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: {} methods: {
// changeStyle
changeStyle () {
}
}
} }
</script> </script>

@ -77,7 +77,11 @@ export default {
watch: {}, watch: {},
mounted () {}, mounted () {},
methods: {} methods: {
// changeStyle
changeStyle () {
}
}
} }
</script> </script>

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

Loading…
Cancel
Save