vxe-gantt 甘特圖使用右鍵菜單,支持表頭菜單、內容菜單、表尾菜單,自定義樣式,配置項 menu-config={header,body,footer},實現對按鈕的控制,通過 visibleMethod 和 visible | disabled 屬性來控制菜單選項的操作權限,可以精確到每一列每一行的顯示隱藏與禁用控制
https://gantt.vxeui.com


菜單點擊後會觸發 menu-click 事件,可以對事件進行處理
<template>
<div>
<vxe-gantt v-bind="ganttOptions" v-on="ganttEvents"></vxe-gantt>
</div>
</template>
<script setup>
import { reactive } from 'vue'
import { VxeUI } from 'vxe-pc-ui'
const ganttOptions = reactive({
border: true,
height: 400,
rowConfig: {
isCurrent: true
},
columnConfig: {
resizable: true
},
taskBarConfig: {
showProgress: true,
showContent: true,
barStyle: {
round: true,
bgColor: '#fca60b',
completedBgColor: '#65c16f'
}
},
taskViewConfig: {
tableStyle: {
width: 480
}
},
columns: [
{ field: 'title', title: '任務名稱' },
{ field: 'start', title: '開始時間', width: 100 },
{ field: 'end', title: '結束時間', width: 100 }
],
data: [
{ id: 10001, title: 'A項目', start: '2024-03-01', end: '2024-03-04', progress: 3 },
{ id: 10002, title: '城市道路修理進度', start: '2024-03-03', end: '2024-03-08', progress: 10 },
{ id: 10003, title: 'B大工程', start: '2024-03-03', end: '2024-03-11', progress: 90 },
{ id: 10004, title: '超級大工程', start: '2024-03-05', end: '2024-03-11', progress: 15 },
{ id: 10005, title: '地球淨化項目', start: '2024-03-08', end: '2024-03-15', progress: 100 },
{ id: 10006, title: '一個小目標項目', start: '2024-03-10', end: '2024-03-21', progress: 5 },
{ id: 10007, title: '某某計劃', start: '2024-03-15', end: '2024-03-24', progress: 70 },
{ id: 10008, title: '某某科技項目', start: '2024-03-20', end: '2024-03-29', progress: 50 },
{ id: 10009, title: '地鐵建設工程', start: '2024-03-19', end: '2024-03-20', progress: 5 },
{ id: 10010, title: '鐵路修建計劃', start: '2024-03-12', end: '2024-03-20', progress: 10 }
],
menuConfig: {
header: {
body: {
options: [
[
{ code: 'copy', name: '複製內容(Ctrl+C)', prefixConfig: { icon: 'vxe-icon-copy' }, visible: true, disabled: false },
{ code: 'clear', name: '清除內容', visible: true, disabled: false },
{ code: 'reload', name: '刷新表格', visible: true, disabled: false }
],
[
{
code: 'fixed',
name: '凍結列',
children: [
{ code: 'cancelFixed', name: '取消凍結' },
{ code: 'fixedLeft', name: '凍結在左側', prefixConfig: { icon: 'vxe-icon-fixed-left' } },
{ code: 'fixedRight', name: '凍結在右側', prefixConfig: { icon: 'vxe-icon-fixed-right' } }
]
}
],
[
{ code: 'myPrint', name: '打印(Ctrl+P)', prefixConfig: { icon: 'vxe-icon-print' }, visible: true, disabled: false },
{ code: 'myExport', name: '導出.csv', prefixConfig: { icon: 'vxe-icon-download' }, visible: true, disabled: false }
]
]
}
}
})
const ganttEvents = {
menuClick ({ menu }) {
VxeUI.modal.message({ content: `點擊了 ${menu.code}`, status: 'success' })
}
}
</script>
https://gitee.com/x-extends/vxe-gantt