HTML中使用Vue+Dhtmlxgantt制作任务进度图

Dhtmlxgantt官网: https://dhtmlx.com/docs/products/dhtmlxGantt/

参考文章

甘特图配置大佬翻译的官方文档 ,https://blog.csdn.net/qq_24472595/article/details/81630117;
实现搜索 新增 编辑 删除 设置具体时间格式 突出周末显示https://blog.csdn.net/CX_silent/article/details/83589451
从0开始使用Dhtmlxgantt https://blog.csdn.net/honantic/article/details/51314672 ;
代码部分

HTML部分:

       //需要引用dhtmlxgantt.css、dhtmlxgantt.js、locale_cn.js(汉化文件)
<div>
<div id="gantt_here" style='width:100%; height:550px;' ref="gantt"></div>
</div>

js部分:

 $(function () {
window.App = new Vue({
el: "#app",
data: function () {
return {
tasks: {
data: []
}
}
};
},
methods: {
QueryClick: function () {
var that = this;
//每次点击查询前清空
that.InitData();
that.Ajax({
url: "/JHProcess/GetProcessContrast",//从后台读取数据
data: {
XXXX//后台查询条件
},
success: function (result) {
var data = result.Data.Data;
var arry = [];
for (var i = 0; i < data.length; i++) {
var current = data[i];
arry.push({
text: current.名称,
start_date: new Date(current.开始时间),
end_date: new Date(current.结束时间),
duration: that.DateDifference(current.开始时间, current.结束时间),
progress: Number((current.计划进度 / current.本年投资计划完成).toFixed(2))
});
}
that.tasks.data = arry;
that.Init(); //加载数据之后初始化
}
});
},
weekScaleTemplate: function (date) {
var dateToStr = gantt.date.date_to_str("%d%M");
var weekNum = gantt.date.date_to_str("(周%W)");
var endDate = gantt.date.add(gantt.date.add(date, 1, "week"), - 1, "day");
return dateToStr(date) + " - " + dateToStr(endDate) + "" + weekNum(date);
},
DateDifference: function (strDateStart, strDateEnd) {
var begintime_ms = Date.parse(new Date(strDateStart.replace(/-/g, "/"))); //begintime 为开始时间
var endtime_ms = Date.parse(new Date(strDateEnd.replace(/-/g, "/"))); // endtime 为结束时间
var date3 = endtime_ms - begintime_ms; //时间差的毫秒数
var days = Math.floor(date3 / (24 * 3600 * 1000));
return days;
},
Init: function () {
var that = this;
gantt.config.scale_unit = "month"; //时间坐标轴单位“minute”, “hour”, “day”, “week”, “quarter”, “month”, “year”
gantt.config.date_scale = "%d,%D";//日期格式 先数字后文字
gantt.config.row_height = 30; //甘特图的行高
gantt.config.scale_height = 20;//甘特图的表头高度
gantt.config.scroll_on_click = false;
gantt.config.min_column_width = 60;
gantt.config.duration_unit = "day";
gantt.config.scale_height = 20 * 3;
//gantt.config.row_height = 28;
gantt.config.drag_resize = false;//两边不可拖动
gantt.config.readonly = true;//只读模式
gantt.config.subscales = [{ //时间坐标为月份的时候 先显示年份再月份
unit: "month",
step: 1,
date: "%Y,%F"
}];
//配置显示列 //name:绑定数据的名称 align:对其方式 label显示在表头的名称
gantt.config.columns = [
{ name: "text", tree: true, width: '*', align: "center", label: "计划名称", resize: true },
{ name: "start_date", align: "center", resize: true },
{ name: "end_date", align: "center", label: "结束时间", resize: true },
{ name: "duration", align: "center" }
];
//显示到进度条上的文本 计划名称和任务进度百分比
gantt.templates.task_text = function (start, end, task) {
return "<b style='text-align:left;'>计划名称:</b> " + task.text +" <span style='text-align:left;'>" +"完成计划:"+ Math.round(task.progress * 100) + "% </span>";
};
gantt.init(that.$refs.gantt); gantt.parse(that.tasks);
},
InitData: function () {
//清空数据
gantt.clearAll();
}
},
mounted() {
var that = this;
that.Ajax = top.Helper.Current.Ajax;
//注入一个用户信息
that.User = top.Helper.Current.User;
console.log(that.$refs.gantt);
that.SizeChange = function () {
var that = this;
var h = $("#app").height();
if (that.WindowSize != h) {
that.WindowSize = (h - 135);
console.log(that.WindowSize);
}
};
gantt.config.min_column_width = 60;
gantt.config.scale_height = 20 * 3;
gantt.config.subscales = [{
unit: "month",
step: 1,
date: "%Y,%F"
}];
//配置显示列 //name:绑定数据的名称 align:对其方式 label显示在表头的名称
gantt.config.columns = [
{ name: "text", tree: true, width: '*', align: "center", label: "计划名称", resize: true },
{ name: "start_date", align: "center", resize: true },
{ name: "end_date", align: "center", label: "结束时间", resize: true },
{ name: "duration", align: "center" }
];
gantt.init(that.$refs.gantt);
}
});
});

HTML中使用Vue+Dhtmlxgantt制作任务进度图的更多相关文章

  1. 使用Vue.js制作仿Metronic高级表格(一)静态设计

    Metronic高级表格是Metonic框架中自行实现的表格,其底层是Datatables.本教程将主要使用Vue实现交互部分,使用Bootstrap做样式库.jQuery做部分用户交互(弹窗). 使 ...

  2. webstorm中关于vue的一些问题

    在进行vue开发中,我使用了webstorm,但是过程坎坷艰辛,遇到了很多问题,我将问题和解决方案贴上,以作参考. 1.vue项目部署在webstorm中,第一个遇到的问题是,webstorm卡住了, ...

  3. 在pycharm中开发vue

    一.在pycharm中开发vue ''' webstorm(vue) pycharm(python) goland(Go语言) idea(java) andrioStuidio(安卓) Php(PHP ...

  4. vue生命周期图示中英文版Vue实例生命周期钩子

    vue生命周期图示中英文版Vue实例生命周期钩子知乎上近日有人发起了一个 “react 是不是比 vue 牛皮,为什么?” 的问题,Vue.js 作者尤雨溪12月4日正面回应了该问题.以下是尤雨溪回复 ...

  5. 在webpack构建的项目中使用vue

    一.复习在普通网页中使用vue1.使用script引入vue2.在index中创建 id为app的容器3.通过new vue得到vm实例二.在webpack中尝试使用vue://注意 : 在webpa ...

  6. django项目中使用项目环境制作脚本 通过终端命令运行脚本文件

    在实际的django项目开发中,有时候需要制作一些脚本文件对项目数据进行处理,然后通过终端命令运行脚本. 完整的实现流程如下: 1.在一个应用目录下(app, 必须是在应用目录下,可以专门创建一个应用 ...

  7. 在webpack中配置vue.js

    在webpack中配置vue.js 这里有两种在webpack中配置vue.js的方法,如下: 1.在main.js中引入vue的包: index.html: <!DOCTYPE html> ...

  8. IDEA 中使用 Vue 提示 namespace is not bound

    今天在 IDEA 中使用 vue.js 时提示我如下错误信息 解决方法: 把这个校验项目去掉就可以了.

  9. webstorn中的vue文件识别es6代码

    webstorn中的vue文件识别es6代码 1.webstorm中es6语法报错,解决方法: 打开 Settings => Languages & Frameworks => J ...

随机推荐

  1. java 集合遍历输出方式

    Iterator:迭代输出 一旦操作集合的遍历输出,首选Iterator接口; ListIterator:Iterator子接口,专门输出List中的元素; Enumeration:古老的输出方式,迭 ...

  2. python编程之操作系统基础

    操作系统发展史: 最早的计算机没有操作系统的概念:是使用打孔机和打孔卡片来进行计算的.只能一个一个处理. 后来产生了批处理系统,可以批量处理,进而加快计算的速度. 批处理系统:串行 数据处理速度加快 ...

  3. 2018-4-29-C#-将dll打包到程序中

    title author date CreateTime categories C# 将dll打包到程序中 lindexi 2018-04-29 09:43:22 +0800 2018-2-13 17 ...

  4. mysql导入文件出现Data truncated for column 'xxx' at row 1的原因

    mysql导入文件的时候很容易出现"Data truncated for column 'xxx' at row x",其中字符串里的xxx和x是指具体的列和行数. 有时候,这是因 ...

  5. 安装 Sureface Hub 系统 Windows 10 team PPIPro 系统

    本文告诉大家如何安装这个系统 本文的方法我自己没试过,如果失败了,不要打我 下载地址 中文版 https://pan.baidu.com/s/1gAJSSE6KB9JHXo4BT_VfmA 其他请看 ...

  6. 找不到 javax.servlet.http.HttpServletResponse 和 javax.servlet.http.HttpServletRequest 问题解决

    时隔3个月,我又回来了!在做完毕设之后,由于对此过程中学到的一些东西疏于整理,所以当再次打开我的project时有些手足无措,以至于出现一些问题也要解决好半天,我知错! 今天的问题是: 开始搜到的解决 ...

  7. Java中大量if...else语句的消除替代方案

    在我们平时的开发过程中,经常可能会出现大量If else的场景,代码显的很臃肿,非常不优雅.那我们又没有办法处理呢? 针对大量的if嵌套让代码的复杂性增高而且难以维护.本文将介绍多种解决方案. 案例 ...

  8. Android TextView调用Settext()耗时的原因

    当textview的宽设置为wrap_content的时候,底层会调用checkForRelayout函数,这个函数根据文字的多少重新开始布局 因此将宽度设置为固定值或者match_parent的时候 ...

  9. MFC防止进程重复建立

    原文:https://blog.csdn.net/zhang11wu4/article/details/7100839 在APP类的InitInstance()的最前面加入以下代码,建立互斥区,可防止 ...

  10. 2017.5.11 昨天晚上看fview直播坚果pro回放

      对话1 彭林: 我以前也是产品经理,身为产品经理,你有没有感觉我们做出过什么之前不被人接受的东西,但是我们却坚持做了,并且得到的反响非常好. 朱萧木: 没有吧,我们没有做颠覆用户认知或者三观的特别 ...