vue dhtmlx-gantt(甘特图-拖拽)

#1、安装依赖

cnpm i dhtmlx-gantt -s 或 npm i dhtmlx-gantt -s

#2、创建demo.vue

<!--
 * @Description: gantt
 * @Author: PengShuai
 * @Date: 2022-02-14 10:31:40
 * @LastEditors: PengShuai
 * @LastEditTime: 2022-02-14 10:39:07
-->
<template>
  <div class="warpper">
    <div ref="gantt" class="gantt-container" />
  </div>
</template>

<script>
// 引入模块
import gantt from 'dhtmlx-gantt'
import 'dhtmlx-gantt/codebase/dhtmlxgantt.css'
export default {
  name: 'Gantt',
  data() {
    return {}
  },
  mounted() {
  },
  methods: {
  },
}
</script>

#3、方法

export default {
  name: 'Gantt',
  data() {
    return {
      // 甘特图配置
      tasks: {
        data: [],
      },
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    // 初始化
    init() {
      // 自动延长时间刻度
      gantt.config.fit_tasks = true
      // 允许拖放
      gantt.config.drag_project = true
      // 定义时间格式
      gantt.config.scales = [
        { unit: 'month', step: 1, date: '%F, %Y' },
        { unit: 'day', step: 1, date: '%j, %D' },
      ]
      // 添加弹窗属性
      gantt.config.lightbox.sections = [
        {
          name: 'description',
          height: 70,
          map_to: 'text',
          type: 'textarea',
          focus: true,
        },
        { name: 'type', type: 'typeselect', map_to: 'type' },
        { name: 'time', type: 'duration', map_to: 'auto' },
      ]
      // 初始化
      gantt.init(this.$refs.gantt)
      // 数据解析
      gantt.parse(this.tasks)
    }
  }
}

#4、数据源

  data() {
    return {
      // 甘特图配置
      tasks: {
        data: [
          {
            id: 11,
            text: 'Project #1',
            type: gantt.config.types.project,
            progress: 0.6,
            open: true,
          },

          {
            id: 12,
            text: 'Task #1',
            start_date: '03-04-2022',
            duration: '5',
            parent: '11',
            progress: 1,
            open: true,
          },
          {
            id: 13,
            text: 'Task #2',
            start_date: '03-04-2022',
            type: gantt.config.types.project,
            parent: '11',
            progress: 0.5,
            open: true,
          },
          {
            id: 14,
            text: 'Task #3',
            start_date: '02-04-2022',
            duration: '6',
            parent: '11',
            progress: 0.8,
            open: true,
          },
          {
            id: 15,
            text: 'Task #4',
            type: gantt.config.types.project,
            parent: '11',
            progress: 0.2,
            open: true,
          },
          {
            id: 16,
            text: 'Final milestone',
            start_date: '15-04-2022',
            type: gantt.config.types.milestone,
            parent: '11',
            progress: 0,
            open: true,
          },

          {
            id: 17,
            text: 'Task #2.1',
            start_date: '03-04-2022',
            duration: '2',
            parent: '13',
            progress: 1,
            open: true,
          },
          {
            id: 18,
            text: 'Task #2.2',
            start_date: '06-04-2022',
            duration: '3',
            parent: '13',
            progress: 0.8,
            open: true,
          },
          {
            id: 19,
            text: 'Task #2.3',
            start_date: '10-04-2022',
            duration: '4',
            parent: '13',
            progress: 0.2,
            open: true,
          },
          {
            id: 20,
            text: 'Task #2.4',
            start_date: '10-04-2022',
            duration: '4',
            parent: '13',
            progress: 0,
            open: true,
          },
          {
            id: 21,
            text: 'Task #4.1',
            start_date: '03-04-2022',
            duration: '4',
            parent: '15',
            progress: 0.5,
            open: true,
          },
          {
            id: 22,
            text: 'Task #4.2',
            start_date: '03-04-2022',
            duration: '4',
            parent: '15',
            progress: 0.1,
            open: true,
          },
          {
            id: 23,
            text: 'Mediate milestone',
            start_date: '14-04-2022',
            type: gantt.config.types.milestone,
            parent: '15',
            progress: 0,
            open: true,
          },
        ],
        links: [
          { id: '10', source: '11', target: '12', type: '1' },
          { id: '11', source: '11', target: '13', type: '1' },
          { id: '12', source: '11', target: '14', type: '1' },
          { id: '13', source: '11', target: '15', type: '1' },
          { id: '14', source: '23', target: '16', type: '0' },
          { id: '15', source: '13', target: '17', type: '1' },
          { id: '16', source: '17', target: '18', type: '0' },
          { id: '17', source: '18', target: '19', type: '0' },
          { id: '18', source: '19', target: '20', type: '0' },
          { id: '19', source: '15', target: '21', type: '2' },
          { id: '20', source: '15', target: '22', type: '2' },
          { id: '21', source: '15', target: '23', type: '0' },
        ],
      },
    }
  },

#5、例

#6、API地址
https://docs.dhtmlx.com/gantt/desktop__dnd.html#draggingprojectswithsubtasks
#7、演示地址
https://docs.dhtmlx.com/gantt/samples/08_api/19_draggable_projects.html

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当涉及到 Vue DHTMLX-Gantt 导出甘特图到 Excel 的详细教程时,以下是一步一步的指南: 1. 确保您的项目中已经安装了 VueDHTMLX-Gantt。如果尚未安装,请使用以下命令进行安装: ```bash npm install vue dhtmlx-gantt ``` 2. 在您的 Vue 组件中引入所需的库和样式: ```javascript import 'dhtmlx-gantt'; import 'dhtmlx-gantt/codebase/dhtmlxgantt.css'; import * as XLSX from 'xlsx'; import FileSaver from 'file-saver'; ``` 3. 创建一个 Vue 组件,并在模板中添加一个 Gantt 图表和一个按钮: ```html <template> <div ref="ganttContainer" style="width: 100%; height: 600px;"></div> <button @click="exportGantt">导出 Excel</button> </template> <script> export default { mounted() { const ganttContainer = this.$refs.ganttContainer; gantt.init(ganttContainer); // 设置 Gantt 图表的配置和数据 // 示例数据 const tasks = [ { id: 1, text: '任务1', start_date: '2022-01-01', duration: 5, progress: 0.5 }, { id: 2, text: '任务2', start_date: '2022-01-06', duration: 4, progress: 0.2 }, // 其他任务... ]; gantt.parse({ data: tasks }); }, methods: { exportGantt() { const gantt = this.$refs.ganttContainer.$gantt; const data = gantt.serialize(); const worksheet = XLSX.utils.json_to_sheet(data); const workbook = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(workbook, worksheet, 'Gantt Data'); const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' }); const excelData = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); FileSaver.saveAs(excelData, 'gantt_data.xlsx'); }, }, }; </script> <style> /* 可选的样式 */ </style> ``` 4. 在上述示例代码中,需要注意以下部分: - 在 `mounted` 钩子中,使用 `gantt.init(ganttContainer)` 初始化 Gantt 图表,并根据您的需求设置其配置和数据。 - `exportGantt` 方法用于将 Gantt 图表数据导出到 Excel。确保在 `exportGantt` 方法中的 `this.$refs.ganttContainer.$gantt` 是对 Gantt 图表组件的正确引用。 - 点击 "导出 Excel" 按钮时,将会生成一个名为 `gantt_data.xlsx` 的 Excel 文件,其中包含了 Gantt 图表的数据。 这就是使用 Vue DHTMLX-Gantt 导出甘特图到 Excel 的详细教程。希望对您有所帮助!如果您有任何其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值