gantt.vue 3.7 KB

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