vue 实现项目进度甘特图

 项目需求:

实现以1天、7天、30天为周期(周期根据筛选条件选择),展示每个项目不同里程碑任务进度。

项目在Vue-Gantt-chart: 使用Vue做数据控制的Gantt图表基础上进行了改造。

有需要的小伙伴也可以直接引入插件,自己修改。

 我是直接把甘特图封装成了组件,结构如下图:

 

 首先,安装插件

npm install v-gantt-chart

引入插件(我是全局引入的)

import vGanttChart from 'v-gantt-chart';Vue.use(vGanttChart);

 代码如下:

index.js

<template><div class="container"><v-gantt-chart:startTime="times[0]":endTime="times[1]":cellWidth="cellWidth":cellHeight="cellHeight":timeLines="timeLines":titleHeight="titleHeight":scale="Number(1440 * scale)":titleWidth="titleWidth"showCurrentTime:hideHeader="hideHeader":dataKey="dataKey":arrayKeys="arrayKeys":scrollToTime="scrollToTime":scrollToPostion="positionA"@scrollLeft="scrollLeftA"customGenerateBlocks:datas="ganttData"><templatev-slot:block="{data,getPositonOffset,getWidthAbout2Times,isInRenderingTimeRange,startTimeOfRenderArea,endTimeOfRenderArea,isAcrossRenderingTimeRange}"><divclass="gantt-block-item"v-for="(item, index) in data.gtArray"v-if="isInRenderingTimeRange(item.start) ||isInRenderingTimeRange(item.end) ||isAcrossRenderingTimeRange(item.start, item.end)":key="item.id":style="{left: getPositonOffset(item.start) + 'px',width: getWidthAbout2Times(item.start, item.end) + 'px',height: judgeTime(data.gtArray) ? '50%' : '100%',top: !judgeTime(data.gtArray)? '': index % 2 !== 1? '0px': '22px'}"><Test:data="data":updateTimeLines="updateTimeLines":cellHeight="cellHeight":currentTime="currentTime":item="item"@nodeEvent="nodeEvent"></Test></div></template><template v-slot:left="{ data }"><TestLeft :data="data" @panelDb="panelDb"></TestLeft></template><!-- <template v-slot:timeline="{ day , getTimeScales }"><TestTimeline :day="day" :getTimeScales="getTimeScales"></TestTimeline></template> --><template v-slot:title><div class="title">名称</div></template></v-gantt-chart></div>
</template><script>
import moment from 'moment';
import Test from './components/test.vue';
import TestLeft from './components/test-left.vue';
import TestTimeline from './components/test-timeline.vue';
import TestMarkline from './components/test-markline.vue';import dayjs from 'dayjs';export default {name: '',components: { Test, TestLeft, TestTimeline, TestMarkline },props: {ganttData: {type: Array,default: () => []},scaleData: {type: Number,default: 10080},scrollToTime: {type: String,default: moment().subtract(4, 'days').format('YYYY-MM-DD')}},data() {return {timeLines: [],currentTime: dayjs(),cellWidth: 100,cellHeight: 50,titleHeight: 50,titleWidth: 250,// scale: 1440 * 30,startDate: moment().startOf('year'),endDate: moment().endOf('year'),times: [moment().subtract(1, 'year').format('YYYY-MM-DD hh:mm:ss'),moment().add(6, 'months').format('YYYY-MM-DD hh:mm:ss')],rowNum: 100,colNum: 10,datasB: [],dataKey: 'projectId',// scrollToTime: moment().subtract(14, 'days').format('YYYY-MM-DD'),// scrollToTime: moment().subtract(4, 'days').format('YYYY-MM-DD'),scrollToPostion: { x: 10000, y: 10000 },hideHeader: false,hideSecondGantt: false,arrayKeys: ['gtArray'],scrollToY: 0,positionB: {},positionA: {}};},watch: {scrollToY(val) {this.positionA = { x: val };},ganttData(newVal, oldVal) {console.log('newVal===', newVal);console.log('oldVal===', oldVal);}},computed: {scale() {console.log(this.scaleData);return this.scaleData / 1440;}},methods: {judgeTime(arr) {let startTimeArr = [];let endTimeArr = [];arr.map(function (item) {startTimeArr.push(item.startDate ? new Date(item.startDate).getTime() : '');endTimeArr.push(item.delayDate? new Date(item.delayDate).getTime(): item.endDate? new Date(item.endDate).getTime(): '');});let allStartTime = startTimeArr.sort(); // 排序let allEndTime = endTimeArr.sort();let result = 0; // 判断时间是否有重复区间for (let k = 0; k < allStartTime.length; k++) {if (k > 0) {if (allStartTime[k] <= allEndTime[k - 1]) {result += 1;}}}return result > 0;},nodeEvent(item) {this.$emit('nodeEventClick', item);},panelDb(item) {this.$emit('panelDbClick', item);},updateTimeLines(timeA, timeB) {this.timeLines = [{time: timeA,text: '自定义'},{time: timeB,text: '测试',color: '#747e80'}];},scrollLeftA(val) {this.positionB = { x: val };}}
};
</script><style lang="scss" scoped>
.container {height: 82vh;background-color: #f5faff;
}
.title {width: 100%;height: 100%;color: #96aaca;background: #f5faff;
}
:deep(.gantt-leftbar-wrapper) {border-right: 1px solid #c6d8ee !important;
}
</style>

test-left.vue

<template><div class="name"><div class="carId" @dblclick="onDblclick" >{{ data.projectName }}</div></div>
</template><script>
export default {name: "TestLeft",props: {data: Object,},methods: {onDblclick() {// this.updateTimeLines(this.item.start, this.item.end);this.$emit('panelDb', this.data);}}
};
</script><style scoped>
.name {color: #000000;display: flex;box-sizing: border-box;overflow: hidden;height: 100%;width: 100%;padding: 10px 0;align-items: center;text-align: center;background: #f5faff;box-shadow: 2px 0px 4px 0px rgba(0, 0, 0, 0.1);
}.carId {flex: 1;
}.type {padding: 0 5px 0 0;font-size: 1.2rem;
}
</style>

test-markline.vue

<template><divclass="markline":style="{  left: getPosition() + 'px' }"><div class="markline-label">{{timeConfig.text}}{{ dayjs(timeConfig.time).format("HH:mm:ss") }}</div></div>
</template><script>
import dayjs from "dayjs"
export default {name: "TestMarkLine",props:['getPosition','timeConfig'],data(){return {dayjs}}
}
</script><style lang="scss" scoped>.markline {position: absolute;z-index: 100;width: 2px;height: 100vh;background: #747e80;&-label {padding: 3px;width: 6rem;margin-left: -3rem;margin-top: 5rem;color: #fff;background: #747e80;text-align: center;border-radius: 5px;font-size: 0.7rem;}
}
</style>

test-timeline.vue

<template><div class="test"><span v-for="i in getTimeScales(day)"> {{i.format('HH:mm')}}</span></div> 
</template><script>
export default {name: "TestLeft",props: {day: Object,getTimeScales:Function,}
};
</script><style lang="scss" scoped>
.test{display: flex;span{flex:1}
}
</style>

test.vue

<template><el-popover placement="bottom" trigger="hover"><divslot="reference"class="plan":style="{'background-color': statusColor,'margin-top': 0.1 * cellHeight + 'px'}"@click="onClick"><div class="middle">{{ item.summary }}</div></div><div class="detail">{{ item.summary }}</div></el-popover>
</template><script>
import dayjs from 'dayjs';
export default {name: 'Test',props: {data: Object,item: Object,currentTime: dayjs,updateTimeLines: Function,cellHeight: Number,startTimeOfRenderArea: Number},data() {return {dayjs: dayjs,stateObj: {DelayStart: '#F56C6C',Normal: '#C2F1E2',NoStart: '#D9E3ED',Delay: '#F56C6C',Stop: '#D9E3ED',DelayRisk: '#FFD4C7',NoControl: '#F56C6C',Close: '#D9E3ED'}};},computed: {statusColor() {console.log('data=======', this.data);let { item } = this;return this.stateObj[item.state] || '#D9E3ED';},startToString() {return dayjs(this.item.start).format('HH:mm');},endToString() {return dayjs(this.item.end).format('HH:mm');}},methods: {onClick() {// this.updateTimeLines(this.item.start, this.item.end);this.$emit('nodeEvent', this.item);}}
};
</script><style lang="scss" scoped>
.middle {flex: 1;text-align: center;padding-left: 5px;text-overflow: ellipsis;  /* ellipsis:显示省略符号来代表被修剪的文本  string:使用给定的字符串来代表被修剪的文本*/ white-space: nowrap;   /* nowrap:规定段落中的文本不进行换行   */ overflow: hidden; /*超出部分隐藏*/
}
.runTime {display: flex;flex-direction: column;
}
.plan {display: flex;align-items: center;box-sizing: border-box;height: 80%;border: 1px solid #f0f0f0;border-radius: 5px;color: #333333;padding-left: 5px;font-size: 0.8rem;// opacity: 0.8;
}.detail {.header {text-align: center;font-size: 1rem;}
}.detail ul {list-style: none;padding: 0px;li {span {display: inline-block;width: 80px;color: #777;font-size: 0.8rem;}span:first-child {text-align: right;}span:last-child {}}
}
</style>

页面中使用

<div><ganttChart:ganttData="ganttArr":scaleData="scaleData":scrollToTime="scrollToTime"@nodeEventClick="nodeEventClick"@panelDbClick="panelDbClick"></ganttChart>
</div>
import moment from 'moment';
import ganttChart from './components/ganttChart/index.vue';export default {components: { ganttChart },data(){return{ganttArr: [],scaleData: 10080,scrollToTime: moment().subtract(4, 'days').format('YYYY-MM-DD'),}},methods: {// 点击甘特图node节点nodeEventClick(item) {// 执行自己的逻辑},// 双击甘特图左侧标题panelDbClick(item) {//执行自己的逻辑}}}

以上就是实现甘特图的全部过程,欢迎大佬们指教。

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

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

相关文章

Ubuntu Mysql修改密码时遇到的问题

参考&#xff1a; ubuntu18.04 首次登录mysql未设置密码或忘记密码解决方法_ubuntu中mysql设置密码-CSDN博客 1. use mysql; #连接到mysql数据库 2. update mysql.user set authentication_stringpassword(123456) where userroot and Host localhost; #修改密码123456是密码…

C++-4

在Complex类的基础上&#xff0c;完成^&#xff0c;>&#xff0c;~运算符的重载 #include <iostream>using namespace std; class Complex {int rel; //实部int vir; //虚部 public:Complex(){}Complex(int rel,int vir):rel(rel),vir(vir){}/* Complex operato…

03 spring-boot+mybatis+jsp 的增删改查的入门级项目

前言 主要是来自于 朋友的需求 项目概况 就是一个 用户信息的增删改查然后 具体到业务这边 使用 mybatis xml 来配置的增删改查 后端这边 springboot mybatis mysql fastjson 的一个基础的增删改查的学习项目, 简单容易上手 前端这边 jsp 的 基础的试题的增删改查 学习项…

全志ARM-官方库SDK安装和验证

进入界面&#xff0c;输入以下指令 git clone https://github.com/orangepi-xunlong/wiringOP //下载源码 cd wiringOP //进入文件夹 sudo ./build clean //清除编译信息 sudo ./build …

photoshop如何使用PS中的吸管工具吸取软件外部的颜色?

第一步&#xff0c;打开PS&#xff0c;随意新建一个画布&#xff0c;或打开一个图片。 第二步&#xff0c;将PS窗口缩小&#xff0c;和外部窗口叠加放置&#xff0c;以露出后面的其它页面。 第三步&#xff0c;选中吸管工具&#xff0c;在PS窗口内单击一点吸取颜色&#xff0c;…

当您的计算机在屏幕显示器熄灭时,需要输入密码才能打开

打开“任务计划程序”&#xff08;可以在Windows搜索栏中输入“任务计划程序”来查找&#xff09;。在左侧面板中&#xff0c;单击“任务计划程序库”下的“创建任务”。在弹出的对话框中&#xff0c;输入任务名称和描述&#xff0c;然后选择“配置为 Windows 10”并勾选“使用…

maven修改默认编码格式为UTF-8

执行mvn -version查看maven版本信息发现&#xff0c;maven使用的编码格式为GBK。 为什么想到要修改编码格式呢&#xff1f;因为idea中我将文件格式统一设置为UTF-8&#xff08;如果不知道如何修改文件编码&#xff0c;可以参考文末&#xff09;&#xff0c;然后使用maven打包时…

Unity类银河恶魔城学习记录15-1,2 p153 Audio Manager p154 Audio distance limiter

Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释&#xff0c;可供学习Alex教程的人参考 此代码仅为较上一P有所改变的代码 【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili AudioManager.cs using System.Collections; using System.Collections.Gen…

python基础之元组、集合和函数的定义与返回值

1.元祖 1.元祖的定义 元组的数据结构跟列表相似 特征&#xff1a;有序、 有序&#xff1a;有&#xff08;索引/下标/index&#xff09; 正序、反序标识符&#xff1a; ( ) 里面的元素是用英文格式的逗号分割开来关键字&#xff1a;tuple 列表和元组有什么区别&#xff1f; 元组…

代码随想录训练营Day 33|Python|Leetcode|● 理论基础 ● 509. 斐波那契数 ● 70. 爬楼梯 ● 746. 使用最小花费爬楼梯

理论基础 动态规划五步曲 确定dp数组&#xff08;dp table&#xff09;以及下标的含义确定递推公式dp数组如何初始化确定遍历顺序举例推导dp数组 509. 斐波那契数 斐波那契数 &#xff08;通常用 F(n) 表示&#xff09;形成的序列称为 斐波那契数列 。该数列由 0 和 1 开始…

原型链prototype、__proto、constructor的那些问题整理

再了解原型链之前,我们先来看看构造函数和实例对象的打印结构 - 函数 这里我们定义一个构造函数Fn,然后打印它的结构吧 function Fn(){} console.dir(Fn)控制台得到结构 从上面结构我们能看的出来,函数有两种原型,一种是作为函数特有的原型:prototype,另一种是作为对象的__…

Kafka 生产者应用解析

目录 1、生产者消息发送流程 1.1、发送原理 2、异步发送 API 2.1、普通异步发送 2.2、带回调函数的异步发送 3、同步发送 API 4、生产者分区 4.1、分区的优势 4.2、生产者发送消息的分区策略 示例1&#xff1a;将数据发往指定 partition 示例2&#xff1a;有 key 的…