查看: 99|回复: 0

vue甘特图vxe-gantt如何设置日期轴显示为周模式

[复制链接]

2

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2011-11-22
发表于 2026-3-25 21:27:00 | 显示全部楼层 |阅读模式

通过 taskViewConfig.scales 参数,可以灵活配置甘特图日期轴的显示层级。本文将介绍如何将日期轴显示为“月 + 周”模式,以及如何自定义每周的起始日期。

核心配置示例

要显示“月 + 第几周”的双层日期轴,只需在 scales 数组中同时配置 'month' 和 'week' 即可。

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

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

const ganttOptions = reactive({
  border: true,
  columnConfig: {
    resizable: true
  },
  taskViewConfig: {
    scales: ['month', 'week'],
    tableStyle: {
      width: 320
    }
  },
  columns: [
    { field: 'name', title: '任务名称' },
    { field: 'start', title: '开始时间' },
    { field: 'end', title: '结束时间' }
  ],
  data: [
    { id: 10001, name: 'A项目', start: '2026-01-01', end: '2026-01-09', progress: 3 },
    { id: 10002, name: '城市道路修理进度', start: '2026-01-05', end: '2026-01-14', progress: 10 },
    { id: 10003, name: 'B大工程', start: '2026-01-12', end: '2026-01-21', progress: 90 },
    { id: 10004, name: '超级大工程', start: '2026-01-18', end: '2026-01-30', progress: 15 }
  ]
})
</script>

指定周的起始日期

默认情况下,周的划分可能以周一或周日为起始,具体取决于组件语言环境。如果需要明确控制每周的起始日期,可以将 scales 中的项从字符串改为对象形式,并通过 startDay 参数指定。

国内项目通常将周一作为一周的起始,默认值为startDay: 1,也自定义设置 。

taskViewConfig: {
  scales: [
    { type: 'month' },
    { type: 'week', startDay: 0 }  // 0 = 周日,1 = 周一,以此类推
  ]
}

合理配置 scales 参数,可以让甘特图的日期轴更贴合项目管理中对时间周期的展示需求。



来源:https://www.cnblogs.com/leid6/p/19772436
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部