Skip to content

Commit ea9c6a3

Browse files
authored
chore: playground 增加 grid-tree,修复 vue playground 多行文本不生效 (#3317)
* chore: 在 playground 中增加 grid-tree * chore: 换行配置生效 * fix: grid-tree 行头文本较长时可能会溢出单元格 * fix: tree 和 grid-tree 模式下,如果用户没有配置 totals,不应该自动聚合
1 parent c6cdec7 commit ea9c6a3

5 files changed

Lines changed: 116 additions & 26 deletions

File tree

‎packages/s2-core/src/cell/row-cell.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ export class RowCell extends HeaderCell<RowHeaderConfig> {
104104
spanWidth += levelSample?.width ?? 0;
105105
}
106106

107+
// CONTENT_BOX 需要减去左右 padding
108+
if (type === CellClipBox.CONTENT_BOX) {
109+
const { padding } = this.getStyle()!.cell!;
110+
111+
spanWidth -= (padding?.left ?? 0) + (padding?.right ?? 0);
112+
}
113+
107114
return {
108115
...baseBBox,
109116
width: spanWidth || baseBBox.width,

‎packages/s2-core/src/data-set/pivot-data-set.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,11 @@ export class PivotDataSet extends BaseDataSet {
412412
getAggregationAndCalcFuncByQuery(status, options?.totals) || {};
413413

414414
// 聚合方式从用户配置的 s2Options.totals 取, 在触发前端兜底计算汇总逻辑时, 如果没有汇总的配置, 默认按 [求和] 计算,避免排序失效.
415+
// tree 和 grid-tree 模式下,如果用户没有配置 totals,不应该自动聚合
415416
const defaultAggregation =
416-
isEmpty(options?.totals) && !this.spreadsheet.isHierarchyTreeType()
417+
isEmpty(options?.totals) &&
418+
!this.spreadsheet.isHierarchyTreeType() &&
419+
!this.spreadsheet.isHierarchyGridTreeType()
417420
? Aggregation.SUM
418421
: '';
419422

‎packages/s2-react/playground/index.tsx‎

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
DatePicker,
3232
Divider,
3333
Input,
34+
InputNumber,
3435
Pagination,
3536
Popover,
3637
Radio,
@@ -470,6 +471,40 @@ function MainLayout() {
470471
</Radio.Button>
471472
</Radio.Group>
472473
</Tooltip>
474+
<InputNumber
475+
style={{ width: 120 }}
476+
min={0}
477+
placeholder="紧凑布局(附加宽)"
478+
disabled={
479+
options?.style?.layoutWidthType !==
480+
'compact'
481+
}
482+
value={options?.style?.compactExtraWidth ?? 0}
483+
onChange={(value) => {
484+
updateOptions({
485+
style: {
486+
compactExtraWidth: value ?? 0,
487+
},
488+
});
489+
}}
490+
/>
491+
<InputNumber
492+
style={{ width: 120 }}
493+
min={0}
494+
placeholder="紧凑布局(最小宽)"
495+
disabled={
496+
options?.style?.layoutWidthType !==
497+
'compact'
498+
}
499+
value={options?.style?.compactMinWidth ?? 0}
500+
onChange={(value) => {
501+
updateOptions({
502+
style: {
503+
compactMinWidth: value ?? 0,
504+
},
505+
});
506+
}}
507+
/>
473508
<Button
474509
danger
475510
onClick={() => {
@@ -495,19 +530,27 @@ function MainLayout() {
495530
updateOptions({ debug: checked });
496531
}}
497532
/>
498-
<Switch
499-
checkedChildren="树形"
500-
unCheckedChildren="平铺"
501-
checked={
502-
mergedOptions.hierarchyType === 'tree'
503-
}
504-
onChange={(checked) => {
505-
updateOptions({
506-
hierarchyType: checked ? 'tree' : 'grid',
507-
});
508-
}}
509-
disabled={sheetType === 'table'}
510-
/>
533+
<Tooltip title="透视表层级结构">
534+
<Radio.Group
535+
value={mergedOptions.hierarchyType}
536+
onChange={(e) => {
537+
updateOptions({
538+
hierarchyType: e.target.value,
539+
});
540+
}}
541+
disabled={sheetType === 'table'}
542+
>
543+
<Radio.Button value="grid">
544+
平铺
545+
</Radio.Button>
546+
<Radio.Button value="tree">
547+
树形
548+
</Radio.Button>
549+
<Radio.Button value="grid-tree">
550+
grid-tree
551+
</Radio.Button>
552+
</Radio.Group>
553+
</Tooltip>
511554
<Switch
512555
checkedChildren="数值挂列头"
513556
unCheckedChildren="数值挂行头"

‎packages/s2-vue/playground/App.vue‎

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
headerActionIcons,
2424
pivotSheetDataCfg,
2525
pivotSheetDataCfgForCompactMode,
26+
pivotSheetMultiLineTextDataCfg,
2627
s2ConditionsOptions,
2728
s2ThemeConfig,
2829
tableSheetDataCfg,
@@ -129,6 +130,12 @@ const onThemeChange = (e: any) => {
129130
};
130131
};
131132
133+
const onMaxLinesChange = (maxLines: number) => {
134+
updateDataCfg(
135+
maxLines > 1 ? pivotSheetMultiLineTextDataCfg : pivotSheetDataCfg,
136+
);
137+
};
138+
132139
const logHandler =
133140
(name: string, callback?: (...args: any[]) => void) =>
134141
(...args: any[]) => {
@@ -321,6 +328,29 @@ const setThemeCfg = (cb: any) => {
321328
</a-radio-group>
322329
</a-tooltip>
323330

331+
<a-input-number
332+
style="width: 120px"
333+
:min="0"
334+
placeholder="紧凑布局(附加宽)"
335+
:disabled="options?.style?.layoutWidthType !== 'compact'"
336+
:value="mergedOptions.style?.compactExtraWidth ?? 0"
337+
@change="
338+
(value) =>
339+
updateOptions({ style: { compactExtraWidth: value } })
340+
"
341+
/>
342+
<a-input-number
343+
style="width: 120px"
344+
:min="0"
345+
placeholder="紧凑布局(最小宽)"
346+
:disabled="options?.style?.layoutWidthType !== 'compact'"
347+
:value="mergedOptions.style?.compactMinWidth ?? 0"
348+
@change="
349+
(value) =>
350+
updateOptions({ style: { compactMinWidth: value } })
351+
"
352+
/>
353+
324354
<a-button
325355
danger
326356
@click="
@@ -334,7 +364,10 @@ const setThemeCfg = (cb: any) => {
334364
</a-button>
335365
</a-space>
336366

337-
<a-space class="filter-container">
367+
<a-space
368+
class="filter-container"
369+
style="margin-bottom: 20px; align-items: flex-start"
370+
>
338371
<a-switch
339372
checked-children="渲染组件"
340373
un-checked-children="卸载组件"
@@ -347,16 +380,19 @@ const setThemeCfg = (cb: any) => {
347380
:checked="mergedOptions.debug"
348381
@change="(checked) => updateOptions({ debug: checked })"
349382
/>
350-
<a-switch
351-
checked-children="树形"
352-
un-checked-children="平铺"
353-
:checked="mergedOptions.hierarchyType === 'tree'"
354-
@change="
355-
(checked) =>
356-
updateOptions({ hierarchyType: checked ? 'tree' : 'grid' })
357-
"
358-
:disabled="sheetType === 'table'"
359-
/>
383+
<a-tooltip title="透视表层级结构">
384+
<a-radio-group
385+
:value="mergedOptions.hierarchyType"
386+
:disabled="sheetType === 'table'"
387+
@change="
388+
(e) => updateOptions({ hierarchyType: e.target.value })
389+
"
390+
>
391+
<a-radio-button value="grid">平铺</a-radio-button>
392+
<a-radio-button value="tree">树形</a-radio-button>
393+
<a-radio-button value="grid-tree">grid-tree</a-radio-button>
394+
</a-radio-group>
395+
</a-tooltip>
360396
<a-switch
361397
checked-children="数值挂列头"
362398
un-checked-children="数值挂行头"
@@ -592,6 +628,7 @@ const setThemeCfg = (cb: any) => {
592628
:options="mergedOptions"
593629
:setOptions="setOptions"
594630
:setThemeCfg="setThemeCfg"
631+
:onMaxLinesChange="onMaxLinesChange"
595632
/>
596633
</a-collapse-panel>
597634
</a-collapse>

‎packages/s2-vue/playground/components/ResizeConfig.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const resizeConfig = () =>
109109

110110
<template>
111111
<div class="resize-config-container">
112-
<a-space class="filter-container">
112+
<a-space class="filter-container" style="margin-bottom: 20px">
113113
<span class="label">
114114
热区配置
115115
<a-divider type="vertical" />

0 commit comments

Comments
 (0)