Skip to content

Commit

Permalink
fix: 🐛表头拖拽后左右高度不一致
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 1, 2023
1 parent 9f1a1e9 commit ddca95c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/components/common/GanttHeader.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<template>
<table class="xg-gantt-header" cellpadding="0" cellspacing="0" border="0">
<table
class="xg-gantt-header"
:style="{ height: `${$param.headerHeight}px` }"
cellpadding="0"
cellspacing="0"
border="0"
>
<colgroup>
<template v-for="i in dateList[1].length" :key="i">
<col :width="`${ganttColumnWidth}px`" />
Expand All @@ -26,7 +32,9 @@
import useData from '@/composables/useData';
import useGanttWidth from '@/composables/useGanttWidth';
import useStyle from '@/composables/useStyle';
import useParam from '@/composables/useParam';
const { $param } = useParam();
const { $styleBox } = useStyle();
const { dateList } = useData();
const { ganttColumnWidth } = useGanttWidth();
Expand All @@ -35,7 +43,6 @@ const { ganttColumnWidth } = useGanttWidth();
<style lang="scss" scoped>
.xg-gantt-header {
width: 100%;
height: 80px;
background-color: blueviolet;
table-layout: fixed;
border-collapse: separate;
Expand Down
31 changes: 27 additions & 4 deletions src/components/common/TableHeader.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
<template>
<table class="xg-table-header" cellpadding="0" cellspacing="0" border="0">
<table
ref="tableRef"
class="xg-table-header"
:style="{ height: `${$param.headerHeight}px` }"
cellpadding="0"
cellspacing="0"
border="0"
>
<colgroup>
<template v-for="(c, i) in $slotsBox.tableHeaders.leafs" :key="i">
<col :width="c.width" />
</template>
</colgroup>
<thead>
<tr v-for="(r, trIndex) in $slotsBox.tableHeaders.headers" :key="trIndex">
<TableHeaderTh v-for="(c, i) in r" :key="i" :column="c" />
<TableHeaderTh
v-for="(c, i) in r"
:key="i"
:column="c"
@resize="onResize"
/>
</tr>
</thead>
</table>
</template>

<script lang="ts" setup>
import TableHeaderTh from './TableHeaderTh.vue';
import { nextTick, ref } from 'vue';
import useSlotsBox from '@/composables/useSlotsBox';
import useParams from '@/composables/useParam';
import TableHeaderTh from './TableHeaderTh.vue';
import Variables from '@/constants/vars';
const { $slotsBox } = useSlotsBox();
const { $param } = useParams();
const tableRef = ref<HTMLElement | null>(null);
const onResize = () => {
nextTick(() => {
const table = tableRef.value;
$param.headerHeight = table?.clientHeight ?? Variables.default.headerHeight;
});
};
</script>

<style lang="scss" scoped>
.xg-table-header {
width: 100%;
height: 80px;
background-color: blueviolet;
table-layout: fixed;
border-collapse: separate;
Expand Down
8 changes: 6 additions & 2 deletions src/components/common/TableHeaderTh.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const props = defineProps({
}
});
const emit = defineEmits(['resize']);
const { $slotsBox } = useSlotsBox();
const { $styleBox } = useStyle();
Expand All @@ -46,12 +48,14 @@ onResizeTableColumn(headerRef, {
onEnd: x => {
$slotsBox.tableHeaders.leafs[index].width = Math.max(
$slotsBox.tableHeaders.leafs[index].width + x,
20
40
);
emit('resize');
},
preMove: (x, clientX) => {
if ($slotsBox.tableHeaders.leafs[index].width + x < 20) return false;
if ($slotsBox.tableHeaders.leafs[index].width + x < 40) return false;
return true;
}
});
Expand Down
9 changes: 9 additions & 0 deletions src/models/param/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ export default class Param {
public set showMoveLine(v: boolean) {
this._showMoveLine = v;
}

private _headerHeight: number = 80;
public get headerHeight(): number {
return this._headerHeight;
}

public set headerHeight(v: number) {
this._headerHeight = v;
}
}

0 comments on commit ddca95c

Please sign in to comment.