Skip to content

Commit

Permalink
feat: GanttColumnSize支持使用对象自定义宽度
Browse files Browse the repository at this point in the history
  • Loading branch information
yanminxing committed Oct 10, 2023
1 parent a9c19fe commit b7fab5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/components/root/rootProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,16 @@ export default {
* 甘特图表的每一列宽度
*/
ganttColumnSize: {
type: String as PropType<GanttColumnSize> | number,
type: String as
| PropType<GanttColumnSize>
| object as PropType<ColumnSizeObject>,
default: 'normal',
validator: (v: GanttColumnSize) => {
return typeof v === 'number' || ['small', 'normal', 'large'].includes(v);
return typeof v === 'string'
? ['small', 'normal', 'large'].includes(v)
: !Object.keys(v).some(
k => !['hour', 'day', 'week', 'month'].includes(k)
) && !['hour', 'day', 'week', 'month'].some(k => !v[k]);
}
},

Expand Down
4 changes: 3 additions & 1 deletion src/composables/useGanttWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export default () => {

const ganttColumnWidth = computed(() => {
const size = store.$styleBox.ganttColumnSize;
if (typeof size === 'number') return size;
if (typeof size === 'object') {
return size[store.ganttHeader.unit];
}
return Variables.size.ganttColumnWidth[size][store.ganttHeader.unit];
});

Expand Down
9 changes: 8 additions & 1 deletion src/typings/size.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
declare type GanttColumnSize = 'small' | 'normal' | 'large' | number;
// 对象方式设置甘特图列宽
declare interface ColumnSizeObject {
hour: number;
day: number;
week: number;
month: number;
}
declare type GanttColumnSize = 'small' | 'normal' | 'large' | ColumnSizeObject;

0 comments on commit b7fab5c

Please sign in to comment.