vue使用甘特图dhtmlxgantt + gantt.addTaskLayer

本文主要是介绍vue使用甘特图dhtmlxgantt + gantt.addTaskLayer,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果图:

甘特图
  • 官网地址

gantt安装与使用

vue版---部分功能收费
  1. 安装gantt  或  引入文件

    npm install dhtmlx-gantt -save或import gantt from "/public/static/dhtmlxgantt/dhtmlxgantt.js";
    import "/public/static/dhtmlxgantt/locale/locale_cn.js";
  2. 引入---组件

<template>
#节点高度要给,gantt不根据内容撑开<div ref="gantt" class="gantt-container" style="min-height: calc(85vh - 100px); width: 100%; overflow: hidden"></div>
</template>
<script>import gantt from "/public/static/dhtmlxgantt/dhtmlxgantt";import "/public/static/dhtmlxgantt/locale/locale_cn.js";
</script>

 借鉴

  1. css文件地址 examples/dhtmlx_gantt/dhtmlxgantt.css · 残星落影/博客 - 码云 - 开源中国 (gitee.com)
  2. js文件地址 examples/dhtmlx_gantt/dhtmlx · 残星落影/博客 - 码云 - 开源中国 (gitee.com)

定义渲染数据 

let tasks = ref({data: [{id: 1,text: "计划#1",start_date: "2023-09-28",end_date: "2023-10-28",sj_start_date: "2023-09-29",sj_end_date: "2023-10-25",open: true,},{id: 2,text: "已完成",start_date: "2023-09-28",end_date: "2023-10-28",sj_start_date: "2023-09-29",sj_end_date: "2023-10-25",parent: 1,},{id: 3,text: "计划#2",start_date: "2023-03-10",end_date: "2023-5-20",sj_start_date: "2023-03-10",sj_end_date: "2023-5-18",open: true,},{id: 4,text: "已完成",start_date: "2023-03-10",end_date: "2023-5-20",sj_start_date: "2023-03-10",sj_end_date: "2023-5-18",parent: 3,},],
});

 完整代码

<script>
onMounted(() => {gantt.config.autosize = true;// 只读模式gantt.config.readonly = true;//是否显示左侧树表格gantt.config.show_grid = true;//表格列设置gantt.config.columns = [{name: "id",label: "编号",align: "center",tree: false,width: "50",},{name: "text",label: "计划名称",tree: true,width: "240",},{name: "start_date",label: "计划开始",align: "center",tree: false,width: "100",},{name: "end_date",label: "计划完成",align: "center",tree: false,width: "100",},{name: "sj_start_date",label: "实际开始",align: "center",tree: false,width: "100",},{name: "sj_end_date",label: "实际完成",align: "center",tree: false,width: "100",},];gantt.config.subscales = [{unit: "day",step: 1,format: "%d日",},];gantt.attachEvent("onGanttReady", function () {gantt.templates.tooltip_text = function (start: any, end: any, task: any) {return (task.toolTipsTxt +"<br/>" +"阶段:" +task.text +"<br/>" +gantt.templates.tooltip_date_format(start));};});//任务条显示内容gantt.templates.task_text = function (start: any, end: any, task: any) {return ("<div style='text-align:center;color:#fff'>" +task.text +"(" +task.duration +"天)" +"</div>");};//任务条上的文字大小 以及取消border自带样式gantt.templates.task_class = function (start: any, end: any, item: any) {return item.$level == 0 ? "firstLevelTask" : "secondLevelTask";};gantt.templates.timeline_cell_class = function (item: any, date: any) {if (date.getDay() == 0 || date.getDay() == 6) {return "weekend";}};gantt.config.layout = {//拖拽布局css: "gantt_container",rows: [{cols: [{view: "grid",id: "grid",scrollX: "scrollHor",scrollY: "scrollVer",},{ resizer: true, width: 1 },{view: "timeline",id: "timeline",scrollX: "scrollHor",scrollY: "scrollVer",},{ view: "scrollbar", scroll: "y", id: "scrollVer" },],},{ view: "scrollbar", scroll: "x", id: "scrollHor", height: 20 },],};//时间轴图表中,任务条形图的高度//   gantt.config.task_height = 28;gantt.config.task_height = 16;gantt.config.row_height = 40;//时间轴图表中,甘特图的高度//   gantt.config.row_height = 36;//时间轴图表中,如果不设置,只有行边框,区分上下的任务,设置之后带有列的边框,整个时间轴变成格子状。gantt.config.show_task_cells = true;//当task的长度改变时,自动调整图表坐标轴区间用于适配task的长度gantt.config.fit_tasks = true;gantt.config.min_column_width = 40;gantt.config.auto_types = true;gantt.config.xml_date = "%Y-%m-%d";gantt.config.scale_unit = "month";gantt.config.step = 1;gantt.config.date_scale = "%Y年%M";gantt.config.start_on_monday = true;gantt.config.scale_height = 90;gantt.config.autoscroll = true;gantt.config.readonly = true;// gantt.i18n.setLocale("cn");gantt.attachEvent("onTaskLoading", function (task: any) {task.sj_start_date = gantt.date.parseDate(task.sj_start_date, "xml_date");task.sj_end_date = gantt.date.parseDate(task.sj_end_date, "xml_date");return true;});// 初始化gantt.init(proxy.$refs.gantt);// 数据解析gantt.parse(tasks.value);addTaskLayer();
});// 渲染方法
function addTaskLayer() {gantt.addTaskLayer({renderer: {render: function draw_planned(task: any) {// console.log(task);if (task.sj_start_date && task.sj_end_date) {var sizes = gantt.getTaskPosition(task,task.sj_start_date,task.sj_end_date);// console.log(sizes);var el = document.createElement("div");el.className = "baseline";el.style.left = sizes.left + "px";el.style.width = sizes.width + "px";el.style.top = sizes.top + gantt.config.task_height + 17 + "px";// console.log(el);return el;}return false;},getRectangle: function (task: any, view: any) {if (task.start_date && task.end_date) {return gantt.getTaskPosition(task, task.start_date, task.end_date);}return null;},},});
}// 切换日月周季
function setScaleConfig(value: any) {dayIndex.value = value;if (value == "1") {gantt.templates.timeline_cell_class = function (item: any, date: any) {if (date.getDay() == 0 || date.getDay() == 6) {return "weekend";}};} else {gantt.templates.timeline_cell_class = function (item: any, date: any) {if (date.getDay() == 0 || date.getDay() == 6) {return "";}};}switch (value) {case "1": //日gantt.config.xml_date = "%Y-%m-%d";gantt.config.scale_unit = "month";gantt.config.step = 1;gantt.config.date_scale = "%Y年%M";gantt.config.subscales = [{unit: "day",step: 1,date: "%d日",},];gantt.render();break;case "2": //周gantt.config.scale_unit = "week";gantt.config.step = 1;gantt.config.date_scale = "%Y年%M";gantt.templates.date_scale = null;gantt.config.subscales = [{unit: "week",step: 1,date: "第%W周",},{unit: "day",step: 1,date: "%d日",},];gantt.render();break;case "3": //月gantt.config.scale_unit = "month";gantt.config.step = 1;gantt.config.date_scale = "%Y年";gantt.templates.date_scale = null;gantt.config.subscales = [{unit: "month",step: 1,date: "%M",},];gantt.render();break;case "4": //季gantt.config.scale_unit = "year";gantt.config.step = 1;gantt.config.date_scale = "%Y年";gantt.config.subscales = [{unit: "month",step: 1,date: "%M",},{unit: "quarter",step: 1,format: function (date: any) {var dateToStr = gantt.date.date_to_str("%M");var endDate = gantt.date.add(gantt.date.add(date, 3, "month"),-1,"day");return dateToStr(date) + " - " + dateToStr(endDate);},},];gantt.render();break;}
}
</script>css样式<style lang="scss" scoped>
@import "/public/static/dhtmlxgantt/dhtmlxgantt.css";:deep(.gantt_task_line, .gantt_line_wrapper) {margin-top: -9px;
}:deep(.gantt_task_line) {background-color: #3b97fe;border: #3b97fe;height: 15px !important;border-radius: 100px;border-radius: 100px;
}:deep(.gantt_task_line) {margin-bottom: 10px !important;
}:deep(.gantt_task_progress) {background: #ffd180;border-top-right-radius: 100px;border-radius: 100px;
}
:deep(.baseline) {position: absolute;border-radius: 100px;margin-top: -12px;height: 15px;background: #67dd23;
}
:deep(.gantt_grid_scale .gantt_grid_head_cell) {color: black !important;
}
:deep(.gantt_task .gantt_task_scale .gantt_scale_cell) {color: black !important;
}
:deep(.gantt_layout_cell) {::-webkit-scrollbar {height: 8px;}::-webkit-scrollbar-track {border-radius: 8px;background-color: #f5f5f5;}::-webkit-scrollbar-thumb {border-radius: 8px;background-color: #b9b9b9;}
}// 周末 区分
:deep(.weekend) {background: #f4f7f4;
}
:deep(.gantt_selected .weekend) {background: #f7eb91;
}

这篇关于vue使用甘特图dhtmlxgantt + gantt.addTaskLayer的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


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

相关文章

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

SpringBoot中使用Flux实现流式返回的方法小结

《SpringBoot中使用Flux实现流式返回的方法小结》文章介绍流式返回(StreamingResponse)在SpringBoot中通过Flux实现,优势包括提升用户体验、降低内存消耗、支持长连... 目录背景流式返回的核心概念与优势1. 提升用户体验2. 降低内存消耗3. 支持长连接与实时通信在Sp

python使用库爬取m3u8文件的示例

《python使用库爬取m3u8文件的示例》本文主要介绍了python使用库爬取m3u8文件的示例,可以使用requests、m3u8、ffmpeg等库,实现获取、解析、下载视频片段并合并等步骤,具有... 目录一、准备工作二、获取m3u8文件内容三、解析m3u8文件四、下载视频片段五、合并视频片段六、错误

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F

CSS实现元素撑满剩余空间的五种方法

《CSS实现元素撑满剩余空间的五种方法》在日常开发中,我们经常需要让某个元素占据容器的剩余空间,本文将介绍5种不同的方法来实现这个需求,并分析各种方法的优缺点,感兴趣的朋友一起看看吧... css实现元素撑满剩余空间的5种方法 在日常开发中,我们经常需要让某个元素占据容器的剩余空间。这是一个常见的布局需求

CSS Anchor Positioning重新定义锚点定位的时代来临(最新推荐)

《CSSAnchorPositioning重新定义锚点定位的时代来临(最新推荐)》CSSAnchorPositioning是一项仍在草案中的新特性,由Chrome125开始提供原生支持需... 目录 css Anchor Positioning:重新定义「锚定定位」的时代来了! 什么是 Anchor Pos

CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比

《CSS中的Static、Relative、Absolute、Fixed、Sticky的应用与详细对比》CSS中的position属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布... css 中的 position 属性用于控制元素的定位方式,不同的定位方式会影响元素在页面中的布局和层叠关

HTML5 getUserMedia API网页录音实现指南示例小结

《HTML5getUserMediaAPI网页录音实现指南示例小结》本教程将指导你如何利用这一API,结合WebAudioAPI,实现网页录音功能,从获取音频流到处理和保存录音,整个过程将逐步... 目录1. html5 getUserMedia API简介1.1 API概念与历史1.2 功能与优势1.3

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项