Skip to content

Commit

Permalink
fix: fix custom container name judgement
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Jun 4, 2024
1 parent 8eac2ff commit 017e7ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
23 changes: 17 additions & 6 deletions packages/vtable/src/scenegraph/component/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import type { percentCalcObj } from '../../render/layout';
import { getTargetCell } from '../../event/util';
import type { Group } from '../graphic/group';

export const CUSTOM_MERGE_PRE_NAME = '_custom_';
export const CUSTOM_CONTAINER_NAME = 'custom-container';
export const CUSTOM_MERGE_CONTAINER_NAME = CUSTOM_MERGE_PRE_NAME + '_0';

export function dealWithCustom(
customLayout: ICustomLayout,
customRender: ICustomRender,
Expand Down Expand Up @@ -67,7 +71,7 @@ export function dealWithCustom(
// expectedHeight = customRenderObj.expectedHeight;
if (customRenderObj.rootContainer instanceof VGroup) {
elementsGroup = customRenderObj.rootContainer;
elementsGroup.name = 'custom-container';
elementsGroup.name = CUSTOM_CONTAINER_NAME;
// } else if (customRenderObj.rootContainer) {
// customElements = customRenderObj.rootContainer.getElements(undefined, false, false);
}
Expand Down Expand Up @@ -151,7 +155,7 @@ function adjustElementToGroup(
stroke: false,
pickable: false
});
customGroup.name = 'custom-container';
customGroup.name = CUSTOM_CONTAINER_NAME;

const elementsAdjusted = adjustElementsPos(elements, width, height, value);
elementsAdjusted.forEach(element => {
Expand Down Expand Up @@ -491,8 +495,6 @@ function parseToGraphic(g: any, props: any) {
}
}

const CUSTOM_MERGE_PRE_NAME = '_custom_';

function bindAttributeUpdate(group: VGroup, col: number, row: number, index: number, preId?: string) {
if (!group) {
return;
Expand All @@ -511,7 +513,7 @@ function onBeforeAttributeUpdate(val: Record<string, any>, attribute: any) {
// @ts-ignore
const graphic = this as any;
const cellGroup = getTargetCell(graphic) as Group;
const table = (cellGroup.stage as any).table as BaseTableAPI;
const table = ((cellGroup as any).stage as any).table as BaseTableAPI;
graphic.skipAttributeUpdate = true;
const { mergeStartCol, mergeEndCol, mergeStartRow, mergeEndRow } = cellGroup;
if (
Expand All @@ -534,8 +536,17 @@ function onBeforeAttributeUpdate(val: Record<string, any>, attribute: any) {
}
for (const key in val) {
// 表格内merge 单元格布局时,会使用dx dy定位,避免重复更新值,属性同步跳过 dx dy
// console.log(
// '[onBeforeAttributeUpdate]',
// target._uid,
// cellGroup.col,
// cellGroup.row,
// col,
// row,
// key,
// val[key]
// );
if (val[key] !== target.attribute[key] && key !== 'dx' && key !== 'dy') {
console.log('[onBeforeAttributeUpdate]', target.uid, cellGroup.col, cellGroup.row, col, row);
target.setAttribute(key, val[key]);
}
}
Expand Down
10 changes: 7 additions & 3 deletions packages/vtable/src/scenegraph/layout/update-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getProp } from '../utils/get-prop';
import { getQuadProps } from '../utils/padding';
import { updateCellContentHeight } from '../utils/text-icon-layout';
import type { IProgressbarColumnBodyDefine } from '../../ts-types/list-table/define/progressbar-define';
import { dealWithCustom } from '../component/custom';
import { CUSTOM_CONTAINER_NAME, CUSTOM_MERGE_CONTAINER_NAME, dealWithCustom } from '../component/custom';
import { updateImageCellContentWhileResize } from '../group-creater/cell-type/image-cell';
import { getStyleTheme } from '../../core/tableHelper';
import { isMergeCellGroup } from '../utils/is-merge-cell-group';
Expand Down Expand Up @@ -183,7 +183,9 @@ export function updateCellHeight(
(cell.firstChild as any)?.originAxis.resize(cell.attribute.width, cell.attribute.height);
} else {
let renderDefault = true;
const customContainer = cell.getChildByName('custom-container') as Group;
const customContainer =
(cell.getChildByName(CUSTOM_CONTAINER_NAME) as Group) ||
(cell.getChildByName(CUSTOM_MERGE_CONTAINER_NAME) as Group);
if (customContainer) {
let customElementsGroup;
customContainer.removeAllChild();
Expand All @@ -196,7 +198,9 @@ export function updateCellHeight(
continue;
}
const mergedCell = scene.getCell(col, mergeRow);
const customContainer = mergedCell.getChildByName('custom-container') as Group;
const customContainer =
(cell.getChildByName(CUSTOM_CONTAINER_NAME) as Group) ||
(cell.getChildByName(CUSTOM_MERGE_CONTAINER_NAME) as Group);
customContainer.removeAllChild();
mergedCell.removeChild(customContainer);
getCustomCellMergeCustom(col, mergeRow, mergedCell, scene.table);
Expand Down
10 changes: 7 additions & 3 deletions packages/vtable/src/scenegraph/layout/update-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CartesianAxis } from '../../components/axis/axis';
import { getStyleTheme } from '../../core/tableHelper';
import type { BaseTableAPI, HeaderData } from '../../ts-types/base-table';
import type { IProgressbarColumnBodyDefine } from '../../ts-types/list-table/define/progressbar-define';
import { dealWithCustom } from '../component/custom';
import { CUSTOM_CONTAINER_NAME, CUSTOM_MERGE_CONTAINER_NAME, dealWithCustom } from '../component/custom';
import type { Group } from '../graphic/group';
import { updateImageCellContentWhileResize } from '../group-creater/cell-type/image-cell';
import { createProgressBarCell } from '../group-creater/cell-type/progress-bar-cell';
Expand Down Expand Up @@ -342,7 +342,9 @@ function updateCellWidth(
(cell.firstChild as any)?.originAxis.resize(cell.attribute.width, cell.attribute.height);
} else {
let renderDefault = true;
const customContainer = cell.getChildByName('custom-container') as Group;
const customContainer =
(cell.getChildByName(CUSTOM_CONTAINER_NAME) as Group) ||
(cell.getChildByName(CUSTOM_MERGE_CONTAINER_NAME) as Group);
if (customContainer) {
let customElementsGroup;
customContainer.removeAllChild();
Expand All @@ -355,7 +357,9 @@ function updateCellWidth(
continue;
}
const mergedCell = scene.getCell(mergeCol, row);
const customContainer = mergedCell.getChildByName('custom-container') as Group;
const customContainer =
(mergedCell.getChildByName(CUSTOM_CONTAINER_NAME) as Group) ||
(cell.getChildByName(CUSTOM_MERGE_CONTAINER_NAME) as Group);
customContainer.removeAllChild();
mergedCell.removeChild(customContainer);
getCustomCellMergeCustom(mergeCol, row, mergedCell, scene.table);
Expand Down

0 comments on commit 017e7ef

Please sign in to comment.