靓天 發表於 2026-3-25 21:27:00

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

<p>通过 taskViewConfig.scales 参数,可以灵活配置甘特图日期轴的显示层级。本文将介绍如何将日期轴显示为“月 + 周”模式,以及如何自定义每周的起始日期。</p>
<h2 id="核心配置示例">核心配置示例</h2>
<p>要显示“月 + 第几周”的双层日期轴,只需在 scales 数组中同时配置 'month' 和 'week' 即可。</p>
<p><img src="https://img2024.cnblogs.com/blog/3766032/202603/3766032-20260325212747120-1835735881.png"></p>
<pre><code class="language-html">&lt;template&gt;
&lt;div&gt;
    &lt;vxe-gantt v-bind="ganttOptions"&gt;&lt;/vxe-gantt&gt;
&lt;/div&gt;
&lt;/template&gt;

&lt;script setup&gt;
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 }
]
})
&lt;/script&gt;
</code></pre>
<h2 id="指定周的起始日期">指定周的起始日期</h2>
<p>默认情况下,周的划分可能以周一或周日为起始,具体取决于组件语言环境。如果需要明确控制每周的起始日期,可以将 scales 中的项从字符串改为对象形式,并通过 startDay 参数指定。</p>
<p>国内项目通常将周一作为一周的起始,默认值为startDay: 1,也自定义设置 。</p>
<pre><code class="language-javascript">taskViewConfig: {
scales: [
    { type: 'month' },
    { type: 'week', startDay: 0 }// 0 = 周日,1 = 周一,以此类推
]
}
</code></pre>
<p>合理配置 scales 参数,可以让甘特图的日期轴更贴合项目管理中对时间周期的展示需求。</p><br><br>
来源:https://www.cnblogs.com/leid6/p/19772436
頁: [1]
查看完整版本: vue甘特图vxe-gantt如何设置日期轴显示为周模式