11<template >
22 <div >
3- <vxe-gantt ref =" ganttRef" v-bind =" ganttOptions" v-on =" ganttEvents" ></vxe-gantt >
3+ <vxe-select v-model =" rowSize" :options =" dataOptions" @change =" changeRowSizeEvent" ></vxe-select >
4+
5+ <vxe-gantt v-bind =" ganttOptions" ></vxe-gantt >
46 </div >
57</template >
68
79<script lang="ts" setup>
810import { ref , reactive } from ' vue'
9- import { VxeUI } from ' vxe-pc-ui'
10- import type { VxeGanttInstance , VxeGanttProps , VxeGanttListeners } from ' ../../../types'
11+ import { VxeGanttProps } from ' ../../../types'
1112
1213interface RowVO {
1314 id: number
@@ -17,73 +18,98 @@ interface RowVO {
1718 progress: number
1819}
1920
20- const ganttRef = ref <VxeGanttInstance <RowVO >>()
21+ const rowSize = ref (500 )
22+
23+ const dataOptions = ref ([
24+ { label: ' 加载 3 行' , value: 3 },
25+ { label: ' 加载 20 行' , value: 20 },
26+ { label: ' 加载 100 行' , value: 100 },
27+ { label: ' 加载 500 行' , value: 500 },
28+ { label: ' 加载 1000 行' , value: 1000 },
29+ { label: ' 加载 5000 行' , value: 5000 },
30+ { label: ' 加载 10000 行' , value: 10000 },
31+ { label: ' 加载 50000 行' , value: 50000 },
32+ { label: ' 加载 100000 行' , value: 100000 }
33+ ])
2134
2235const ganttOptions = reactive <VxeGanttProps <RowVO >>({
2336 border: true ,
24- showFooter: true ,
37+ loading: false ,
38+ showOverflow: true ,
39+ showHeaderOverflow: true ,
40+ showFooterOverflow: true ,
41+ height: 600 ,
2542 rowConfig: {
26- keyField: ' id' ,
27- isCurrent: true
28- },
29- columnConfig: {
30- resizable: true
43+ keyField: ' id' // 行主键
3144 },
3245 taskBarConfig: {
33- showProgress: true ,
34- showContent: true
46+ showProgress: true , // 是否显示进度条
47+ showContent: true , // 是否在任务条显示内容
48+ moveable: true , // 是否允许拖拽任务移动日期
49+ resizable: true , // 是否允许拖拽任务调整日期
50+ barStyle: {
51+ round: true , // 圆角
52+ bgColor: ' #fca60b' , // 任务条的背景颜色
53+ completedBgColor: ' #65c16f' // 已完成部分任务条的背景颜色
54+ }
3555 },
3656 taskViewConfig: {
37- scales: [' year' , ' quarter' , ' month' , ' date' ],
3857 tableStyle: {
39- width: 480
58+ width: 480 // 表格宽度
4059 }
4160 },
42- taskViewScaleConfig: {
43- // scaleUnit: 'week'
61+ virtualYConfig: {
62+ gt: 0 ,
63+ enabled: true
4464 },
4565 columns: [
46- { type: ' seq' },
66+ { type: ' seq' , width: 70 },
4767 { field: ' title' , title: ' 任务名称' },
4868 { field: ' start' , title: ' 开始时间' , width: 100 },
49- { field: ' end' , title: ' 结束时间' , width: 100 }
69+ { field: ' end' , title: ' 结束时间' , width: 100 },
70+ { field: ' progress' , title: ' 进度(%)' , width: 80 }
5071 ],
5172 data: [
52- { id: 10001 , title: ' A项目' , start: ' 2024-03-01' , end: ' 2024-03-04' , progress: 3 },
53- { id: 10002 , title: ' 城市道路修理进度' , start: ' 2024-03-03' , end: ' 2024-03-08' , progress: 10 },
54- { id: 10003 , title: ' B大工程' , start: ' 2024-03-03' , end: ' 2024-03-11' , progress: 90 },
55- { id: 10004 , title: ' 超级大工程' , start: ' 2024-02-26 07:30:00' , end: ' 2024-02-28 09:00:00' , progress: 15 },
56- { id: 10005 , title: ' 地球净化项目' , start: ' 2024-03-01' , end: ' 2024-03-05' , progress: 100 },
57- { id: 10006 , title: ' 一个小目标项目' , start: ' 2024-03-04' , end: ' 2024-03-08' , progress: 5 },
58- { id: 10007 , title: ' 某某计划7' , start: ' 2024-03-05' , end: ' 2024-03-09' , progress: 70 },
59- { id: 10008 , title: ' 某某科技项目8' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 50 },
60- { id: 10009 , title: ' 地铁建设工程9' , start: ' 2024-03-02' , end: ' 2024-03-04' , progress: 5 },
61- { id: 10010 , title: ' 铁路修建计划10' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 10 },
62- { id: 10011 , title: ' 铁路修建计划11' , start: ' 2024-03-04' , end: ' 2024-03-08' , progress: 10 },
63- { id: 10012 , title: ' 铁路修建计划12' , start: ' 2024-03-02' , end: ' 2024-03-04' , progress: 10 },
64- { id: 10013 , title: ' 铁路修建计划13' , start: ' 2024-03-08' , end: ' 2024-03-12' , progress: 10 },
65- { id: 10014 , title: ' 铁路修建计划14' , start: ' 2024-03-11' , end: ' 2024-03-19' , progress: 10 },
66- { id: 10015 , title: ' 铁路修建计划15' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 10 },
67- { id: 10016 , title: ' 铁路修建计划16' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 10 },
68- { id: 10017 , title: ' 铁路修建计划17' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 10 },
69- { id: 10018 , title: ' 铁路修建计划18' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 10 },
70- { id: 10019 , title: ' 铁路修建计划19' , start: ' 2024-03-01' , end: ' 2024-03-03' , progress: 10 }
71- ],
72- footerData: [
73- { title: ' 合计' , start: 111 , end: 222 }
73+ { id: 10001 , title: ' 任务1' , start: ' 2024-03-01' , end: ' 2024-03-04' , progress: 3 },
74+ { id: 10002 , title: ' 任务2' , start: ' 2024-03-03' , end: ' 2024-03-08' , progress: 10 },
75+ { id: 10003 , title: ' 任务3' , start: ' 2024-03-03' , end: ' 2024-03-11' , progress: 90 },
76+ { id: 10004 , title: ' 任务4' , start: ' 2024-03-05' , end: ' 2024-03-11' , progress: 15 },
77+ { id: 10005 , title: ' 任务5' , start: ' 2024-03-08' , end: ' 2024-03-15' , progress: 100 },
78+ { id: 10006 , title: ' 任务6' , start: ' 2024-03-10' , end: ' 2024-03-21' , progress: 5 },
79+ { id: 10007 , title: ' 任务7' , start: ' 2024-03-15' , end: ' 2024-03-24' , progress: 70 },
80+ { id: 10008 , title: ' 任务8' , start: ' 2024-03-05' , end: ' 2024-03-15' , progress: 50 },
81+ { id: 10009 , title: ' 任务9' , start: ' 2024-03-19' , end: ' 2024-03-20' , progress: 5 },
82+ { id: 10010 , title: ' 任务10' , start: ' 2024-03-12' , end: ' 2024-03-20' , progress: 10 },
83+ { id: 10011 , title: ' 任务11' , start: ' 2024-03-01' , end: ' 2024-03-08' , progress: 90 },
84+ { id: 10012 , title: ' 任务12' , start: ' 2024-03-03' , end: ' 2024-03-06' , progress: 60 },
85+ { id: 10013 , title: ' 任务13' , start: ' 2024-03-02' , end: ' 2024-03-05' , progress: 50 },
86+ { id: 10014 , title: ' 任务14' , start: ' 2024-03-04' , end: ' 2024-03-15' , progress: 0 },
87+ { id: 10015 , title: ' 任务15' , start: ' 2024-03-01' , end: ' 2024-03-05' , progress: 30 }
7488 ]
7589})
7690
77- const ganttEvents: VxeGanttListeners <RowVO > = {
78- cellMenu ({ row }) {
79- const $gantt = ganttRef .value
80- if ($gantt ) {
81- $gantt .setCurrentRow (row )
91+ // 模拟行数据
92+ const loadList = (size = 200 ) => {
93+ ganttOptions .loading = true
94+ setTimeout (() => {
95+ const dataList: RowVO [] = []
96+ for (let i = 0 ; i < size ; i ++ ) {
97+ dataList .push ({
98+ id: 10000 + i ,
99+ title: ` 任务${i + 1 } ` ,
100+ start: i % 3 ? ' 2024-03-03' : i % 2 ? ' 2024-03-10' : ' 2024-03-22' ,
101+ end: i % 3 ? ' 2024-03-11' : i % 2 ? ' 2024-03-19' : ' 2024-04-04' ,
102+ progress: i % 2 ? 50 : 30
103+ })
82104 }
83- },
84- menuClick (e ) {
85- console .log (e )
86- VxeUI .modal .message ({ content: ` 点击了 ${e .menu .code } ` , status: ' success' })
87- }
105+ ganttOptions .data = dataList
106+ ganttOptions .loading = false
107+ }, 150 )
108+ }
109+
110+ const changeRowSizeEvent = () => {
111+ loadList (rowSize .value )
88112}
113+
114+ loadList (rowSize .value )
89115 </script >
0 commit comments