forked from github/dataease
Merge pull request #13068 from dataease/pr@dev-v2@refactor_table_info_merge_index_number
refactor(图表): 明细表合并单元格序号列序号计算逻辑优化
This commit is contained in:
commit
c23c61c757
@ -14,7 +14,11 @@ import { S2ChartView, S2DrawOptions } from '../../types/impl/s2'
|
|||||||
import { TABLE_EDITOR_PROPERTY, TABLE_EDITOR_PROPERTY_INNER } from './common'
|
import { TABLE_EDITOR_PROPERTY, TABLE_EDITOR_PROPERTY_INNER } from './common'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { isNumber } from 'lodash-es'
|
import { isNumber } from 'lodash-es'
|
||||||
import { copyContent, SortTooltip } from '@/views/chart/components/js/panel/common/common_table'
|
import {
|
||||||
|
copyContent,
|
||||||
|
getRowIndex,
|
||||||
|
SortTooltip
|
||||||
|
} from '@/views/chart/components/js/panel/common/common_table'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
class ImageCell extends TableDataCell {
|
class ImageCell extends TableDataCell {
|
||||||
@ -192,7 +196,12 @@ export class TableInfo extends S2ChartView<TableSheet> {
|
|||||||
return new ImageCell(viewMeta, viewMeta?.spreadsheet)
|
return new ImageCell(viewMeta, viewMeta?.spreadsheet)
|
||||||
}
|
}
|
||||||
if (viewMeta.colIndex === 0 && s2Options.showSeriesNumber) {
|
if (viewMeta.colIndex === 0 && s2Options.showSeriesNumber) {
|
||||||
viewMeta.fieldValue = pageInfo.pageSize * (pageInfo.currentPage - 1) + viewMeta.rowIndex + 1
|
if (tableCell.mergeCells) {
|
||||||
|
viewMeta.fieldValue = getRowIndex(s2Options.mergedCellsInfo, viewMeta)
|
||||||
|
} else {
|
||||||
|
viewMeta.fieldValue =
|
||||||
|
pageInfo.pageSize * (pageInfo.currentPage - 1) + viewMeta.rowIndex + 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new TableDataCell(viewMeta, viewMeta?.spreadsheet)
|
return new TableDataCell(viewMeta, viewMeta?.spreadsheet)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,9 @@ import {
|
|||||||
TableDataCell,
|
TableDataCell,
|
||||||
MergedCell,
|
MergedCell,
|
||||||
getPolygonPoints,
|
getPolygonPoints,
|
||||||
renderPolygon
|
renderPolygon,
|
||||||
|
MergedCellInfo,
|
||||||
|
ViewMeta
|
||||||
} from '@antv/s2'
|
} from '@antv/s2'
|
||||||
import { keys, intersection, filter, cloneDeep, merge, find, repeat } from 'lodash-es'
|
import { keys, intersection, filter, cloneDeep, merge, find, repeat } from 'lodash-es'
|
||||||
import { createVNode, render } from 'vue'
|
import { createVNode, render } from 'vue'
|
||||||
@ -1419,12 +1421,12 @@ export function configMergeCells(chart: Chart, options: S2Options) {
|
|||||||
const xAxis = chart.xAxis
|
const xAxis = chart.xAxis
|
||||||
const quotaIndex = xAxis.findIndex(axis => axis.groupType === 'q')
|
const quotaIndex = xAxis.findIndex(axis => axis.groupType === 'q')
|
||||||
const data = chart.data?.tableRow
|
const data = chart.data?.tableRow
|
||||||
if (quotaIndex <= 0 || !data?.length) {
|
if (quotaIndex === 0 || !data?.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const mergedColInfo: number[][][] = [[[0, data.length - 1]]]
|
const mergedColInfo: number[][][] = [[[0, data.length - 1]]]
|
||||||
const mergedCellsInfo = []
|
const mergedCellsInfo = []
|
||||||
const axisToMerge = xAxis.filter((a, i) => a.hide !== true && i < quotaIndex)
|
const axisToMerge = xAxis.filter((a, i) => a.hide !== true && (i < quotaIndex || quotaIndex === -1))
|
||||||
axisToMerge.forEach((a, i) => {
|
axisToMerge.forEach((a, i) => {
|
||||||
const preMergedColInfo = mergedColInfo[i]
|
const preMergedColInfo = mergedColInfo[i]
|
||||||
const curMergedColInfo = []
|
const curMergedColInfo = []
|
||||||
@ -1476,11 +1478,33 @@ export function configMergeCells(chart: Chart, options: S2Options) {
|
|||||||
}
|
}
|
||||||
options.mergedCellsInfo = mergedCellsInfo
|
options.mergedCellsInfo = mergedCellsInfo
|
||||||
options.mergedCell = (sheet, cells, meta) => {
|
options.mergedCell = (sheet, cells, meta) => {
|
||||||
|
if (showIndex && meta.colIndex === 0) {
|
||||||
|
meta.fieldValue = getRowIndex(mergedCellsInfo, meta)
|
||||||
|
}
|
||||||
return new CustomMergedCell(sheet, cells, meta)
|
return new CustomMergedCell(sheet, cells, meta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRowIndex(mergedCellsInfo: MergedCellInfo[][], meta: ViewMeta): number {
|
||||||
|
let curRangeStartIndex = 0
|
||||||
|
const lostCells = mergedCellsInfo.reduce((p, n) => {
|
||||||
|
if (n[0].colIndex !== 0) {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
const start = n[0].rowIndex
|
||||||
|
const end = n[n.length - 1].rowIndex
|
||||||
|
const lost = end - start
|
||||||
|
if (meta.rowIndex >= start && meta.rowIndex <= end) {
|
||||||
|
curRangeStartIndex = start
|
||||||
|
}
|
||||||
|
if (meta.rowIndex > end) {
|
||||||
|
return p + lost
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}, 0)
|
||||||
|
return curRangeStartIndex - lostCells + 1
|
||||||
|
}
|
||||||
class CustomMergedCell extends MergedCell {
|
class CustomMergedCell extends MergedCell {
|
||||||
protected drawBackgroundShape() {
|
protected drawBackgroundShape() {
|
||||||
const allPoints = getPolygonPoints(this.cells)
|
const allPoints = getPolygonPoints(this.cells)
|
||||||
|
Loading…
Reference in New Issue
Block a user