vue table 甘特图 vxe-gantt 实现多个表格的任务互相拖拽数据
对于需要实现多表数据互相拖拽的场景就非常有用了,实现方式非常简单

查看官网:
Github:
Gitee:

效果

代码

通过参数 row-drag-config.isCrossTableDrag 启用跨表格、多表格互相拖拽。跨表拖拽需要确保数据主键不重复,通过 row-config.keyField 指定主键字段名

<template>  <div>    <vxe-button status="success" @click="resultEvent1">获取数据1</vxe-button>    <vxe-gantt ref="ganttRef1" v-bind="ganttOptions1"></vxe-gantt>    <vxe-button status="success" @click="resultEvent2">获取数据2</vxe-button>    <vxe-gantt ref="ganttRef2" v-bind="ganttOptions2"></vxe-gantt>    <vxe-button status="success" @click="resultEvent3">获取数据3</vxe-button>    <vxe-gantt ref="ganttRef3" v-bind="ganttOptions3"></vxe-gantt>  </div></template><script setup>import { ref, reactive } from 'vue'import { VxeUI } from 'vxe-pc-ui'const ganttRef1 = ref()const ganttOptions1 = reactive({  border: true,  height: 240,  rowConfig: {    drag: true,    keyField: 'id'  },  rowDragConfig: {    isCrossTableDrag: true // 允许跨表  },  columns: [    { type: 'seq', width: 70 },    { field: 'title', title: '任务名称', minWidth: 160, dragSort: true },    { 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: 0 }  ]})const resultEvent1 = () => {  const $gantt = ganttRef1.value  if ($gantt) {    const { insertRecords, removeRecords } = $gantt.getRecordset()    const tableData = $gantt.getFullData()    VxeUI.modal.message({      content: `新增:${insertRecords.length} 删除:${removeRecords.length} 现有:${tableData.length}`,      status: 'success'    })  }}const ganttRef2 = ref()const ganttOptions2 = reactive({  border: true,  height: 240,  rowConfig: {    drag: true,    keyField: 'id'  },  rowDragConfig: {    isCrossTableDrag: true // 允许跨表  },  columns: [    { type: 'seq', width: 70 },    { field: 'title', title: '任务名称', minWidth: 160, dragSort: true },    { field: 'start', title: '开始时间', width: 100 },    { field: 'end', title: '结束时间', width: 100 }  ],  data: [    { 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: '公寓装修计划2', start: '2024-03-12', end: '2024-03-20', progress: 30 },    { id: 10011, title: '两个小目标工程', start: '2024-03-01', end: '2024-03-04', progress: 20 },    { id: 10012, title: '蓝天计划', start: '2024-03-02', end: '2024-03-08', progress: 50 },    { id: 10013, title: 'C大项目', start: '2024-03-08', end: '2024-03-11', progress: 10 },    { id: 10014, title: 'H计划', start: '2024-03-12', end: '2024-03-16', progress: 100 }  ]})const resultEvent2 = () => {  const $gantt = ganttRef2.value  if ($gantt) {    const { insertRecords, removeRecords } = $gantt.getRecordset()    const tableData = $gantt.getFullData()    VxeUI.modal.message({      content: `新增:${insertRecords.length} 删除:${removeRecords.length} 现有:${tableData.length}`,      status: 'success'    })  }}const ganttRef3 = ref()const ganttOptions3 = reactive({  border: true,  height: 240,  rowConfig: {    drag: true,    keyField: 'id'  },  rowDragConfig: {    isCrossTableDrag: true // 允许跨表  },  columns: [    { type: 'seq', width: 70 },    { field: 'title', title: '任务名称', minWidth: 160, dragSort: true },    { field: 'start', title: '开始时间', width: 100 },    { field: 'end', title: '结束时间', width: 100 }  ],  data: [    { id: 10015, title: '铁路修建计划', start: '2024-03-05', end: '2024-03-06', progress: 0 },    { id: 10016, title: 'D项目', start: '2024-03-06', end: '2024-03-11', progress: 10 },    { id: 10017, title: '海外改造工程', start: '2024-03-08', end: '2024-03-09', progress: 0 },    { id: 10018, title: 'Z计划', start: '2024-03-24', end: '2024-03-26', progress: 80 },    { id: 10019, title: 'F工程', start: '2024-03-20', end: '2024-03-28', progress: 10 },    { id: 10020, title: '投资大项目', start: '2024-03-23', end: '2024-03-28', progress: 60 },    { id: 10021, title: 'X计划', start: '2024-03-16', end: '2024-03-25', progress: 10 },    { id: 10022, title: '上天计划', start: '2024-03-05', end: '2024-03-24', progress: 0 },    { id: 10023, title: 'G项目', start: '2024-03-08', end: '2024-03-28', progress: 5 },    { id: 10024, title: '下地计划', start: '2024-03-09', end: '2024-03-16', progress: 50 }  ]})const resultEvent3 = () => {  const $gantt = ganttRef3.value  if ($gantt) {    const { insertRecords, removeRecords } = $gantt.getRecordset()    const tableData = $gantt.getFullData()    VxeUI.modal.message({      content: `新增:${insertRecords.length} 删除:${removeRecords.length} 现有:${tableData.length}`,      status: 'success'    })  }}</script>

本站提供的所有下载资源均来自互联网,仅提供学习交流使用,版权归原作者所有。如需商业使用,请联系原作者获得授权。 如您发现有涉嫌侵权的内容,请联系我们 邮箱:[email protected]