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

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

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>

gitee.com/x-extends/v...

相关推荐
你真的快乐吗40 分钟前
@fuxishi/svg-icon:一个 Vue 3 svg本地图标+iconify图标组件库,让图标管理不再头疼
前端·vue.js·typescript
吴声子夜歌2 小时前
Vue3——脚手架Vite
前端·javascript·vue.js·vite
rADu REME3 小时前
SpringBoot + vue 管理系统
vue.js·spring boot·后端
被考核重击4 小时前
Vue响应式原理(下)
前端·javascript·vue.js
前端摸鱼匠15 小时前
Vue 3 的v-bind合并行为:讲解v-bind与普通属性合并的规则
前端·javascript·vue.js·前端框架·ecmascript
Python私教1 天前
Pure-Admin-Thin 深度解析:完整版和精简版到底怎么选?
vue.js·人工智能·开源
ayqy贾杰1 天前
Cursor SDK发布!开发者可直接搬走其内核
前端·vue.js·面试
李白的天不白1 天前
vue 数据格式问题
前端·vue.js·windows
小白蒋博客1 天前
【ai开发段永平投资理财的知识图谱网站】第一天:搭 Vite + Vue 项目,跑通 Hello World
vue.js·人工智能·trae
@yanyu6662 天前
登录注册功能-明文
vue.js·springboot