gantt.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. {{ src/components/Gantt.vue }}
  2. <template>
  3. <div ref="gantt">
  4. </div>
  5. </template>
  6. <script>
  7. import {gantt} from 'dhtmlx-gantt';
  8. // import 'dhtmlx-gantt/codebase/dhtmlxgantt.css'
  9. // import 'dhtmlx-gantt/codebase/locale/locale_cn' // 本地化
  10. export default {
  11. name: 'gantt',
  12. props: {
  13. tasks: {
  14. type: Object,
  15. default () {
  16. return {data: [], links: []}
  17. }
  18. },
  19. stafforpro: '',
  20. valueDate:[]
  21. },
  22. created:function(){
  23. // gantt.clearAll()
  24. console.log("tasks",this.$props.tasks);
  25. },
  26. methods: {
  27. },
  28. mounted: function () {
  29. gantt.clearAll()
  30. gantt.locale={
  31. date: {
  32. month_full: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
  33. month_short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
  34. day_full: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
  35. day_short: ["日", "一", "二", "三", "四", "五", "六"]
  36. },
  37. labels: {
  38. dhx_cal_today_button: "今天",
  39. day_tab: "日",
  40. week_tab: "周",
  41. month_tab: "月",
  42. new_event: "新建日程",
  43. icon_save: "保存",
  44. icon_cancel: "关闭",
  45. icon_details: "详细",
  46. icon_edit: "编辑",
  47. icon_delete: "删除",
  48. confirm_closing: "请确认是否撤销修改!", //Your changes will be lost, are your sure?
  49. confirm_deleting: "是否删除日程?",
  50. section_description: "描述",
  51. section_time: "时间范围",
  52. section_type: "类型",
  53. /* grid columns */
  54. column_text: "任务名",
  55. column_start_date: "开始时间",
  56. column_duration: "持续时间",
  57. column_add: "",
  58. /* link confirmation */
  59. link: "关联",
  60. confirm_link_deleting: "将被删除",
  61. link_start: " (开始)",
  62. link_end: " (结束)",
  63. type_task: "任务",
  64. type_project: "项目",
  65. type_milestone: "里程碑",
  66. minutes: "分钟",
  67. hours: "小时",
  68. days: "天",
  69. weeks: "周",
  70. months: "月",
  71. years: "年"
  72. }
  73. };
  74. // gantt.config.autosize = true;
  75. gantt.config.duration_unit = "hour";
  76. gantt.config.fit_tasks = true;
  77. gantt.config.drag_move = false;
  78. gantt.config.xml_date = "%Y-%m-%d";
  79. gantt.config.columns=[
  80. {name:"text",label:(this.stafforpro == "人员" ? "员工名称" : "项目名称"), align: "left" },
  81. {name:"duration",label:"计划工时(h)", align: "center" }
  82. // {name:"start_date", label:"开始时间", width:'*' , align: "center" },
  83. // {name:"duration", label:"工时(天)", width:'*' , align: "center" }
  84. ];
  85. gantt.config.scale_unit = "month"; //按月显示
  86. gantt.config.date_scale = "%F, %Y"; //设置时间刻度的格式(X轴) 多个尺度
  87. gantt.config.scale_height = 50; //设置时间刻度的高度和网格的标题
  88. gantt.config.subscales = [
  89. {unit: "day", step: 1, date: "周%D,%d"}
  90. ];
  91. gantt.config.start_date = new Date(this.valueDate[0]);
  92. gantt.config.end_date = new Date(this.valueDate[1]);
  93. //设置任务条样式
  94. gantt.templates.task_class = function (start, end, item) {
  95. return item.parent == 0 ? "person_line" : ""
  96. };
  97. gantt.init(this.$refs.gantt);
  98. // this.$props.tasks.data[31].render = "split"
  99. gantt.parse(this.$props.tasks);
  100. // gantt.groupBy({
  101. // relation_property: "owner",
  102. // groups: [{key:'seya', label: "seya"},{key:'tina', label: "tina"}],
  103. // group_id: "key",
  104. // group_text: "label"
  105. // });
  106. console.log("props",this.$props.tasks);
  107. }
  108. }
  109. </script>
  110. <style>
  111. @import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
  112. .person_line {
  113. background:#8ecaf8;
  114. border: #20a0ff 1px solid
  115. }
  116. </style>