2021-04-25 18:03:13 +08:00
|
|
|
<template>
|
2021-05-13 17:15:07 +08:00
|
|
|
<div ref="tableContainer" :style="bg_class">
|
2021-04-26 12:35:47 +08:00
|
|
|
<p v-show="title_show" ref="title" :style="title_class">{{ chart.title }}</p>
|
2021-04-25 18:03:13 +08:00
|
|
|
<ux-grid
|
|
|
|
ref="plxTable"
|
|
|
|
size="mini"
|
|
|
|
style="width: 100%;"
|
|
|
|
:height="height"
|
|
|
|
:checkbox-config="{highlight: true}"
|
|
|
|
:width-resize="true"
|
2021-04-26 15:20:55 +08:00
|
|
|
:header-row-style="table_header_class"
|
|
|
|
:row-style="getRowStyle"
|
|
|
|
class="table-class"
|
2021-06-09 17:21:17 +08:00
|
|
|
:class="chart.id"
|
2021-04-26 16:56:22 +08:00
|
|
|
show-summary
|
|
|
|
:summary-method="summaryMethod"
|
2021-04-25 18:03:13 +08:00
|
|
|
>
|
|
|
|
<ux-table-column
|
|
|
|
v-for="field in fields"
|
2021-05-12 12:19:24 +08:00
|
|
|
:key="field.dataeaseName"
|
|
|
|
:field="field.dataeaseName"
|
2021-04-25 18:03:13 +08:00
|
|
|
:resizable="true"
|
|
|
|
sortable
|
|
|
|
:title="field.name"
|
|
|
|
>
|
|
|
|
<!-- <template slot="header">-->
|
|
|
|
<!-- <span>{{ field.name }}</span>-->
|
|
|
|
<!-- </template>-->
|
|
|
|
</ux-table-column>
|
|
|
|
</ux-grid>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-04-26 12:35:47 +08:00
|
|
|
import { hexColorToRGBA } from '../../chart/util'
|
2021-05-18 16:38:24 +08:00
|
|
|
import eventBus from '@/components/canvas/utils/eventBus'
|
2021-04-26 12:35:47 +08:00
|
|
|
|
2021-04-25 18:03:13 +08:00
|
|
|
export default {
|
|
|
|
name: 'TableNormal',
|
|
|
|
props: {
|
|
|
|
chart: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
filter: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: function() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
fields: [],
|
2021-04-26 16:56:22 +08:00
|
|
|
height: 'auto',
|
2021-04-26 12:35:47 +08:00
|
|
|
title_class: {
|
2021-05-06 11:08:57 +08:00
|
|
|
margin: '0 0',
|
2021-04-26 12:35:47 +08:00
|
|
|
width: '100%',
|
|
|
|
fontSize: '18px',
|
|
|
|
color: '#303133',
|
|
|
|
textAlign: 'left',
|
2021-06-29 12:09:37 +08:00
|
|
|
fontStyle: 'normal',
|
|
|
|
fontWeight: 'normal'
|
2021-04-26 12:35:47 +08:00
|
|
|
},
|
|
|
|
bg_class: {
|
|
|
|
background: hexColorToRGBA('#ffffff', 0)
|
|
|
|
},
|
2021-04-26 15:20:55 +08:00
|
|
|
table_header_class: {
|
|
|
|
fontSize: '12px',
|
|
|
|
color: '#606266',
|
2021-06-28 16:21:54 +08:00
|
|
|
background: '#e8eaec',
|
|
|
|
height: '36px'
|
2021-04-26 15:20:55 +08:00
|
|
|
},
|
|
|
|
table_item_class: {
|
|
|
|
fontSize: '12px',
|
|
|
|
color: '#606266',
|
2021-06-28 16:21:54 +08:00
|
|
|
background: '#ffffff',
|
|
|
|
height: '36px'
|
2021-04-26 15:20:55 +08:00
|
|
|
},
|
|
|
|
table_item_class_stripe: {
|
|
|
|
fontSize: '12px',
|
|
|
|
color: '#606266',
|
2021-06-28 16:21:54 +08:00
|
|
|
background: '#ffffff',
|
|
|
|
height: '36px'
|
2021-04-26 15:20:55 +08:00
|
|
|
},
|
2021-04-26 12:35:47 +08:00
|
|
|
title_show: true
|
2021-04-25 18:03:13 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2021-06-30 12:42:09 +08:00
|
|
|
chart: function() {
|
2021-04-25 18:03:13 +08:00
|
|
|
this.init()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
2021-05-18 16:38:24 +08:00
|
|
|
// 监听元素变动事件
|
|
|
|
eventBus.$on('resizing', (componentId) => {
|
|
|
|
this.chartResize()
|
|
|
|
})
|
2021-04-25 18:03:13 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
init() {
|
2021-06-30 12:42:09 +08:00
|
|
|
this.resetHeight()
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.initData()
|
|
|
|
this.calcHeightDelay()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
initData() {
|
2021-04-26 12:35:47 +08:00
|
|
|
const that = this
|
2021-04-26 17:38:33 +08:00
|
|
|
let datas = []
|
|
|
|
if (this.chart.data) {
|
|
|
|
this.fields = JSON.parse(JSON.stringify(this.chart.data.fields))
|
|
|
|
datas = JSON.parse(JSON.stringify(this.chart.data.tableRow))
|
|
|
|
} else {
|
|
|
|
this.fields = []
|
|
|
|
datas = []
|
|
|
|
}
|
2021-04-25 18:03:13 +08:00
|
|
|
this.$refs.plxTable.reloadData(datas)
|
2021-06-07 15:42:24 +08:00
|
|
|
this.$nextTick(() => {
|
|
|
|
this.initStyle()
|
|
|
|
})
|
2021-04-25 18:49:57 +08:00
|
|
|
window.onresize = function() {
|
2021-06-30 12:42:09 +08:00
|
|
|
that.calcHeightDelay()
|
2021-04-25 18:49:57 +08:00
|
|
|
}
|
|
|
|
},
|
2021-06-30 12:42:09 +08:00
|
|
|
calcHeightRightNow() {
|
2021-06-19 11:11:58 +08:00
|
|
|
this.$nextTick(() => {
|
2021-06-30 12:42:09 +08:00
|
|
|
if (this.$refs.tableContainer) {
|
|
|
|
const currentHeight = this.$refs.tableContainer.offsetHeight
|
|
|
|
const tableMaxHeight = currentHeight - this.$refs.title.offsetHeight
|
|
|
|
let tableHeight
|
|
|
|
if (this.chart.data) {
|
|
|
|
tableHeight = (this.chart.data.tableRow.length + 2) * 36
|
|
|
|
} else {
|
|
|
|
tableHeight = 0
|
|
|
|
}
|
|
|
|
if (tableHeight > tableMaxHeight) {
|
|
|
|
this.height = tableMaxHeight + 'px'
|
|
|
|
} else {
|
|
|
|
this.height = 'auto'
|
2021-05-18 16:38:24 +08:00
|
|
|
}
|
2021-06-30 12:42:09 +08:00
|
|
|
}
|
2021-05-18 16:38:24 +08:00
|
|
|
})
|
2021-04-26 12:35:47 +08:00
|
|
|
},
|
2021-06-30 12:42:09 +08:00
|
|
|
calcHeightDelay() {
|
|
|
|
setTimeout(() => {
|
|
|
|
this.calcHeightRightNow()
|
|
|
|
}, 100)
|
|
|
|
},
|
2021-04-26 12:35:47 +08:00
|
|
|
initStyle() {
|
2021-04-26 15:20:55 +08:00
|
|
|
if (this.chart.customAttr) {
|
|
|
|
const customAttr = JSON.parse(this.chart.customAttr)
|
|
|
|
if (customAttr.color) {
|
|
|
|
this.table_header_class.color = customAttr.color.tableFontColor
|
|
|
|
this.table_header_class.background = hexColorToRGBA(customAttr.color.tableHeaderBgColor, customAttr.color.alpha)
|
|
|
|
this.table_item_class.color = customAttr.color.tableFontColor
|
|
|
|
this.table_item_class.background = hexColorToRGBA(customAttr.color.tableItemBgColor, customAttr.color.alpha)
|
|
|
|
}
|
|
|
|
if (customAttr.size) {
|
|
|
|
this.table_header_class.fontSize = customAttr.size.tableTitleFontSize + 'px'
|
|
|
|
this.table_item_class.fontSize = customAttr.size.tableItemFontSize + 'px'
|
2021-06-28 16:21:54 +08:00
|
|
|
this.table_header_class.height = customAttr.size.tableTitleHeight + 'px'
|
|
|
|
this.table_item_class.height = customAttr.size.tableItemHeight + 'px'
|
2021-04-26 15:20:55 +08:00
|
|
|
}
|
|
|
|
this.table_item_class_stripe = JSON.parse(JSON.stringify(this.table_item_class))
|
2021-06-21 10:54:59 +08:00
|
|
|
// 暂不支持斑马纹
|
|
|
|
// if (customAttr.color.tableStripe) {
|
|
|
|
// // this.table_item_class_stripe.background = hexColorToRGBA(customAttr.color.tableItemBgColor, customAttr.color.alpha - 40)
|
|
|
|
// if (this.chart.customStyle) {
|
|
|
|
// const customStyle = JSON.parse(this.chart.customStyle)
|
|
|
|
// if (customStyle.background) {
|
|
|
|
// this.table_item_class_stripe.background = hexColorToRGBA(customStyle.background.color, customStyle.background.alpha)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2021-04-26 15:20:55 +08:00
|
|
|
}
|
2021-04-26 12:35:47 +08:00
|
|
|
if (this.chart.customStyle) {
|
|
|
|
const customStyle = JSON.parse(this.chart.customStyle)
|
|
|
|
if (customStyle.text) {
|
|
|
|
this.title_show = customStyle.text.show
|
|
|
|
this.title_class.fontSize = customStyle.text.fontSize + 'px'
|
|
|
|
this.title_class.color = customStyle.text.color
|
|
|
|
this.title_class.textAlign = customStyle.text.hPosition
|
|
|
|
this.title_class.fontStyle = customStyle.text.isItalic ? 'italic' : 'normal'
|
2021-06-29 12:09:37 +08:00
|
|
|
this.title_class.fontWeight = customStyle.text.isBolder ? 'bold' : 'normal'
|
2021-04-26 12:35:47 +08:00
|
|
|
}
|
|
|
|
if (customStyle.background) {
|
|
|
|
this.bg_class.background = hexColorToRGBA(customStyle.background.color, customStyle.background.alpha)
|
|
|
|
}
|
|
|
|
}
|
2021-04-26 16:56:22 +08:00
|
|
|
// 修改footer合计样式
|
2021-06-09 17:21:17 +08:00
|
|
|
const table = document.getElementsByClassName(this.chart.id)
|
|
|
|
for (let i = 0; i < table.length; i++) {
|
|
|
|
const s_table = table[i].getElementsByClassName('elx-table--footer')
|
|
|
|
// console.log(s_table)
|
|
|
|
let s = ''
|
|
|
|
for (const i in this.table_header_class) {
|
|
|
|
s += (i === 'fontSize' ? 'font-size' : i) + ':' + this.table_header_class[i] + ';'
|
|
|
|
}
|
|
|
|
// console.log(s_table)
|
|
|
|
for (let i = 0; i < s_table.length; i++) {
|
|
|
|
s_table[i].setAttribute('style', s)
|
|
|
|
}
|
2021-06-07 15:42:24 +08:00
|
|
|
}
|
2021-04-26 15:20:55 +08:00
|
|
|
},
|
|
|
|
getRowStyle({ row, rowIndex }) {
|
2021-06-10 12:36:28 +08:00
|
|
|
if (rowIndex % 2 !== 0) {
|
2021-04-26 15:20:55 +08:00
|
|
|
return this.table_item_class_stripe
|
|
|
|
} else {
|
|
|
|
return this.table_item_class
|
|
|
|
}
|
2021-04-26 16:56:22 +08:00
|
|
|
},
|
|
|
|
summaryMethod({ columns, data }) {
|
2021-04-28 17:30:18 +08:00
|
|
|
const that = this
|
2021-04-26 16:56:22 +08:00
|
|
|
const means = [] // 合计
|
|
|
|
columns.forEach((column, columnIndex) => {
|
|
|
|
if (columnIndex === 0) {
|
|
|
|
means.push('合计')
|
|
|
|
} else {
|
2021-04-28 17:30:18 +08:00
|
|
|
if (columnIndex >= that.chart.data.fields.length - that.chart.data.series.length) {
|
|
|
|
const values = data.map(item => Number(item[column.property]))
|
|
|
|
// 合计
|
|
|
|
if (!values.every(value => isNaN(value))) {
|
|
|
|
means[columnIndex] = values.reduce((prev, curr) => {
|
|
|
|
const value = Number(curr)
|
|
|
|
if (!isNaN(value)) {
|
|
|
|
return prev + curr
|
|
|
|
} else {
|
|
|
|
return prev
|
|
|
|
}
|
|
|
|
}, 0)
|
|
|
|
means[columnIndex] = (means[columnIndex] + '').includes('.') ? means[columnIndex].toFixed(2) : means[columnIndex]
|
|
|
|
} else {
|
|
|
|
means[columnIndex] = ''
|
|
|
|
}
|
2021-04-26 16:56:22 +08:00
|
|
|
} else {
|
|
|
|
means[columnIndex] = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// 返回一个二维数组的表尾合计(不要平均值,就不要在数组中添加)
|
|
|
|
return [means]
|
2021-05-18 16:38:24 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
chartResize() {
|
|
|
|
// 指定图表的配置项和数据
|
2021-07-03 14:50:07 +08:00
|
|
|
this.calcHeightDelay()
|
2021-06-09 17:21:17 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
initClass() {
|
|
|
|
return this.chart.id
|
2021-06-30 12:42:09 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
resetHeight() {
|
|
|
|
this.height = 100
|
2021-04-25 18:03:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2021-04-26 15:20:55 +08:00
|
|
|
.table-class>>>.body--wrapper{
|
|
|
|
background: rgba(1,1,1,0);
|
|
|
|
}
|
2021-04-25 18:03:13 +08:00
|
|
|
</style>
|