gantt.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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", tree:true},
  81. // {name:"time",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.open_tree_initially = true;
  89. // gantt.config.layout = {
  90. // css: "gantt_container",
  91. // rows:[
  92. // {
  93. // cols: [
  94. // {
  95. // // the default grid view
  96. // view: "grid",
  97. // scrollX:"scrollHor",
  98. // scrollY:"scrollVer"
  99. // },
  100. // { resizer: true, width: 2 },
  101. // {
  102. // // the default timeline view
  103. // view: "timeline",
  104. // scrollX:"scrollHor",
  105. // scrollY:"scrollVer"
  106. // },
  107. // {
  108. // view: "scrollbar",
  109. // id:"scrollVer"
  110. // }
  111. // ]},
  112. // {
  113. // view: "scrollbar",
  114. // id:"scrollHor"
  115. // }
  116. // ]
  117. // }
  118. // gantt.templates.task_time = function(start,end,task){
  119. // console.log('startend',start,end,task);
  120. // let Jstart = JSON.parse(JSON.stringify(start))
  121. // let Jend = JSON.parse(JSON.stringify(end))
  122. // let estartmonth = Jstart.getMonth() + 1
  123. // let estartday = Jstart.getDate()
  124. // let estart = Jstart.getFullYear() + '-' + (estartmonth < 10 ? '0' + estartmonth : estartmonth) + '-' + (estartday < 10 ? '0' + estartday : estartday)
  125. // let tend = new Date(Jend.setDate(end.getDate() - 1))
  126. // let eendmonth = tend.getMonth() + 1
  127. // let eendday = tend.getDate()
  128. // let eend = tend.getFullYear() + '-' + (eendmonth < 10 ? '0' + eendmonth : eendmonth) + '-' + (eendday < 10 ? '0' + eendday : eendday)
  129. // return estart + ' ' + eend
  130. // };
  131. gantt.config.subscales = [
  132. {unit: "day", step: 1, date: "周%D,%d"}
  133. ];
  134. gantt.config.buttons_left = []
  135. gantt.config.buttons_right = ["gantt_cancel_btn"]
  136. gantt.config.drag_links = false
  137. gantt.config.drag_resize = false
  138. gantt.config.drag_progress = false
  139. gantt.config.details_on_dblclick = false
  140. gantt.config.lightbox.sections = [
  141. {name:"description", height:76, map_to:"text", type:"textarea",focus:true}
  142. ];
  143. gantt.config.start_date = new Date(this.valueDate[0]);
  144. gantt.config.end_date = new Date(this.valueDate[1]);
  145. //设置任务条样式
  146. gantt.templates.task_class = function (start, end, item) {
  147. return item.parent == 0 ? "person_line" : ""
  148. };
  149. gantt.init(this.$refs.gantt);
  150. // this.$props.tasks.data[31].render = "split"
  151. gantt.parse(this.$props.tasks);
  152. // gantt.groupBy({
  153. // relation_property: "owner",
  154. // groups: [{key:'seya', label: "seya"},{key:'tina', label: "tina"}],
  155. // group_id: "key",
  156. // group_text: "label"
  157. // });
  158. // console.log("props",gantt);
  159. }
  160. }
  161. </script>
  162. <style>
  163. @import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
  164. .person_line {
  165. background:#8ecaf8;
  166. border: #20a0ff 1px solid
  167. }
  168. </style>