Skip to content

Commit

Permalink
feat: ✨添加所有 root 的 props
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjone committed May 12, 2023
1 parent 97232cd commit 295c129
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 82 deletions.
25 changes: 24 additions & 1 deletion demo/demo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
data-id="index"
:data="ganttData"
:links="ganttLinks"
:border-color="borderColor"
show-checkbox
:show-expand="showExpand"
:expand-all="expandAll"
:show-today="true"
:show-weekend="true"
@row-click="onClickRow"
>
<x-gantt-column label="group1">
Expand Down Expand Up @@ -54,11 +60,16 @@
共{{ ganttData.length }}条
<button @click="onAdd">增加</button>
<button @click="onReduce">减少</button>
<button @click="onExpand">{{ showExpand ? '隐藏' : '展示' }}</button>
<button @click="expandAll = !expandAll">
{{ expandAll ? '闭合' : '展开' }}
</button>
<button @click="onChangeBorderColor">border颜色</button>
</div>
</template>

<script setup lang="ts">
import { reactive } from 'vue';
import { reactive, ref } from 'vue';
let id = 0;
Expand Down Expand Up @@ -104,6 +115,18 @@ const ganttLinks = [
}
];
const showExpand = ref(true);
function onExpand() {
showExpand.value = !showExpand.value;
}
const expandAll = ref(false);
const colors = ['red', 'blue', 'green', 'yellow', 'pink', 'orange'];
const borderColor = ref('black');
function onChangeBorderColor() {
borderColor.value = colors[Math.floor(Math.random() * colors.length)];
}
function onAdd() {
ganttData.push({
index: ++id,
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="zh-CN">

<head>
<meta charset="UTF-8" />
Expand Down
4 changes: 2 additions & 2 deletions src/components/column/selection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="level-block" :style="{ width: `${data!.level * indent}px` }" />

<div
v-if="!!data?.children?.length"
v-if="$styleBox.showExpand && !!data?.children?.length"
:class="['expand-icon', { 'expand-icon__expanded': data?.isExpand }]"
@click="
() => {
Expand Down Expand Up @@ -38,7 +38,7 @@ import { PropType, ref } from 'vue';
import useStyle from '@/composables/useStyle';
import useData from '@/composables/useData';
import RowItem from '@/models/data/row';
const { rowHeight } = useStyle();
const { rowHeight, $styleBox } = useStyle();
const checked = ref(false);
defineProps({
Expand Down
4 changes: 4 additions & 0 deletions src/components/column/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
box-sizing: border-box;
border-right: 1px solid;

&:nth-last-child(1) {
border-right: 0px;
}

& > div {
width: calc(100% - 12px);
overflow: hidden;
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/GanttBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<!-- 周末 -->
<template v-for="(date, i) in ganttHeader.dates">
<div
v-if="date.isWeekend()"
v-if="$styleBox.showWeekend && date.isWeekend()"
:key="i"
class="xg-gantt-body-date-line weekend"
:style="{
Expand Down Expand Up @@ -60,7 +60,7 @@ import LinkPath from './LinkPath.vue';
import useLinks from '@/composables/useLinks';
const { $slotsBox } = useSlotsBox();
const { bodyHeight } = useStyle();
const { bodyHeight, $styleBox } = useStyle();
const { ganttWidth, ganttColumnWidth } = useGanttWidth();
const { inView } = useInView();
const { todayLeft, showToday } = useToday();
Expand Down
9 changes: 7 additions & 2 deletions src/components/common/GanttHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
$param.hoverItem?.end.isSame(c.date, ganttHeader.unit))
}
]"
:style="{ ...$styleBox.getBorderColor() }"
:style="{
...$styleBox.getBorderColor(),
color: $styleBox.headerStyle?.textColor,
backgroundColor:
$styleBox.headerStyle?.bgColor || $styleBox.primaryColor
}"
:colspan="c.colSpan"
:rowspan="c.rowSpan"
>
Expand Down Expand Up @@ -76,7 +81,7 @@ onMounted(updateHeaderHeight);
border-bottom: 1px solid;
border-right: 1px solid;
font-size: 14px;
background-color: blueviolet;
background-color: #eca710;
}
.highlight {
Expand Down
5 changes: 3 additions & 2 deletions src/components/common/Row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
top: `${(props.data?.flatIndex ?? 0) * rowHeight}px`,
height: `${rowHeight}px`,
borderWidth: props.renderStyle ? '1px' : 0,
backgroundColor: props.renderStyle ? ($styleBox.levelColor[props.data!.level] ?? undefined) : undefined,
...$styleBox.getBorderColor()
}"
@mouseenter="onEnter"
Expand Down Expand Up @@ -69,10 +70,10 @@ function onDblClick() {
}
.xg-row.xg-row__hover {
background-color: #f0f0f0aa;
background-color: #f0f0f0aa !important;
}
.xg-row__select {
background-color: #e0e0e0aa;
background-color: #e0e0e0aa !important;
}
</style>
10 changes: 8 additions & 2 deletions src/components/common/TableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<table
ref="tableHeaderRef"
class="xg-table-header"
:style="{ height: `${$param.headerHeight}px` }"
:style="{
height: `${$param.headerHeight}px`,
color: $styleBox.headerStyle?.textColor,
backgroundColor: $styleBox.headerStyle?.bgColor || $styleBox.primaryColor
}"
cellpadding="0"
cellspacing="0"
border="0"
Expand All @@ -26,8 +30,10 @@ import useParams from '@/composables/useParam';
import TableHeaderTh from './TableHeaderTh.vue';
import useElement from '@/composables/useElement';
import { onMounted } from 'vue';
import useStyle from '@/composables/useStyle';
const { $slotsBox } = useSlotsBox();
const { $styleBox } = useStyle();
const { $param } = useParams();
const { tableHeaderRef, updateHeaderHeight } = useElement();
Expand All @@ -37,7 +43,7 @@ onMounted(updateHeaderHeight);
<style lang="scss" scoped>
.xg-table-header {
width: 100%;
background-color: blueviolet;
background-color: #eca710;
table-layout: fixed;
border-collapse: separate;
top: 0;
Expand Down
56 changes: 22 additions & 34 deletions src/components/common/TableHeaderTh.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,30 @@ onResizeTableColumn(headerRef, {
</script>

<style lang="scss" scoped>
.xg-table-header {
width: 100%;
height: 80px;
background-color: blueviolet;
table-layout: fixed;
border-collapse: separate;
top: 0;
position: sticky;
z-index: 10;
.xg-table-header-cell {
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
text-align: center;
position: relative;
box-sizing: border-box;
border-bottom: 1px solid;
border-right: 1px solid;
padding: 0 12px;
font-size: 14px;
pointer-events: none;
}
.xg-table-header-cell {
overflow: hidden;
text-overflow: ellipsis;
vertical-align: middle;
text-align: left;
position: relative;
box-sizing: border-box;
border-bottom: 1px solid;
border-right: 1px solid;
padding: 0 20px;
font-size: 14px;
pointer-events: none;
}
.cell-resizable {
&::after {
content: '';
position: absolute;
right: -5px;
top: 0;
bottom: 0;
width: 10px;
cursor: col-resize;
pointer-events: auto;
}
.cell-resizable {
&::after {
content: '';
position: absolute;
right: -5px;
top: 0;
bottom: 0;
width: 10px;
cursor: col-resize;
pointer-events: auto;
}
}
</style>
12 changes: 2 additions & 10 deletions src/components/root/rootProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
},

/**
* 接收一个表头高度,应该保证大于30,默认值为60
* 接收一个表头高度,默认值为80。如果高度过小,且表头过于复杂,可能会引起高度异常
*/
headerHeight: {
type: [Number, String],
Expand Down Expand Up @@ -107,7 +107,7 @@ export default {
throw new Error(
`${
Errors.header + Errors.invalidProps
}"border" should be a positive integer.`
}"border" should be a nonnegative integer.`
);
}
return r;
Expand Down Expand Up @@ -218,14 +218,6 @@ export default {
default: '#eca710'
},

/**
* 显示设置按钮
*/
showSettingBtn: {
type: Boolean,
default: true
},

/**
* 日期单位
*/
Expand Down
24 changes: 22 additions & 2 deletions src/composables/useData.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import type rootProps from '@/components/root/rootProps';
import type RowItem from '@/models/data/row';
import { useStore } from '@/store';
import { computed, toRaw, watch, type Ref } from 'vue';
import { computed, type ExtractPropTypes, toRaw, watch, type Ref } from 'vue';
import useGanttHeader from './useGanttHeader';

export default () => {
const store = useStore();
const { setGanttHeaders } = useGanttHeader();

function initData(data: Ref<any[]>, props: any) {
function initData(
data: Ref<any[]>,
props: ExtractPropTypes<typeof rootProps>
) {
const options: DataOptions = {
dataId: props.dataId,
isExpand: !props.showExpand || props.expandAll,
Expand All @@ -29,6 +33,22 @@ export default () => {
},
{ deep: true }
);

watch(
() => props.showExpand,
() => {
store.$data.updateExpand(true);
store.$links.update(store.$data.flatData);
}
);

watch(
() => props.expandAll,
val => {
store.$data.updateExpand(!props.showExpand || val);
store.$links.update(store.$data.flatData);
}
);
}

function toRowData(data?: RowItem): RowData {
Expand Down
27 changes: 13 additions & 14 deletions src/composables/useGanttWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ export default () => {
const store = useStore();

const ganttColumnWidth = computed(() => {
// const size = store.$styleBox.ganttColumnSize;
// switch (size) {
// case 'small':
// if (store.$styleBox.unit === 'week') return 7;
// return 15;
// case 'large':
// if (store.$styleBox.unit === 'week') return 30;
// return 60;
// case 'normal':
// default:
// if (store.$styleBox.unit === 'week') return 15;
// return 30;
// }
return 30;
const size = store.$styleBox.ganttColumnSize;
switch (size) {
case 'small':
if (store.$styleBox.unit === 'week') return 7;
return 20;
case 'large':
if (store.$styleBox.unit === 'week') return 30;
return 60;
case 'normal':
default:
if (store.$styleBox.unit === 'week') return 15;
return 30;
}
});

const ganttWidth = computed(() => {
Expand Down
Loading

0 comments on commit 295c129

Please sign in to comment.