超短期简单甘特图,vue自定义简单甘特图

18 篇文章 0 订阅
6 篇文章 0 订阅

当日前后30天,共60天内的任务展示,不同任务状态不同颜色

为了同画面多甘特图;美丽废物一个,展示用

在这里插入图片描述
在这里插入图片描述

<div class="gantt">
    <div class="gantt-time">
        <div class="gantt-time-one g-time"><span>{{mLdate2}}</span><div class="time-masker"></div></div>
        <div class="gantt-time-two g-time"><span>{{mLdate1}}</span> <div class="time-masker"></div></div>
        <div class="gantt-time-three g-time"><span>{{local=='en'?'Today':'今日'}}</span> <div class="time-masker"></div></div>
        <div class="gantt-time-four g-time"><span>{{mRdate1}}</span> <div class="time-masker"></div></div>
        <div class="gantt-time-five g-time"><span>{{mRdate2}}</span> <div class="time-masker"></div></div>
    </div>
    <div class="gantt-layout">
        <div class="gantt-cell">
            <div v-for="(item,i) in colList" :key="i" class="gantt-cell-name">{{item}}</div>
        </div>
        <div class="gantt-task">
            <div v-for="(item,i) in taskList" :key="i" >
                <div :class="['gantt-task-item','gantt-task-item'+i]" :style="{backgroundColor:item.color,borderLeft:'2px solid'+ item.colorL,width:item.width+'%',marginLeft:item.left+'%'}"> {{item.text}}</div>
            </div>
        </div>
    </div>
</div>
export default defineComponent({
    props:{
        taskdata:{type: Array, default: []},
        status1:{type:String,default:''},
        status2:{type:String,default:''},
        status3:{type:String,default:''},
        status4:{type:String,default:''},
        status5:{type:String,default:''},
    },
    setup(props) {
        let rolegroup = ref<string[]>([]); //部门confirm权限
        const today = new Date();
        const day = 24 * 60 * 60 *1000;
        const mToday = (today.getMonth()+1) + '/ ' +today.getDate();
        const mL1 = new Date(today.getTime() - day*15); 
        const mL2 = new Date(today.getTime() - day*30); //最小时间
        const mR1 = new Date(today.getTime() + day*15);
        const mR2 = new Date(today.getTime() + day*30); //最大时间
        const mLdate1 = mL1.getMonth()+1 +'/' +mL1.getDate(); //前15天
        const mLdate2 = mL2.getMonth()+1 +'/' +mL2.getDate(); //前30天
        const mRdate1 = mR1.getMonth()+1 +'/' +mR1.getDate(); //后15天
        const mRdate2 = mR2.getMonth()+1 +'/' +mR2.getDate(); //后30天
        let taskList =ref<TaskItem[]>([]);//任务数组
        let testTask = [] as any;
        const colList = ref(['','','','',''])
        type TaskItem = {des:string, text:string, start_date: string, end_date: string, width: string, left:string, color: string,colorL: string,group:boolean,confirm:boolean};
        function checkColor(status){
            if(status=='0'){
                return ['#EFEFEF','#BDBDBD']
            }else if(status=='1'){
                return ['#F3F7FE','#2F80ED']
            }else if(status=='2'){
                return ['#F2F9F3','#20A13E']
            }else if(status==3){
                return ['#FEF2F3','#EB5757']
            }
        }
        function checkTask(task){
            task.forEach((item)=>{
                if(new Date(item.start_date) < mL2){
                    item.start_date = mL2.toLocaleDateString().replace('/','-');
                }
                if(new Date(item.end_date)>mR2){
                    item.end_date = mR2.toLocaleDateString().replace('/','-');
                }
                item.width = 1.67 * (Math.round((<any>new Date(item.end_date)-<any>new Date(item.start_date))/day));
                item.left = 1.66 * (Math.round((<any>new Date(item.start_date)-<any>new Date(mL2.toLocaleDateString().replace('/','-')))/day));               
            })
        }
        function setTask(val){
            taskList.value = [];
                val.forEach((item,i) => {
                        let ta=<TaskItem>{}
                        ta.text= item.taskName;
                        ta.start_date = item.taskFromDate.substr(0,4)+'-'+item.taskFromDate.substr(4,2)+'-' +item.taskFromDate.substr(6,2);
                        ta.end_date = item.taskRequestDate.substr(0,4)+'-'+item.taskRequestDate.substr(4,2)+'-' +item.taskRequestDate.substr(6,2);
                        ta.color = checkColor(item.taskStatus)[0];
                        ta.colorL = checkColor(item.taskStatus)[1];
                        ta.group = rolegroup.value.indexOf(item.groupId)!=-1?true:false;
                        taskList.value.push(ta);
                });
                checkTask(taskList.value)
        }
        watch(
            ()=> props.taskdata,
            (val)=>{
                testTask = val
                setTask(val)
            }
        )
        return {
            taskList,mToday,mLdate1,mLdate2,mRdate1,mRdate2,t,rolegroup,colList,local
        }
    },
})
.gantt{
    width: 84%;
    min-width: 74%;
    height: 218px;
    padding: 12px;
    font-size: 12px;
    position: relative;
    background-color: #fff;
    z-index: 1;
    border-radius: 12px;
}
.gantt-time{
    display: flex;
    width: 90%;
    margin-left: 10%;
    justify-content: space-between;
    margin-bottom: 13px;
    color: #828282;
    .g-time span{
        display: inline-block;
        width: 31px;
        text-align: center;
    }
    .gantt-time-three{
        color: #20A13E;
        font-weight: 600;
        .time-masker{
            background-color: #20A13E;
        }
    }
    .time-masker{
        z-index: 1;
        position: absolute;
        width: 0.4px;
        height: 77%;
        background-color: #E6EAF0;
        margin-left: 11px;
        margin-top: 4px;
    }
}
.gantt-layout{
    display: flex;
}
.gantt-cell{
    width: 10%;
    color: #828282;
}
.gantt-task{
    width: 100%;
    z-index: 2;
    padding: 0 12px;
}
.gantt-task-item,.gantt-cell-name{
    height: 22px;
    line-height: 22px;
    margin-bottom: 8px;
}
.gantt-cell-name{
    height: 22px;
    line-height: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gantt-task-item{
    border-radius:2px;
    color: #333333;
    padding-left:4px ;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
dhtmlx甘特图是一种基于JavaScript甘特图库,可以帮助开发者在Vue项目中实现甘特图功能。它有专门为Vue3写的版本,但并不适用于Vue2项目。所以,如果你的项目使用的是Vue2,可以选择使用dhtmlx的普通版本。 在使用dhtmlx甘特图时,你需要安装dhtmlx并引入相关的代码库。你可以使用`npm install dhtmlx-gantt -save`命令安装dhtmlx-gantt,并在Vue组件中引入`gantt`对象。然后,你可以在模板中添加一个容器元素,在其中渲染甘特图。 dhtmlx甘特图提供了丰富的功能和配置选项,包括更新数据、显示任务完成百分比、设置鼠标悬浮时展示的内容、拖动和拖拽修改任务时间、添加和删除依赖关系、双击事件、甘特图缩放、动态加载等。你可以根据你的需求进行相应的配置和使用。 如果你想实现任务的层级关系(即任务有子任务),你可以让后端传递一个额外的值来表示该任务是否有子任务,并相应地进行配置。另外,你可以使用`gantt.load`方法来加载数据。 总的来说,使用dhtmlx甘特图可以帮助你在Vue项目中实现强大的甘特图功能,并提供了丰富的配置选项和扩展性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [dhtmlx甘特图--vue2](https://blog.csdn.net/weixin_44364294/article/details/126470299)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值