refactor(图表): 图表详情查看优化: 非表格类型统一样式,表格类型使用自身样式。

This commit is contained in:
wisonic-s 2024-03-12 18:09:22 +08:00
parent 03d2f2876a
commit 52187b6a6d
2 changed files with 38 additions and 13 deletions

View File

@ -60,6 +60,7 @@ import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { VIEW_DETAILS_BASH_STYLE } from '@/views/chart/components/editor/util/dataVisualiztion' import { VIEW_DETAILS_BASH_STYLE } from '@/views/chart/components/editor/util/dataVisualiztion'
import { exportExcelDownload } from '@/views/chart/components/js/util' import { exportExcelDownload } from '@/views/chart/components/js/util'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
import { assign } from 'lodash-es'
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
const dialogShow = ref(false) const dialogShow = ref(false)
let viewInfo = ref<DeepPartial<ChartObj>>(null) let viewInfo = ref<DeepPartial<ChartObj>>(null)
@ -70,22 +71,35 @@ const { t } = useI18n()
const optType = ref(null) const optType = ref(null)
const chartComponentDetails = ref(null) const chartComponentDetails = ref(null)
const { dvInfo } = storeToRefs(dvMainStore) const { dvInfo } = storeToRefs(dvMainStore)
const DETAIL_TABLE_ATTR: DeepPartial<ChartObj> = {
render: 'antv',
type: 'table-info',
customAttr: {
basicStyle: {
tableColumnMode: 'dialog'
},
tableHeader: {
tableHeaderBgColor: '#F8F8F9',
tableHeaderFontColor: '#7C7E81'
},
tableCell: {
tableItemBgColor: '#FFFFFF',
tableFontColor: '#7C7E81',
enableTableCrossBG: false
}
}
}
const dialogInit = (canvasStyle, view, item, opt) => { const dialogInit = (canvasStyle, view, item, opt) => {
optType.value = opt optType.value = opt
dialogShow.value = true dialogShow.value = true
viewInfo.value = deepCopy(view) as DeepPartial<ChartObj> viewInfo.value = deepCopy(view) as DeepPartial<ChartObj>
viewInfo.value.customStyle.text.show = false viewInfo.value.customStyle.text.show = false
if (!viewInfo.value.type?.includes('table')) {
viewInfo.value.customAttr.tableHeader.tableHeaderBgColor = '#F8F8F9'
viewInfo.value.customAttr.tableHeader.tableHeaderFontColor = '#7C7E81'
viewInfo.value.customAttr.tableCell.tableItemBgColor = '#FFFFFF'
viewInfo.value.customAttr.tableCell.tableFontColor = '#7C7E81'
viewInfo.value.customAttr.tableCell.enableTableCrossBG = false
}
config.value = deepCopy(item) config.value = deepCopy(item)
canvasStyleData.value = canvasStyle canvasStyleData.value = canvasStyle
if (opt === 'details') { if (opt === 'details') {
if (!viewInfo.value.type?.includes('table')) {
assign(viewInfo.value, DETAIL_TABLE_ATTR)
}
dataDetailsOpt() dataDetailsOpt()
} }
} }
@ -93,10 +107,7 @@ const dialogInit = (canvasStyle, view, item, opt) => {
const dataDetailsOpt = () => { const dataDetailsOpt = () => {
nextTick(() => { nextTick(() => {
const viewDataInfo = dvMainStore.getViewDataDetails(viewInfo.value.id) const viewDataInfo = dvMainStore.getViewDataDetails(viewInfo.value.id)
chartComponentDetails.value.renderChartFromDialog( chartComponentDetails.value.renderChartFromDialog(viewInfo.value, viewDataInfo)
JSON.parse(VIEW_DETAILS_BASH_STYLE),
viewDataInfo
)
}) })
} }

View File

@ -337,9 +337,23 @@ export function getStyle(chart: Chart): Style {
} }
break break
} }
case 'custom': {
style.colCfg.width = basicStyle.tableColumnWidth
break
}
// 查看详情用均分铺满
default: { default: {
delete style.layoutWidthType delete style.layoutWidthType
style.colCfg.width = basicStyle.tableColumnWidth style.colCfg.width = node => {
const width = node.spreadsheet.container.cfg.el.offsetWidth
const fieldsSize = chart.data?.fields?.length
if (!fieldsSize) {
return 0
}
const columnCount = tableHeader.showIndex ? fieldsSize + 1 : fieldsSize
const minWidth = width / columnCount
return Math.max(minWidth, basicStyle.tableColumnWidth)
}
} }
} }
} }