数据探索数据列 / 指标增加百分比,dashboard日期和日期范围默认T-1

dev
zhenghuang 4 years ago
parent ce49fd603c
commit 409cd06063

@ -1,13 +1,19 @@
<template> <template>
<div ref="tableContainer" :style="bg_class" style="padding: 8px;width: 100%;height: 100%;overflow: hidden;"> <div
<el-row style="height: 100%;"> ref="tableContainer"
<p v-show="title_show" ref="title" :style="title_class">{{ chart.title }}</p> :style="bg_class"
style="padding: 8px; width: 100%; height: 100%; overflow: hidden"
>
<el-row style="height: 100%">
<p v-show="title_show" ref="title" :style="title_class">
{{ chart.title }}
</p>
<ux-grid <ux-grid
ref="plxTable" ref="plxTable"
size="mini" size="mini"
style="width: 100%;" style="width: 100%"
:height="height" :height="height"
:checkbox-config="{highlight: true}" :checkbox-config="{ highlight: true }"
:width-resize="true" :width-resize="true"
:header-row-style="table_header_class" :header-row-style="table_header_class"
:row-style="getRowStyle" :row-style="getRowStyle"
@ -21,15 +27,15 @@
> >
<ux-table-column <ux-table-column
v-for="(field, index) in fields" v-for="(field, index) in fields"
:key="field.dataeaseName+index" :key="field.dataeaseName + index"
:field="field.subFields?'':field.dataeaseName" :field="field.subFields ? '' : field.dataeaseName"
:resizable="true" :resizable="true"
:fixed="field.fixed" :fixed="field.fixed"
:title="field.name" :title="field.name"
> >
<template v-if="field.subFields"> <template v-if="field.subFields">
<ux-table-column <ux-table-column
v-for="(subfield) in field.subFields" v-for="subfield in field.subFields"
:key="subfield.dataeaseName" :key="subfield.dataeaseName"
:field="subfield.dataeaseName" :field="subfield.dataeaseName"
:resizable="true" :resizable="true"
@ -42,13 +48,15 @@
<el-row v-show="chart.type === 'table-info'" class="table-page"> <el-row v-show="chart.type === 'table-info'" class="table-page">
<span class="total-style"> <span class="total-style">
{{ $t('chart.total') }} {{ $t('chart.total') }}
<span>{{ (chart.data && chart.data.tableRow)?chart.data.tableRow.length:0 }}</span> <span>{{
chart.data && chart.data.tableRow ? chart.data.tableRow.length : 0
}}</span>
{{ $t('chart.items') }} {{ $t('chart.items') }}
</span> </span>
<el-pagination <el-pagination
small small
:current-page="currentPage.page" :current-page="currentPage.page"
:page-sizes="[10,20,50,100]" :page-sizes="[10, 20, 50, 100]"
:page-size="currentPage.pageSize" :page-size="currentPage.pageSize"
:pager-count="5" :pager-count="5"
layout="sizes, prev, pager, next" layout="sizes, prev, pager, next"
@ -172,7 +180,7 @@ export default {
for (var i = 0; i < obj.length; i++) { for (var i = 0; i < obj.length; i++) {
var keys = Object.keys(obj[i]) var keys = Object.keys(obj[i])
keys.sort(function(a, b) { keys.sort(function(a, b) {
return (Number(a) - Number(b)) return Number(a) - Number(b)
}) })
var str = '' var str = ''
for (var j = 0; j < keys.length; j++) { for (var j = 0; j < keys.length; j++) {
@ -192,33 +200,45 @@ export default {
if (this.chart.data) { if (this.chart.data) {
this.fields = JSON.parse(JSON.stringify(this.chart.data.fields)) this.fields = JSON.parse(JSON.stringify(this.chart.data.fields))
datas = JSON.parse(JSON.stringify(this.chart.data.tableRow)) datas = JSON.parse(JSON.stringify(this.chart.data.tableRow))
const findRowIndex = this.fields.findIndex(e => e.chartType === 'row') const findRowIndex = this.fields.findIndex((e) => e.chartType === 'row')
const findValueIndex = this.fields.findIndex(e => e.chartType === 'bar') const findValueIndex = this.fields.findIndex(
(e) => e.chartType === 'bar'
)
if (this.chart.type === 'table-info') { if (this.chart.type === 'table-info') {
// //
this.currentPage.show = datas.length this.currentPage.show = datas.length
const pageStart = (this.currentPage.page - 1) * this.currentPage.pageSize const pageStart =
(this.currentPage.page - 1) * this.currentPage.pageSize
const pageEnd = pageStart + this.currentPage.pageSize const pageEnd = pageStart + this.currentPage.pageSize
datas = datas.slice(pageStart, pageEnd) datas = datas.slice(pageStart, pageEnd)
} else if (this.chart.type === 'table-normal' && findRowIndex >= 0) { } else if (this.chart.type === 'table-normal' && findRowIndex >= 0) {
// //
const xaxis = this.chart.xaxis ? JSON.parse(this.chart.xaxis) : [] const xaxis = this.chart.xaxis ? JSON.parse(this.chart.xaxis) : []
const yaxisExt = this.chart.yaxisExt ? JSON.parse(this.chart.yaxisExt) : [] const yaxisExt = this.chart.yaxisExt
const xaxisFieldId = xaxis.map(e => e.dataeaseName) ? JSON.parse(this.chart.yaxisExt)
const yaxisExtFieldId = yaxisExt.map(e => e.dataeaseName) : []
const xaxisFieldId = xaxis.map((e) => e.dataeaseName)
const yaxisExtFieldId = yaxisExt.map((e) => e.dataeaseName)
const fieldValueName = this.fields[findValueIndex].dataeaseName const fieldValueName = this.fields[findValueIndex].dataeaseName
this.cellDimension = xaxisFieldId.length this.cellDimension = xaxisFieldId.length
let fields = this.fields.filter(e => xaxisFieldId.includes(e.dataeaseName)) let fields = this.fields.filter((e) =>
xaxisFieldId.includes(e.dataeaseName)
)
console.log(fields) console.log(fields)
let rowSum = 0 let rowSum = 0
let columnValue = [] let columnValue = []
let rowName = [] let rowName = []
yaxisExtFieldId.forEach((e, index) => { yaxisExtFieldId.forEach((e, index) => {
const arr = [] const arr = []
datas.forEach(ele => { datas.forEach((ele) => {
if (index > 0) { if (index > 0) {
arr.push({ arr.push({
dataeaseName: e + ele[e] + ',' + yaxisExtFieldId[0] + ele[yaxisExtFieldId[0]], dataeaseName:
e +
ele[e] +
',' +
yaxisExtFieldId[0] +
ele[yaxisExtFieldId[0]],
name: ele[e] name: ele[e]
}) })
} else { } else {
@ -230,9 +250,9 @@ export default {
}) })
if (index > 0) { if (index > 0) {
const copyArr = this.deteleObject(arr) const copyArr = this.deteleObject(arr)
rowName.forEach(item => { rowName.forEach((item) => {
const newArr = [] const newArr = []
copyArr.forEach(sube => { copyArr.forEach((sube) => {
if (item.dataeaseName === sube.dataeaseName.split(',')[1]) { if (item.dataeaseName === sube.dataeaseName.split(',')[1]) {
newArr.push(sube) newArr.push(sube)
} }
@ -246,7 +266,7 @@ export default {
if (xaxisFieldId.length > 1) { if (xaxisFieldId.length > 1) {
let arr1 = [] let arr1 = []
let arr2 = [] let arr2 = []
datas.forEach(obj => { datas.forEach((obj) => {
for (const key in obj) { for (const key in obj) {
if (Object.hasOwnProperty.call(obj, key)) { if (Object.hasOwnProperty.call(obj, key)) {
const element = obj[key] const element = obj[key]
@ -265,42 +285,57 @@ export default {
arr1 = this.deteleObject(arr1) arr1 = this.deteleObject(arr1)
arr2 = this.deteleObject(arr2) arr2 = this.deteleObject(arr2)
let rowIndex = 0 let rowIndex = 0
arr1.forEach(e => { arr1.forEach((e) => {
this.mergeCells.push({ this.mergeCells.push({
col: 0, col: 0,
row: rowIndex, row: rowIndex,
rowspan: arr2.length, rowspan: arr2.length,
colspan: 1 colspan: 1
}) })
arr2.forEach(item => { arr2.forEach((item) => {
const obj = {} const obj = {}
columnValue.push(Object.assign(obj, e, item)) columnValue.push(Object.assign(obj, e, item))
rowIndex += 1 rowIndex += 1
}) })
}) })
columnValue.forEach(ele => { columnValue.forEach((ele) => {
if (yaxisExtFieldId.length > 1) { if (yaxisExtFieldId.length > 1) {
datas.forEach(subEle => { datas.forEach((subEle) => {
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]] && ele[xaxisFieldId[1]] === subEle[xaxisFieldId[1]]) { if (
const key = yaxisExtFieldId[1] + subEle[yaxisExtFieldId[1]] + ',' + yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]] ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]] &&
ele[xaxisFieldId[1]] === subEle[xaxisFieldId[1]]
) {
const key =
yaxisExtFieldId[1] +
subEle[yaxisExtFieldId[1]] +
',' +
yaxisExtFieldId[0] +
subEle[yaxisExtFieldId[0]]
ele[key] = subEle[fieldValueName] ele[key] = subEle[fieldValueName]
rowSum += subEle[fieldValueName] rowSum += subEle[fieldValueName]
} }
}) })
} else { } else {
datas.forEach(subEle => { datas.forEach((subEle) => {
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]] && ele[xaxisFieldId[1]] === subEle[xaxisFieldId[1]]) { if (
ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]] &&
ele[xaxisFieldId[1]] === subEle[xaxisFieldId[1]]
) {
const key = yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]] const key = yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]]
ele[key] = subEle[fieldValueName] ele[key] = subEle[fieldValueName]
rowSum += subEle[fieldValueName] rowSum += subEle[fieldValueName]
} }
}) })
} }
rowSum = rowSum.toFixed(2)
if (this.fields[findValueIndex].summary === 'ratio') {
rowSum += '%'
}
ele.rowTotal = rowSum ele.rowTotal = rowSum
rowSum = 0 rowSum = 0
}) })
} else { } else {
datas.forEach(obj => { datas.forEach((obj) => {
for (const key in obj) { for (const key in obj) {
if (Object.hasOwnProperty.call(obj, key)) { if (Object.hasOwnProperty.call(obj, key)) {
const element = obj[key] const element = obj[key]
@ -313,21 +348,28 @@ export default {
} }
}) })
columnValue = this.deteleObject(columnValue) columnValue = this.deteleObject(columnValue)
columnValue.forEach(ele => { columnValue.forEach((ele) => {
if (yaxisExtFieldId.length > 1) { if (yaxisExtFieldId.length > 1) {
datas.forEach(subEle => { datas.forEach((subEle) => {
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]]) { if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]]) {
const key = yaxisExtFieldId[1] + subEle[yaxisExtFieldId[1]] + ',' + yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]] const key =
yaxisExtFieldId[1] +
subEle[yaxisExtFieldId[1]] +
',' +
yaxisExtFieldId[0] +
subEle[yaxisExtFieldId[0]]
ele[key] = subEle[fieldValueName] ele[key] = subEle[fieldValueName]
rowSum += subEle[fieldValueName] rowSum += subEle[fieldValueName]
console.log(3, ele)
} }
}) })
} else { } else {
datas.forEach(subEle => { datas.forEach((subEle) => {
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]]) { if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]]) {
const key = yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]] const key = yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]]
ele[key] = subEle[fieldValueName] ele[key] = subEle[fieldValueName]
rowSum += subEle[fieldValueName] rowSum += subEle[fieldValueName]
console.log(3, subEle)
} }
}) })
} }
@ -335,6 +377,7 @@ export default {
rowSum = 0 rowSum = 0
}) })
} }
fields = fields.concat(rowName) fields = fields.concat(rowName)
fields.push({ fields.push({
dataeaseName: 'rowTotal', dataeaseName: 'rowTotal',
@ -367,7 +410,8 @@ export default {
pageHeight = 36 pageHeight = 36
} }
const currentHeight = this.$refs.tableContainer.offsetHeight const currentHeight = this.$refs.tableContainer.offsetHeight
const tableMaxHeight = currentHeight - this.$refs.title.offsetHeight - 16 - pageHeight const tableMaxHeight =
currentHeight - this.$refs.title.offsetHeight - 16 - pageHeight
let tableHeight let tableHeight
if (this.chart.data) { if (this.chart.data) {
if (this.chart.type === 'table-info') { if (this.chart.type === 'table-info') {
@ -396,17 +440,28 @@ export default {
const customAttr = JSON.parse(this.chart.customAttr) const customAttr = JSON.parse(this.chart.customAttr)
if (customAttr.color) { if (customAttr.color) {
this.table_header_class.color = customAttr.color.tableFontColor this.table_header_class.color = customAttr.color.tableFontColor
this.table_header_class.backgroundColor = hexColorToRGBA(customAttr.color.tableHeaderBgColor, customAttr.color.alpha) this.table_header_class.backgroundColor = hexColorToRGBA(
customAttr.color.tableHeaderBgColor,
customAttr.color.alpha
)
this.table_item_class.color = customAttr.color.tableFontColor this.table_item_class.color = customAttr.color.tableFontColor
this.table_item_class.background = hexColorToRGBA(customAttr.color.tableItemBgColor, customAttr.color.alpha) this.table_item_class.background = hexColorToRGBA(
customAttr.color.tableItemBgColor,
customAttr.color.alpha
)
} }
if (customAttr.size) { if (customAttr.size) {
this.table_header_class.fontSize = customAttr.size.tableTitleFontSize + 'px' this.table_header_class.fontSize =
this.table_item_class.fontSize = customAttr.size.tableItemFontSize + 'px' customAttr.size.tableTitleFontSize + 'px'
this.table_header_class.height = customAttr.size.tableTitleHeight + 'px' this.table_item_class.fontSize =
customAttr.size.tableItemFontSize + 'px'
this.table_header_class.height =
customAttr.size.tableTitleHeight + 'px'
this.table_item_class.height = customAttr.size.tableItemHeight + 'px' this.table_item_class.height = customAttr.size.tableItemHeight + 'px'
} }
this.table_item_class_stripe = JSON.parse(JSON.stringify(this.table_item_class)) this.table_item_class_stripe = JSON.parse(
JSON.stringify(this.table_item_class)
)
// //
// if (customAttr.color.tableStripe) { // if (customAttr.color.tableStripe) {
// // this.table_item_class_stripe.background = hexColorToRGBA(customAttr.color.tableItemBgColor, customAttr.color.alpha - 40) // // this.table_item_class_stripe.background = hexColorToRGBA(customAttr.color.tableItemBgColor, customAttr.color.alpha - 40)
@ -425,11 +480,18 @@ export default {
this.title_class.fontSize = customStyle.text.fontSize + 'px' this.title_class.fontSize = customStyle.text.fontSize + 'px'
this.title_class.color = customStyle.text.color this.title_class.color = customStyle.text.color
this.title_class.textAlign = customStyle.text.hPosition this.title_class.textAlign = customStyle.text.hPosition
this.title_class.fontStyle = customStyle.text.isItalic ? 'italic' : 'normal' this.title_class.fontStyle = customStyle.text.isItalic
this.title_class.fontWeight = customStyle.text.isBolder ? 'bold' : 'normal' ? 'italic'
: 'normal'
this.title_class.fontWeight = customStyle.text.isBolder
? 'bold'
: 'normal'
} }
if (customStyle.background) { if (customStyle.background) {
this.bg_class.background = hexColorToRGBA(customStyle.background.color, customStyle.background.alpha) this.bg_class.background = hexColorToRGBA(
customStyle.background.color,
customStyle.background.alpha
)
} }
} }
// footer // footer
@ -439,7 +501,15 @@ export default {
// console.log(s_table) // console.log(s_table)
let s = '' let s = ''
for (const i in this.table_header_class) { for (const i in this.table_header_class) {
s += (i === 'fontSize' ? 'font-size' : i === 'backgroundColor' ? 'background-color' : i) + ':' + this.table_header_class[i] + ';' s +=
(i === 'fontSize'
? 'font-size'
: i === 'backgroundColor'
? 'background-color'
: i) +
':' +
this.table_header_class[i] +
';'
} }
// console.log(s_table) // console.log(s_table)
for (let i = 0; i < s_table.length; i++) { for (let i = 0; i < s_table.length; i++) {
@ -455,7 +525,12 @@ export default {
} }
}, },
getColumStyle({ columnIndex }) { getColumStyle({ columnIndex }) {
if (this.chart.type === 'table-normal' && this.cellDimension > 0 && (columnIndex < this.cellDimension || columnIndex === this.fields.length - 1)) { if (
this.chart.type === 'table-normal' &&
this.cellDimension > 0 &&
(columnIndex < this.cellDimension ||
columnIndex === this.fields.length - 1)
) {
return this.table_header_class return this.table_header_class
} else { } else {
return '' return ''
@ -464,7 +539,9 @@ export default {
summaryMethod({ columns, data }) { summaryMethod({ columns, data }) {
const that = this const that = this
const means = [] // const means = [] //
const findValueIndex = this.chart.data.fields.findIndex(e => e.chartType === 'bar') const findValueIndex = this.chart.data.fields.findIndex(
(e) => e.chartType === 'bar'
)
columns.forEach((column, columnIndex) => { columns.forEach((column, columnIndex) => {
if (columnIndex === 0) { if (columnIndex === 0) {
if (this.cellDimension > 0 && findValueIndex !== -1) { if (this.cellDimension > 0 && findValueIndex !== -1) {
@ -473,10 +550,23 @@ export default {
means.push('合计') means.push('合计')
} }
} else { } else {
if (columnIndex >= that.chart.data.fields.length - that.chart.data.series.length || this.cellDimension > 0) { let isRatio = false
const values = data.map(item => Number(item[column.property])) if (
columnIndex >=
that.chart.data.fields.length - that.chart.data.series.length ||
this.cellDimension > 0
) {
const values = data.map((item) => {
let a = item[column.property]
if (typeof a === 'string' && a.indexOf('%') >= 0) {
a = a.replace('%', '')
isRatio = true
}
return Number(a)
})
// //
if (!values.every(value => isNaN(value))) { if (!values.every((value) => isNaN(value))) {
means[columnIndex] = values.reduce((prev, curr) => { means[columnIndex] = values.reduce((prev, curr) => {
const value = Number(curr) const value = Number(curr)
if (!isNaN(value)) { if (!isNaN(value)) {
@ -485,7 +575,14 @@ export default {
return prev return prev
} }
}, 0) }, 0)
means[columnIndex] = (means[columnIndex] + '').includes('.') ? means[columnIndex].toFixed(2) : means[columnIndex] means[columnIndex] = (means[columnIndex] + '').includes('.')
? means[columnIndex].toFixed(2)
: means[columnIndex]
if (isRatio) {
means[columnIndex] =
means[columnIndex] > 100 ? 100 : means[columnIndex]
means[columnIndex] += '%'
}
} else { } else {
means[columnIndex] = '' means[columnIndex] = ''
} }
@ -533,14 +630,14 @@ export default {
</script> </script>
<style scoped> <style scoped>
.table-class>>>.body--wrapper{ .table-class >>> .body--wrapper {
background: rgba(1,1,1,0); background: rgba(1, 1, 1, 0);
} }
.table-class>>>.elx-cell{ .table-class >>> .elx-cell {
max-height: none!important; max-height: none !important;
line-height: normal!important; line-height: normal !important;
} }
.table-page{ .table-page {
position: absolute; position: absolute;
bottom: 0; bottom: 0;
display: flex; display: flex;
@ -548,23 +645,23 @@ export default {
justify-content: flex-end; justify-content: flex-end;
width: 100%; width: 100%;
overflow: hidden; overflow: hidden;
} }
.page-style{ .page-style {
margin-right: auto; margin-right: auto;
} }
.total-style{ .total-style {
flex: 1; flex: 1;
font-size: 12px; font-size: 12px;
color: #606266; color: #606266;
white-space:nowrap; white-space: nowrap;
} }
.page-style >>> .el-input__inner{ .page-style >>> .el-input__inner {
height: 24px; height: 24px;
} }
.colum-header { .colum-header {
font-size: 12px; font-size: 12px;
color: #000; color: #000;
background: rgb(78, 129, 187); background: rgb(78, 129, 187);
height: 36px; height: 36px;
} }
</style> </style>

Loading…
Cancel
Save