vxe-gantt vue table 甘特图子任务多层级自定义模板用法

news/2025/12/7 10:10:50/文章来源:https://www.cnblogs.com/qaz666/p/19317671

vxe-gantt vue table 甘特图子任务多层级自定义模板用法,通过树结构来渲染多层级的子任务,将数据带有父子层级的数组进行渲染

查看官网:https://gantt.vxeui.com/
gitbub:https://github.com/x-extends/vxe-gantt
gitee:https://gitee.com/x-extends/vxe-gantt

安装

npm install xe-utils@3.8.0 vxe-pc-ui@4.10.45 vxe-table@4.17.26 vxe-gantt@4.1.2
// ...
import VxeUIBase from 'vxe-pc-ui'
import 'vxe-pc-ui/es/style.css'import VxeUITable from 'vxe-table'
import 'vxe-table/es/style.css'import VxeUIGantt from 'vxe-gantt'
import 'vxe-gantt/lib/style.css'
// ...createApp(App).use(VxeUIBase).use(VxeUITable).use(VxeUIGantt).mount('#app')
// ...

效果

image

代码

树结构由 tree-config 和 column.tree-node 参数开启,支持自动转换带有父子层级字段的平级列表数据,例如 { id: 'xx', parentId: 'xx' }。只需要设置 tree-config.transform 就可以开启自动转换,通过 task-view-config.scales.headerCellStyle 自定义列头样式

<template><div><vxe-gantt v-bind="ganttOptions"><template #task-bar="{ row }"><div class="custom-task-bar" :style="{ backgroundColor: row.bgColor }"><div class="custom-task-bar-img"><vxe-image :src="row.imgUrl" width="60" height="60"></vxe-image></div><div><div>{{ row.title }}</div><div>开始日期:{{ row.start }}</div><div>结束日期:{{ row.end }}</div><div>进度:{{ row.progress }}%</div></div></div></template><template #task-bar-tooltip="{ row }"><div><div>任务名称:{{ row.title }}</div><div>开始时间:{{ row.start }}</div><div>结束时间:{{ row.end }}</div><div>进度:{{ row.progress }}%</div></div></template></vxe-gantt></div>
</template><script setup>
import { reactive } from 'vue'const ganttOptions = reactive({border: true,height: 600,cellConfig: {height: 100},treeConfig: {transform: true,rowField: 'id',parentField: 'parentId'},taskViewConfig: {tableStyle: {width: 380},showNowLine: true,scales: [{ type: 'month' },{type: 'day',headerCellStyle ({ dateObj }) {// 周日高亮if (dateObj.e === 0) {return {backgroundColor: '#f9f0f0'}}return {}}},{type: 'date',headerCellStyle ({ dateObj }) {// 周日高亮if (dateObj.e === 0) {return {backgroundColor: '#f9f0f0'}}return {}}}],viewStyle: {cellStyle ({ dateObj }) {// 周日高亮if (dateObj.e === 0) {return {backgroundColor: '#f9f0f0'}}return {}}}},taskBarConfig: {showTooltip: true,barStyle: {round: true}},columns: [{ field: 'title', title: '任务名称', treeNode: true },{ field: 'start', title: '开始时间', width: 100 },{ field: 'end', title: '结束时间', width: 100 }],data: [{ id: 10001, parentId: null, title: '任务1', start: '2024-03-03', end: '2024-03-10', progress: 20, bgColor: '#c1c452', imgUrl: 'https://vxeui.com/resource/productImg/product9.png' },{ id: 10002, parentId: 10001, title: '任务2', start: '2024-03-05', end: '2024-03-12', progress: 15, bgColor: '#fd9393', imgUrl: 'https://vxeui.com/resource/productImg/product8.png' },{ id: 10003, parentId: 10001, title: '任务3', start: '2024-03-10', end: '2024-03-21', progress: 25, bgColor: '#92c1f1', imgUrl: 'https://vxeui.com/resource/productImg/product1.png' },{ id: 10004, parentId: 10002, title: '任务4', start: '2024-03-15', end: '2024-03-24', progress: 70, bgColor: '#fad06c', imgUrl: 'https://vxeui.com/resource/productImg/product3.png' },{ id: 10005, parentId: 10003, title: '任务5', start: '2024-03-20', end: '2024-04-05', progress: 50, bgColor: '#e78dd2', imgUrl: 'https://vxeui.com/resource/productImg/product11.png' },{ id: 10006, parentId: null, title: '任务6', start: '2024-03-22', end: '2024-03-29', progress: 38, bgColor: '#8be1e6', imgUrl: 'https://vxeui.com/resource/productImg/product7.png' },{ id: 10007, parentId: null, title: '任务7', start: '2024-03-28', end: '2024-04-04', progress: 24, bgColor: '#78e6d1', imgUrl: 'https://vxeui.com/resource/productImg/product5.png' },{ id: 10008, parentId: 10007, title: '任务8', start: '2024-05-18', end: '2024-05-28', progress: 65, bgColor: '#edb695', imgUrl: 'https://vxeui.com/resource/productImg/product4.png' },{ id: 10009, parentId: 10008, title: '任务9', start: '2024-05-05', end: '2024-05-28', progress: 78, bgColor: '#92c1f1', imgUrl: 'https://vxeui.com/resource/productImg/product6.png' },{ id: 10010, parentId: 10008, title: '任务10', start: '2024-04-28', end: '2024-05-17', progress: 19, bgColor: '#92c1f1', imgUrl: 'https://vxeui.com/resource/productImg/product5.png' },{ id: 10011, parentId: 10009, title: '任务11', start: '2024-04-01', end: '2024-05-01', progress: 100, bgColor: '#fd9393', imgUrl: 'https://vxeui.com/resource/productImg/product4.png' },{ id: 10012, parentId: 10009, title: '任务12', start: '2024-04-09', end: '2024-04-22', progress: 90, bgColor: '#fd9393', imgUrl: 'https://vxeui.com/resource/productImg/product8.png' },{ id: 10013, parentId: 10010, title: '任务13', start: '2024-03-22', end: '2024-04-05', progress: 86, bgColor: '#fad06c', imgUrl: 'https://vxeui.com/resource/productImg/product11.png' },{ id: 10014, parentId: null, title: '任务14', start: '2024-04-05', end: '2024-04-18', progress: 65, bgColor: '#8be1e6', imgUrl: 'https://vxeui.com/resource/productImg/product6.png' },{ id: 10015, parentId: 10014, title: '任务15', start: '2024-03-05', end: '2024-03-18', progress: 48, bgColor: '#edb695', imgUrl: 'https://vxeui.com/resource/productImg/product11.png' },{ id: 10016, parentId: null, title: '任务16', start: '2024-03-01', end: '2024-03-28', progress: 28, bgColor: '#e78dd2', imgUrl: 'https://vxeui.com/resource/productImg/product12.png' },{ id: 10017, parentId: null, title: '任务17', start: '2024-03-19', end: '2024-04-02', progress: 36, bgColor: '#c1c452', imgUrl: 'https://vxeui.com/resource/productImg/product5.png' }]
})
</script><style lang="scss" scoped>
.custom-task-bar {display: flex;flex-direction: row;padding: 8px 16px;width: 100%;font-size: 12px;
}
.custom-task-bar-img {display: flex;flex-direction: row;align-items: center;justify-content: center;width: 70px;height: 70px;
}
</style>

https://gitee.com/x-extends/vxe-gantt

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/991206.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2025年质量好的碳分子筛CMS-260型/GXN-CMS型碳分子筛直销制造

2025年质量好的碳分子筛CMS-260型/GXN-CMS型碳分子筛直销制造碳分子筛行业背景与市场趋势碳分子筛(Carbon Molecular Sieve,简称CMS)作为一种高效吸附材料,在气体分离领域发挥着不可替代的作用。随着全球工业的快速…

【20251028】固定Ubuntu的IP地址 - 指南

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

2025年知名的行星式搅拌机/上海双行星式搅拌机最新TOP品牌厂家排行

2025年知名的行星式搅拌机/上海双行星式搅拌机TOP品牌厂家排行行业背景与市场趋势随着精细化工、新材料、新能源等行业的快速发展,行星式搅拌机作为关键生产设备,市场需求持续增长。2024-2025年,全球行星式搅拌机市…

2025年知名的精冲工艺门锁/精冲工艺调节功能家具行业内口碑厂家排行榜

2025年知名的精冲工艺门锁/精冲工艺调节功能家具行业内口碑厂家排行榜行业背景与市场趋势随着全球制造业向精密化、高效化方向不断发展,精冲工艺作为一种先进的金属成形技术,正在家具、门锁及功能调节部件领域展现出…

2025年知名的加厚雨衣厂家最新实力排行

2025年知名的加厚雨衣厂家实力排行行业背景与市场趋势随着全球气候变化加剧,极端天气事件频发,防护用品的市场需求呈现持续增长态势。根据市场调研数据显示,2025年中国雨衣市场规模预计将达到85亿元人民币,年复合增…

2025年质量好的可弯曲弹性磨切割片/切割机切割片厂家最新权威实力榜

2025年质量好的可弯曲弹性磨切割片/切割机切割片厂家权威实力榜行业背景与市场趋势随着全球制造业的持续升级和基础设施建设的不断推进,切割片作为工业加工中不可或缺的消耗品,市场需求呈现稳定增长态势。2025年,全…

专业视角:PET胶带涂布机厂商的选择与推荐

在工业生产领域,PET胶带涂布机的重要性不言而喻。它广泛应用于各类胶带生产,对于保证胶带质量和生产效率起着关键作用。那么,PET胶带涂布机生产厂哪家专业?选PET胶带涂布机厂商需关注什么?哪个品牌适合低速涂布?…

2025年比较大的哈尔滨金融律师事务所口碑排行榜

2025年哈尔滨金融律师事务所口碑排行榜:专业服务与市场趋势分析行业背景与市场趋势随着中国金融市场的持续发展和法治建设的深入推进,金融法律服务需求呈现爆发式增长。作为东北地区重要的金融中心,哈尔滨近年来金融…

Excel炒股法:回本年限计算

散户乙说他在2014年,究竟选择茅台还是老窖的问题上,进行过计算,因为老窖回本比茅台快(好像是10年),所以选择了老窖。一直对这个问题比较好奇,今天打算研究研究。直觉可以用roe/pb,来计算理论的年化,再计算收益…

2025年口碑好的全包围汽车脚垫品牌推荐:看哪家汽车脚垫品质

为帮助车主避开劣质汽车脚垫的安全隐患与健康风险,精准锁定适配需求的高品质产品,我们从环保材质认证、贴合工艺精度、全包围防护能力、安全性能及用户口碑五大核心维度展开测评,终筛选出2025年的十大汽车脚垫品牌。…

2025防伪标签定制厂家有哪些?靠谱定制厂家精选清单

2025防伪标签定制厂家有哪些?靠谱定制厂家精选清单!在选择防伪标签定制厂家时,企业需综合考虑多个因素,以确保产品的可靠性和长期使用效果。首先,应关注厂家的技术实力,包括是否拥有自主知识产权和专利技术,这直…

P4168 蒲公英 分块

把信息全部按块处理,在本题中体现的是块内众数(p[i])和块间次数(sum[i][j]) Remarks: 1.桶暴力 2.离散化 3.前缀和 #include<bits/stdc++.h> #define ll long long #define maxn 40003 #define inf 1e9+2 using…

2025防静电吸盘厂家哪家好?海绵吸盘定制厂家实力榜单

2025防静电吸盘厂家哪家好?海绵吸盘定制厂家实力榜单!在精密制造、电子加工等领域,防静电吸盘的品质直接影响生产效率与产品良率,而 “海绵吸盘定制厂家哪家好” 也是众多企业采购时的核心疑问。选择靠谱的防静电吸…

2025真空吸盘定制厂家哪家好?优质真空吸盘厂家精选指南

2025真空吸盘定制厂家哪家好?优质真空吸盘厂家精选指南!一、开篇:挑选真空吸盘定制厂家的关键要点在现代工业生产中,真空吸盘作为一种高效的物料搬运工具,广泛应用于自动化生产线、物流仓储、电子制造等众多领域。…

江西cpe膜厂家哪家好?2025复合包装袋定制厂家实力推荐

CPE 膜(流延聚乙烯薄膜)作为复合包装袋的核心基材,如今在服装、食品、电子等行业应用越来越广。从现状看,江西凭借塑料产业集群优势,已成为南方地区重要的 CPE 膜生产基地,当地厂家年产 CPE 膜总量占全国 15% 左…

鑫金鼎隔热条怎么样?隔热条品牌排名前十盘点

鑫金鼎隔热条怎么样?隔热条品牌盘点选择隔热条品牌,核心要关注三点:产品性能是否适配使用环境,生产实力能否保障稳定供应,是否符合环保与安全相关标准。把握这三点,能更精准找到适合的产品,避免后期使用踩坑。一…

2025加速度计厂家怎么挑?这些靠谱厂家值得关注

2025加速度计厂家怎么挑?这些靠谱厂家值得关注!加速度计挑选秘籍加速度计作为一种能够测量加速度的传感器,在工业制造、航空航天、汽车电子、医疗设备等众多领域都有着举足轻重的地位。在工业制造中,它可用于监测机…

2025年口碑好的抽条韩国绒厂家推荐及采购指南

2025年口碑好的抽条韩国绒厂家推荐及采购指南行业背景与市场趋势随着全球纺织产业的持续升级和消费需求的多元化发展,抽条韩国绒作为一种兼具舒适性与时尚感的面料,近年来在服装、家纺等领域获得了广泛关注。2025年,…

找2025IMU 生产厂家/惯性测量单元厂家?精准匹配优质供

找2025IMU生产厂家/惯性测量单元厂家?精准匹配优质供应商!在选择惯性测量单元(IMU)生产厂家时,企业需综合考虑多个因素,以确保产品匹配实际应用需求。首先,应评估厂家的技术研发能力,包括是否具备自主设计、测试…

2025非标定制吸杆厂家哪家好?优质内缩吸杆定制厂家汇总

2025非标定制吸杆厂家哪家好?优质内缩吸杆定制厂家汇总!在选择非标定制吸杆厂家时,需重点关注其技术适配性与综合服务能力。首先,应评估厂家的研发实力,包括是否具备独立设计能力、能否理解复杂工况并提供解决方案…