Skip to content

Commit

Permalink
fix: 表头高度属性不生效
Browse files Browse the repository at this point in the history
由于表头使用了动态计算,可能会导致不会按照参数预期高度展示,会取 `可能的最小值` 与 `给定参数值` 的最大值作为最终展示值。

fix #127
  • Loading branch information
xpyjs committed Aug 16, 2024
1 parent 6731e6f commit 8a2782d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/composables/useElement.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import Variables from '@/constants/vars';
import useStore from '@/store';
import useParam from './useParam';
import useStyle from './useStyle';

export default () => {
const { $param } = useParam();
const { $styleBox } = useStyle();
const { tableHeaderRef, ganttHeaderRef, ganttBodyRef, ganttRef } = useStore();

function getMaxHeaderHeight() {
return Math.max(
tableHeaderRef.value?.clientHeight ?? 0,
ganttHeaderRef.value?.clientHeight ?? 0,
Variables.default.headerHeight
Variables.size.minHeaderHeight
);
}

function updateHeaderHeight() {
if (!$param.headerHeight) return;

// 删除 ref 中 style 的 height 属性,以便获取真实高度
tableHeaderRef.value?.style.removeProperty('height');
ganttHeaderRef.value?.style.removeProperty('height');

const maxHeight = getMaxHeaderHeight();
let maxHeight = getMaxHeaderHeight();
if ($param.headerHeight !== maxHeight) {
$param.headerHeight = maxHeight;
}

// 重新设置高度
if ($styleBox.headerHeight) {
maxHeight = Math.max($styleBox.headerHeight, maxHeight);
}

tableHeaderRef.value &&
(tableHeaderRef.value.style.height = `${maxHeight}px`);
ganttHeaderRef.value &&
Expand Down
1 change: 1 addition & 0 deletions src/composables/useStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default () => {
store.$styleBox.draggable = props.draggable;
store.$styleBox.holidays = props.holidays;
store.$styleBox.formatGanttHeader = props.formatGanttHeader;
store.$styleBox.headerHeight = props.headerHeight;
};

fn();
Expand Down
13 changes: 13 additions & 0 deletions src/models/param/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ export default class StyleBox {
}
}

private _headerHeight: number | undefined;
public get headerHeight(): number | undefined {
return this._headerHeight;
}

public set headerHeight(v: number | string) {
if (typeof v === 'string') {
this._headerHeight = parseInt(v);
} else {
this._headerHeight = v;
}
}

private _showCheckbox: boolean = false;
public get showCheckbox(): boolean {
return this._showCheckbox;
Expand Down

0 comments on commit 8a2782d

Please sign in to comment.