博客 / 詳情

返回

vue 甘特圖 vxe-gantt table 連接線的用法教程

vue 甘特圖 vxe-gantt table 連接線的用法教程,通過設置 links 定義連接線,from 對應源任務的行主鍵,tom 對應目標任務的行主鍵

https://gantt.vxeui.com

類型説明
0 FinishToStart 結束後才開始,表示一個任務必須在另一個任務開始之前完成
1 StartToFinish 開始到結束,表示從某個過程的開始到結束的整個過程
2 StartToStart 開始後才開始,表示一個活動結束了,另一個活動才能開始,它們之間按先後順序進行
3 FinishToFinish 完成到完成,表示一個任務必須在另一個任務完成之後才能完成

線配置

通過設置 links 定義連接線,from 對應源任務的行主鍵,tom 對應目標任務的行主鍵

extend_gantt_chart_gantt_dependency_links

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

<script setup>
import { reactive } from 'vue'
import { VxeGanttDependencyType } from 'vxe-gantt'

const ganttOptions = reactive({
  border: true,
  height: 500,
  rowConfig: {
    keyField: 'id' // 行主鍵
  },
  taskBarConfig: {
    showProgress: true, // 是否顯示進度條
    showContent: true, // 是否在任務條顯示內容
    move: true, // 是否允許拖拽任務移動日期
    barStyle: {
      round: true, // 圓角
      bgColor: '#fca60b', // 任務條的背景顏色
      completedBgColor: '#65c16f' // 已完成部分任務條的背景顏色
    }
  },
  taskViewConfig: {
    tableStyle: {
      width: 480 // 表格寬度
    }
  },
  links: [
    { from: 10001, to: 10002, type: VxeGanttDependencyType.FinishToFinish },
    { from: 10004, to: 10005, type: VxeGanttDependencyType.StartToStart },
    { from: 10005, to: 10006, type: VxeGanttDependencyType.FinishToStart },
    { from: 10013, to: 10012, type: VxeGanttDependencyType.StartToFinish }
  ],
  columns: [
    { type: 'seq', width: 70 },
    { field: 'title', title: '任務名稱' },
    { field: 'start', title: '開始時間', width: 100 },
    { field: 'end', title: '結束時間', width: 100 },
    { field: 'progress', title: '進度(%)', width: 80 }
  ],
  data: [
    { id: 10001, title: '任務1', start: '2024-03-01', end: '2024-03-04', progress: 3 },
    { id: 10002, title: '任務2', start: '2024-03-03', end: '2024-03-08', progress: 10 },
    { id: 10003, title: '任務3', start: '2024-03-03', end: '2024-03-11', progress: 90 },
    { id: 10004, title: '任務4', start: '2024-03-05', end: '2024-03-11', progress: 15 },
    { id: 10005, title: '任務5', start: '2024-03-08', end: '2024-03-15', progress: 100 },
    { id: 10006, title: '任務6', start: '2024-03-10', end: '2024-03-21', progress: 5 },
    { id: 10007, title: '任務7', start: '2024-03-15', end: '2024-03-24', progress: 70 },
    { id: 10008, title: '任務8', start: '2024-03-05', end: '2024-03-15', progress: 50 },
    { id: 10009, title: '任務9', start: '2024-03-19', end: '2024-03-20', progress: 5 },
    { id: 10010, title: '任務10', start: '2024-03-12', end: '2024-03-20', progress: 10 },
    { id: 10011, title: '任務11', start: '2024-03-01', end: '2024-03-08', progress: 90 },
    { id: 10012, title: '任務12', start: '2024-03-03', end: '2024-03-06', progress: 60 },
    { id: 10013, title: '任務13', start: '2024-03-02', end: '2024-03-05', progress: 50 },
    { id: 10014, title: '任務14', start: '2024-03-04', end: '2024-03-15', progress: 0 },
    { id: 10015, title: '任務15', start: '2024-03-01', end: '2024-03-05', progress: 30 }
  ]
})
</script>

線類型

通過設置 task-link-config.lineType 設置連接線的樣式類型,可以設置實線、虛線、流式虛線

extend_gantt_chart_gantt_dependency_lineType2

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

<script setup>
import { reactive } from 'vue'
import { VxeGanttDependencyType } from 'vxe-gantt'

const ganttOptions = reactive({
  border: true,
  height: 300,
  rowConfig: {
    keyField: 'id' // 行主鍵
  },
  taskBarConfig: {
    showProgress: true, // 是否顯示進度條
    showContent: true, // 是否在任務條顯示內容
    move: true, // 是否允許拖拽任務移動日期
    barStyle: {
      round: true, // 圓角
      bgColor: '#fca60b', // 任務條的背景顏色
      completedBgColor: '#65c16f' // 已完成部分任務條的背景顏色
    }
  },
  taskViewConfig: {
    tableStyle: {
      width: 480 // 表格寬度
    }
  },
  taskLinkConfig: {
    lineType: 'flowDashed'
  },
  links: [
    { from: 10001, to: 10002, type: VxeGanttDependencyType.FinishToFinish },
    { from: 10004, to: 10005, type: VxeGanttDependencyType.StartToStart },
    { from: 10005, to: 10006, type: VxeGanttDependencyType.FinishToStart },
    { from: 10013, to: 10012, type: VxeGanttDependencyType.StartToFinish }
  ],
  columns: [
    { type: 'seq', width: 70 },
    { field: 'title', title: '任務名稱' },
    { field: 'start', title: '開始時間', width: 100 },
    { field: 'end', title: '結束時間', width: 100 },
    { field: 'progress', title: '進度(%)', width: 80 }
  ],
  data: [
    { id: 10001, title: '任務1', start: '2024-03-01', end: '2024-03-04', progress: 3 },
    { id: 10002, title: '任務2', start: '2024-03-03', end: '2024-03-08', progress: 10 },
    { id: 10003, title: '任務3', start: '2024-03-03', end: '2024-03-11', progress: 90 },
    { id: 10004, title: '任務4', start: '2024-03-05', end: '2024-03-11', progress: 15 },
    { id: 10005, title: '任務5', start: '2024-03-08', end: '2024-03-15', progress: 100 },
    { id: 10006, title: '任務6', start: '2024-03-10', end: '2024-03-21', progress: 5 },
    { id: 10007, title: '任務7', start: '2024-03-15', end: '2024-03-24', progress: 70 },
    { id: 10008, title: '任務8', start: '2024-03-05', end: '2024-03-15', progress: 50 },
    { id: 10009, title: '任務9', start: '2024-03-19', end: '2024-03-20', progress: 5 },
    { id: 10010, title: '任務10', start: '2024-03-12', end: '2024-03-20', progress: 10 },
    { id: 10011, title: '任務11', start: '2024-03-01', end: '2024-03-08', progress: 90 },
    { id: 10012, title: '任務12', start: '2024-03-03', end: '2024-03-06', progress: 60 },
    { id: 10013, title: '任務13', start: '2024-03-02', end: '2024-03-05', progress: 50 },
    { id: 10014, title: '任務14', start: '2024-03-04', end: '2024-03-15', progress: 0 },
    { id: 10015, title: '任務15', start: '2024-03-01', end: '2024-03-05', progress: 30 }
  ]
})
</script>

線顏色

通過設置 task-link-config.lineStatus 設置連接線的狀態顏色,也可以給每條線單獨設置狀態顏色

image

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

<script setup>
import { reactive } from 'vue'
import { VxeGanttDependencyType } from 'vxe-gantt'

const ganttOptions = reactive({
  border: true,
  height: 500,
  rowConfig: {
    keyField: 'id' // 行主鍵
  },
  taskBarConfig: {
    showProgress: true, // 是否顯示進度條
    showContent: true, // 是否在任務條顯示內容
    move: true, // 是否允許拖拽任務移動日期
    barStyle: {
      round: true, // 圓角
      bgColor: '#fca60b', // 任務條的背景顏色
      completedBgColor: '#65c16f' // 已完成部分任務條的背景顏色
    }
  },
  taskViewConfig: {
    tableStyle: {
      width: 480 // 表格寬度
    }
  },
  taskLinkConfig: {
    lineStatus: 'success' // 給所有線設置狀態顏色,內置幾種狀態顏色 'primary', 'success', 'info', 'warning', 'danger', 'error'
  },
  links: [
    { from: 10001, to: 10002, type: VxeGanttDependencyType.FinishToFinish },
    { from: 10004, to: 10005, type: VxeGanttDependencyType.StartToStart },
    { from: 10005, to: 10006, type: VxeGanttDependencyType.FinishToStart },
    { from: 10013, to: 10012, type: VxeGanttDependencyType.StartToFinish }
  ],
  columns: [
    { type: 'seq', width: 70 },
    { field: 'title', title: '任務名稱' },
    { field: 'start', title: '開始時間', width: 100 },
    { field: 'end', title: '結束時間', width: 100 },
    { field: 'progress', title: '進度(%)', width: 80 }
  ],
  data: [
    { id: 10001, title: '任務1', start: '2024-03-01', end: '2024-03-04', progress: 3 },
    { id: 10002, title: '任務2', start: '2024-03-03', end: '2024-03-08', progress: 10 },
    { id: 10003, title: '任務3', start: '2024-03-03', end: '2024-03-11', progress: 90 },
    { id: 10004, title: '任務4', start: '2024-03-05', end: '2024-03-11', progress: 15 },
    { id: 10005, title: '任務5', start: '2024-03-08', end: '2024-03-15', progress: 100 },
    { id: 10006, title: '任務6', start: '2024-03-10', end: '2024-03-21', progress: 5 },
    { id: 10007, title: '任務7', start: '2024-03-15', end: '2024-03-24', progress: 70 },
    { id: 10008, title: '任務8', start: '2024-03-05', end: '2024-03-15', progress: 50 },
    { id: 10009, title: '任務9', start: '2024-03-19', end: '2024-03-20', progress: 5 },
    { id: 10010, title: '任務10', start: '2024-03-12', end: '2024-03-20', progress: 10 },
    { id: 10011, title: '任務11', start: '2024-03-01', end: '2024-03-08', progress: 90 },
    { id: 10012, title: '任務12', start: '2024-03-03', end: '2024-03-06', progress: 60 },
    { id: 10013, title: '任務13', start: '2024-03-02', end: '2024-03-05', progress: 50 },
    { id: 10014, title: '任務14', start: '2024-03-04', end: '2024-03-15', progress: 0 },
    { id: 10015, title: '任務15', start: '2024-03-01', end: '2024-03-05', progress: 30 }
  ]
})
</script>

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

user avatar
0 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.