vue 甘特图 vxe-gantt 自定义任务条插槽模板的用法

vue 甘特图 vxe-gantt 自定义任务条插槽模板的用法

https://gantt.vxeui.com

过设置 taskBar 插槽来自定义模板

html 复制代码
<template>
  <div>
    <vxe-gantt v-bind="ganttOptions">
      <template #task-bar-overview="{ row }">
        <div class="custom-task-bar" :style="{ backgroundColor: row.bgColor }">
          <div class="custom-task-txt">总进度:{{ row.progress }}%</div>
        </div>
      </template>

      <template #task-bar="{ row }">
        <div class="custom-task-bar" :style="{ backgroundColor: row.bgColor }">
          <div>
            <vxe-image :src="row.imgUrl" height="30" circle></vxe-image>
          </div>
          <div>
            <div class="custom-task-txt">{{ row.title }}</div>
            <div class="custom-task-txt">已完成:{{ row.progress }}%</div>
          </div>
        </div>
      </template>
    </vxe-gantt>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
import { VxeGanttTaskType } from 'vxe-gantt'

const ganttOptions = reactive({
  border: true,
  height: 500,
  treeConfig: {
    transform: true,
    rowField: 'id',
    parentField: 'parentId'
  },
  taskBarSubviewConfig: {
    showOverview: true
  },
  taskBarConfig: {
    showContent: true,
    barStyle: {
      round: true
    }
  },
  taskViewConfig: {
    tableStyle: {
      width: 380
    }
  },
  columns: [
    { field: 'title', title: '任务名称', minWidth: 140, treeNode: true },
    { field: 'start', title: '开始时间', width: 100 },
    { field: 'end', title: '结束时间', width: 100 }
  ],
  data: [
    { id: 10001, parentId: null, title: 'A项目', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar3.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10002, parentId: 10001, title: '城市道路修理进度', start: '2024-03-03', end: '2024-03-08', progress: 70, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar5.jpeg' },
    { id: 10003, parentId: null, title: 'B大工程', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar2.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10004, parentId: 10003, title: '超级大工程', start: '2024-03-05', end: '2024-03-08', progress: 50, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar1.jpeg' },
    { id: 10005, parentId: 10003, title: '地球净化项目', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar8.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10006, parentId: 10003, title: '一个小目标项目', start: '2024-03-13', end: '2024-03-21', progress: 60, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar9.jpeg' },
    { id: 10007, parentId: 10005, title: '某某计划', start: '2024-03-22', end: '2024-03-24', progress: 70, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar3.jpeg' },
    { id: 10008, parentId: null, title: '某某科技项目', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar6.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10009, parentId: 10008, title: '地铁建设工程', start: '2024-03-19', end: '2024-03-20', progress: 50, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar7.jpeg' },
    { id: 10010, parentId: 10008, title: '公寓装修计划2', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar5.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10011, parentId: 10008, title: '两个小目标工程', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar4.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10012, parentId: null, title: '蓝天计划', start: '2024-03-29', end: '2024-04-01', progress: 60, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar7.jpeg' },
    { id: 10013, parentId: 10010, title: 'C大项目', start: '2024-03-08', end: '2024-03-11', progress: 70, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar2.jpeg' },
    { id: 10014, parentId: 10010, title: 'H计划', start: '2024-03-12', end: '2024-03-16', progress: 100, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar1.jpeg' },
    { id: 10015, parentId: 10011, title: '铁路修建计划', start: '2024-03-18', end: '2024-03-19', progress: 80, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar2.jpeg' },
    { id: 10016, parentId: 10011, title: 'D项目', start: '2024-03-20', end: '2024-03-22', progress: 10, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar6.jpeg' },
    { id: 10017, parentId: 10011, title: '海外改造工程', start: '2024-03-24', end: '2024-03-29', progress: 60, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar7.jpeg' },
    { id: 10018, parentId: null, title: 'Z计划', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar8.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10019, parentId: 10018, title: 'F工程', start: '2024-03-20', end: '2024-03-22', progress: 80, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar8.jpeg' },
    { id: 10020, parentId: 10018, title: '投资大项目', start: '2024-03-23', end: '2024-03-25', progress: 60, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar7.jpeg' },
    { id: 10021, parentId: 10018, title: 'X计划', start: '2024-03-26', end: '2024-03-29', progress: 60, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar9.jpeg' },
    { id: 10022, parentId: null, title: '上天计划', start: '2024-03-19', end: '2024-03-26', progress: 70, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar4.jpeg' },
    { id: 10023, parentId: null, title: 'G项目', start: '', end: '', progress: 0, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar3.jpeg', type: VxeGanttTaskType.Subview },
    { id: 10024, parentId: 10023, title: '下地计划', start: '2024-03-09', end: '2024-03-16', progress: 50, imgUrl: 'https://vxeui.com/resource/avatarImg/avatar5.jpeg' }
  ]
})
</script>

<style lang="scss" scoped>
.custom-task-bar {
  display: flex;
  flex-direction: row;
  padding: 2px 6px;
  width: 100%;
  font-size: 12px;
}
.custom-task-txt {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>

https://gitee.com/x-extends/vxe-gantt

相关推荐
鶴哥只手遮天5 小时前
Vue 3 核心源码深度剖析系列(v3.5.44)-第 1 章 项目全景:monorepo 架构与工程化体系
前端·vue.js·开源
OpenTiny社区7 小时前
多会话 + 流式输出怎么落地?TinyRobot Kit 对话数据层深度解析
前端·vue.js
破烂三角裤10 小时前
Vue 3 自动生成汉字拼音:pinyin-pro、Ruby 标签
vue.js
顽疲10 小时前
java vue springboot 养老系统源码详解:退住 care_out 审批结算与腾床事务实践
java·vue.js·spring boot·vue养老·springboot养老·java养老
雪芽蓝域zzs10 小时前
第 10 节:地图点击逆地理编码(点击地图获取经纬度 + 地址)
vue.js
斯内普吖10 小时前
(开源)线上花店系统实战指南 基于 Java + SSM + Vue + MySQL
java·vue.js·mysql·开源
溪语流沙11 小时前
【Web全栈进阶】Vue Router + Pinia:SPA路由与全局状态
前端·javascript·vue.js
u01110267513 小时前
WebP 转成 PNG 后为什么更大?图片格式转换不等于压缩
前端·javascript·vue.js
seconp13 小时前
基于Spring Boot和Vue 3的智慧旅游网站:住宿预订、行程规划与千问接入
vue.js·spring boot·毕业设计·软件工程·课程设计·旅游·毕设
daols8814 小时前
vue 甘特图组件 vxe-gantt 修改滚动条样式-让滚动条自动隐藏
javascript·vue.js·甘特图