vue vxe-gantt table 甘特图实现多个维度视图展示,支持切换年视图、月视图、周视图等

vue vxe-gantt table 甘特图实现多个维度视图展示,支持切换年视图、月视图、周视图等,通过 task-view-config 来配置日期轴。

https://gantt.vxeui.com

效果

代码

通过 task-view-config.scales 可以灵活的切换显示模式

html 复制代码
<template>
  <div>
    <vxe-radio-group v-model="viewMode" @change="changeViewEvent">
      <vxe-radio-button label="1" content="年视图"></vxe-radio-button>
      <vxe-radio-button label="2" content="季度视图"></vxe-radio-button>
      <vxe-radio-button label="3" content="月视图"></vxe-radio-button>
      <vxe-radio-button label="4" content="周视图"></vxe-radio-button>
      <vxe-radio-button label="5" content="日视图"></vxe-radio-button>
    </vxe-radio-group>

    <vxe-gantt v-bind="ganttOptions"></vxe-gantt>
  </div>
</template>

<script setup>
import { reactive, ref } from 'vue'

const viewMode = ref('1')

const taskViewConfig = reactive({
  scales: ['year']
})

const ganttOptions = reactive({
  border: true,
  taskBarConfig: {
    showProgress: true,
    barStyle: {
      round: true,
      bgColor: '#fca60b',
      completedBgColor: '#65c16f'
    }
  },
  taskViewConfig,
  columns: [
    { field: 'name', title: '任务名称' },
    { field: 'start', title: '开始时间', width: 100 },
    { field: 'end', title: '结束时间', width: 100 }
  ],
  data: [
    { id: 10001, name: 'A项目', start: '2023-08-01', end: '2024-11-15', progress: 3 },
    { id: 10002, name: '城市道路修理进度', start: '2024-01-03', end: '2024-03-08', progress: 10 },
    { id: 10003, name: 'B大工程', start: '2024-05-03', end: '2024-07-11', progress: 90 },
    { id: 10004, name: '超级大工程', start: '2024-04-05', end: '2024-06-11', progress: 15 },
    { id: 10005, name: '地球净化项目', start: '2024-07-08', end: '2024-08-15', progress: 100 },
    { id: 10006, name: '一个小目标项目', start: '2024-08-10', end: '2024-11-21', progress: 5 },
    { id: 10007, name: '某某计划', start: '2024-03-15', end: '2024-08-24', progress: 70 },
    { id: 10008, name: '某某科技项目', start: '2024-03-20', end: '2024-03-29', progress: 50 },
    { id: 10009, name: '地铁建设工程', start: '2025-01-19', end: '2025-03-18', progress: 5 },
    { id: 10010, name: '铁路修建计划', start: '2024-12-12', end: '2025-02-10', progress: 10 }
  ]
})

const changeViewEvent = () => {
  switch (viewMode.value) {
    case '1':
      taskViewConfig.scales = ['year']
      break
    case '2':
      taskViewConfig.scales = ['year', 'quarter']
      break
    case '3':
      taskViewConfig.scales = ['year', 'month']
      break
    case '4':
      taskViewConfig.scales = ['year', 'week']
      break
    case '5':
      taskViewConfig.scales = ['month', 'day', 'date']
      break
  }
}
</script>

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

相关推荐
m0_740043731 小时前
Element-UI 组件库的核心组件及其用法
前端·javascript·vue.js·ui·elementui·html
游九尘1 小时前
js:获取上一周,本周,下一周,上个月,本月,下个月的日期时间段
javascript
向上的车轮1 小时前
从“能用”到“好用”:基于 DevUI 构建高维护性、多端自适应的企业级前端架构实践
前端·架构
脾气有点小暴1 小时前
H5 跳转方式
前端·javascript
ghfdgbg1 小时前
11. 后端Web实战:登录认证(令牌 + 过滤器 + 拦截器)
前端
Doris8931 小时前
【JS】JS进阶--作用域、函数、解构赋值、数组方法
开发语言·前端·javascript
黑客思维者1 小时前
核弹级漏洞突袭React生态:RSC反序列化何以成为RCE通道?
前端·javascript·react.js·远程代码执行漏洞
K3v1 小时前
【npm install sentry/cli】安装这个破包一直失败
前端·npm·sentry
山峰哥1 小时前
现代 C++ 的炼金术:铸就高性能与高可维护性的工程实践
java·开发语言·前端·数据结构·c++