Vue3甘特图 - dhtmlx-gantt

news/2025/3/10 22:26:03/文章来源:https://www.cnblogs.com/newBugs/p/18637513

Vue3甘特图

<template><div style="height:100%; background-color: white"><div id="gantt_here" style="width:100%; height:100%;"></div></div>
</template><script setup>
import { onMounted } from 'vue'
import { gantt } from 'dhtmlx-gantt'
import 'dhtmlx-gantt/codebase/dhtmlxgantt.css'
import { formatDate } from '@/utils/index.js'
const zoomConfig = {levels: [{name: 'day',scale_height: 60,min_column_width: 18,scales: [{ unit: 'month', format: '%Y-%m' },{unit: 'day',step: 1,format: '%d',css: function (date) {if (date.getDay() == 0 || date.getDay() == 6) {return 'day-item weekend weekend-border-bottom'} else {return 'day-item'}}}]},{name: 'week',height: 60,min_column_width: 110,scales: [{unit: 'quarter',step: 1,format: function (date) {let yearStr = new Date(date).getFullYear() + '年'let dateToStr = gantt.date.date_to_str('%M')let endDate = gantt.date.add(gantt.date.add(date, 3, 'month'), -1, 'day')return yearStr + dateToStr(date) + ' - ' + dateToStr(endDate)}},{unit: 'week',step: 1,format: function (date) {let dateToStr = gantt.date.date_to_str('%m-%d')let endDate = gantt.date.add(date, 6, 'day')let weekNum = gantt.date.date_to_str('%W')(date)return dateToStr(date) + ' 至 ' + dateToStr(endDate)}}]},{name: 'month',scale_height: 50,min_column_width: 150,scales: [{ unit: 'year', step: 1, format: '%Y年' },{ unit: 'month', format: '%Y-%m' }]}]
}
onMounted(() => {gantt.plugins({quick_info: true,marker: true,tooltip: true,quick_info: true,})gantt.config.readonly = false //是否只读gantt.config.lightbox.sections = [] // 清空弹窗内容gantt.config.drag_move = true //允许拖动任务时移动任务gantt.config.auto_types = true //将包含子任务的任务转换为项目,将没有子任务的项目转换回任务gantt.config.open_split_tasks = true//激活列表展开、折叠功能gantt.config.xml_date = '%Y.%m.%d' //甘特图时间数据格式gantt.config.show_errors = false //不显示错误信息gantt.ext.zoom.init(zoomConfig) //配置初始化扩展gantt.i18n.setLocale("cn")gantt.config.work_time = truegantt.ext.zoom.setLevel('day') //切换到指定的缩放级别xgantt.config.add_column = false //添加符号gantt.config.show_progress = false //显示进度条gantt.config.drag_resize = true //允许拖动任务时调整任务大小gantt.config.drag_links = false //允许拖动任务时调整任务链接gantt.config.order_branch = true //允许拖动任务时保持任务顺序gantt.config.drag_progress = true //允许拖动任务时调整任务进度// 设置表头gantt.config.columns = [{name: "text", //tasks参数名tree: true, //是否开始tree联级width: '170', //宽度 值为string 例如 width:"75"  "*" 为autoresize: true, //可重置大小label: '订单', //标签名template: function (obj) { return obj.text }, //返回值align: "left" //对齐方式},]gantt.config.columns.push({name: "start_date",label: "开始时间",width: '110',align: "left"}, {name: "end_date",label: "结束时间",width: '100',align: "left"}, {name: "number",label: "订单数量",width: '100',align: "left",template: function (obj) { return `${obj.number}个` }, //返回值})gantt.templates.grid_folder = (item) => {return ""}//更改子项图标gantt.templates.grid_file = (item) => {return ""}// 设置当天标记const dateToStr = gantt.date.date_to_str(gantt.config.task_date)const today = new Date(new Date().setHours(0, 0, 0, 0)) // 获取当天零点的时间gantt.addMarker({start_date: today,css: "today",text: "今日",title: `Today: ${dateToStr(today)}`,})// 设置颜色gantt.templates.task_class = function (start, end, task) {if (task.estimate) {return 'gray_color'} else {return 'red_color'}}gantt.config.work_time = truegantt.templates.timeline_cell_class = function (task, date) {if (date.getDay() === 0 || date.getDay() === 6) { // 检查是否为周末return "weekend-border-bottom " // 返回红色样式} else {return "" // 其他日期使用默认样式}// const targetDate = new Date(2024, 11, 17) // 2024-12-17// if (date.getTime() === targetDate.getTime()) {//   return "red_color" // 返回红色样式// }// return "" // 其他日期使用默认样式}gantt.attachEvent("onTaskDblClick", function (id, e) { })gantt.config.fit_tasks = true //自动适配任务大小gantt.templates.quick_info_content = function (start, end, task) {console.log(task, 'task')return `<div><h2>${task.text}</h2><br/>计划开始 : ${formatDate(task.start_date)}<br/>计划结束 : ${formatDate(task.end_date)}<br/>计划数量 : ${task.number}<br/></div>`}gantt.templates.tooltip_text = function (start, end, task) {return (task.text +'<br/><span>开始:</span> ' +gantt.templates.tooltip_date_format(start) +'<br/><span>结束:</span> ' +gantt.templates.tooltip_date_format(end))}gantt.init("gantt_here")gantt.parse({tasks: [{ id: 11, text: "2024-12订单", type: "project", number: 15000, open: true },{ id: 12, text: "成品钢板订单", start_date: "2024-12-03", duration: 30, parent: 11, estimate: true, number: 10000 },{ id: 13, text: "成品铅笔订单", start_date: "2024-12-20", duration: 30, parent: 11, estimate: false, number: 5000 },],links: []})
})
</script><style>
.red_color {background: red;
}.weekend-border-bottom {background: #bdbbbb;color: rgb(255, 255, 255) !important;
}.blue_color {background: blue;
}.gray_color {background: gray;
}.gantt_cal_qi_controls {display: none;
}.gantt_cal_qi_title {display: none;
}
</style>

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

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

相关文章

恍恍惚惚,走到了尾声

课程链接 https://edu.cnblogs.com/campus/fzu/SE2024/作业链接 https://edu.cnblogs.com/campus/fzu/SE2024/homework/13315作业目标 回顾自己的软工实践课程学号 102202157一、学期回顾 1.1 回顾你对于软件工程课程的想象在课程开始前,我一直以为软件工程课程会聚焦于各种编…

转正了!!!!!!!!

近期&感受、问题: 1.版本优化描述:秘境排行榜;一键探险功能的顺序;背包随机类宝箱一键开启;美食家一键合成闪光美食;电玩活动跳过动画功能;许愿池自动投币;结晶一键熔炼 感受/反思:感觉自己菜菜的QAQ,各种版本的本地数据处理错误(删早了删晚了/先notify后notify…

Navicat密码导出解密导入到DataGrip中

使用Navicat导出密码:目前使用Navicat17亲测有效使用php解密代码 <?php class NavicatPassword {protected $version = 0;protected $aesKey = libcckeylibcckey;protected $aesIv = libcciv libcciv ;protected $blowString = 3DC5CA39;protected $blowKey = null;protec…

鸿蒙原生页面高性能解决方案上线OpenHarmony社区 助力打造高性能原生应用

随着HarmonyOS NEXT的正式推出,鸿蒙原生应用开发热度高涨,数量激增。但在三方应用鸿蒙化进程中,性能问题频出。为此,HarmonyOS NEXT推出了一整套原生页面高性能解决方案,包括Nodepool、HMrouter和DataCache 三大解决方案,并上架OpenHarmony开源社区,分别针对应用页面滑动…

数值计算方法(2) 数值积分方法

+++ date = 2024-12-21T13:49:00+08:00 draft = true title = 数值计算方法(2) 数值积分方法 +++ 初次发布于我的个人文档 上一期讲了插值方法,这一次自然是要运用一下插值方法了。所以这一期的主题是用插值方法计算定积分。 机械求积方法 下面我们来介绍一下怎么用插值法来得…

AI烟雾监测识别摄像机

AI烟雾监测识别摄像机的应用范围广泛,不仅可以安装在家庭、商业建筑、工厂等场所,还可以应用于地铁、火车站等公共场所,为人们的生命财产安全提供全方位的保障。总的来说,AI烟雾监测识别摄像机作为智能化安全防范的重要工具,具有广阔的应用前景和社会意义。通过提高火灾预…

Omnissa Horizon Clients 2412 发布 - 虚拟桌面基础架构 (VDI) 和应用软件

Omnissa Horizon Clients 2412 发布 - 虚拟桌面基础架构 (VDI) 和应用软件Omnissa Horizon Clients 2412 发布 - 虚拟桌面基础架构 (VDI) 和应用软件 Omnissa Horizon,之前称为 VMware Horizon, 通过高效、安全的虚拟桌面交付增强您的工作空间 请访问原文链接:https://sysin.…

题目集7-8总结:智能家居强电电路模拟系统

一、前言 1.1 题目背景 题目集7和8以智能家居为主题,通过强电电路的模拟设计,引导我们从基本开关电路到多功能调速器和受控设备模拟的深入探索,体现了物联网技术在智能家居中的实际应用。 1.2 题目特点 知识点:涵盖开关逻辑、电路模拟、受控设备特性、并联与串联电路等核…

业务凭证与总账凭证有何异同

在企业财务管理中,"业务凭证"和"总账凭证"是两个核心概念,它们在会计核算和ERP系统中扮演着至关重要的角色。本文将深入探讨这两个概念的异同点,帮助读者更好地理解它们在记录企业经济活动、会计分录以及财务报表编制中的作用和区别。在ERP财务系统里,…

Qt - 实现HTTP服务器和HTTP客户端

1. WebSocket服务器和HTTP服务器的区别 WebSocket服务器和HTTP服务器是两种不同的服务器类型,它们在协议、连接方式和通信模式等方面有所区别。协议:HTTP服务器使用HTTP协议进行通信,而WebSocket服务器使用WebSocket协议。HTTP协议是无状态的,客户端发起请求,服务器响应请…

“代码之舟”——2024秋软工实践纪

这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzu/SE2024这个作业要求在哪里 https://edu.cnblogs.com/campus/fzu/SE2024/homework/13315这个作业的目标 回顾这一学期所完成的软工任务,总结这一学期的收获学号 102202102 王子聪引言: 在上这门课之前还没有真正的体…

Python-DdddOcr的简单使用

前言:我们在做WEB端UI自动化时,会遇到图片验证码校验的登录方式。我在之前的文章也做过介绍:https://www.cnblogs.com/TSmagic/p/16082799.html (Pillow + pytesseract + tesseract-ocr 破解简单的图形验证码)https://www.cnblogs.com/TSmagic/p/16117861.html(Python + 超…