gantt.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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.config.grid_width = 350;
  150. gantt.plugins({tooltip: true});
  151. gantt.templates.tooltip_text = function (start, end, task) {
  152. return
  153. };
  154. // gantt.ext.tooltips.tooltip.show = function(event){
  155. // // console.log('show', event);
  156. // }
  157. // console.log('show',gantt.ext.tooltips.tooltip.show);
  158. // gantt.ext.tooltips.tooltip = {
  159. // getNode: function (params) {
  160. // // console.log('getNode',params);
  161. // },
  162. // hide: function(){
  163. // // console.log('hide');
  164. // },
  165. // setContent: function(){
  166. // // console.log('setContent');
  167. // },
  168. // show: function(event){
  169. // console.log('show',event);
  170. // },
  171. // }
  172. gantt.ext.tooltips.attach({
  173. selector: '.gantt_grid [' + gantt.config.task_attribute + ']',
  174. onmouseenter: (event,node) => {
  175. if(node.textContent.length > 19){
  176. let sdom = document.createElement('span')
  177. sdom.innerText = node.innerText
  178. sdom.className = 'tooltiptext'
  179. node.appendChild(sdom)
  180. }
  181. },
  182. onmousemove: () => {},
  183. onmouseleave: (event,node) => {
  184. let sdom = document.getElementsByClassName('tooltiptext')[0]
  185. if(sdom){node.removeChild(sdom)}
  186. },
  187. // html: (event,node) => {
  188. // const targetTaskId = gantt.locate(event)
  189. // const task = gantt.getTask(targetTaskId)
  190. // return gantt.templates.tooltip_text(null,null,task)
  191. // },
  192. global: true
  193. })
  194. gantt.init(this.$refs.gantt);
  195. // this.$props.tasks.data[31].render = "split"
  196. gantt.parse(this.$props.tasks);
  197. // gantt.groupBy({
  198. // relation_property: "owner",
  199. // groups: [{key:'seya', label: "seya"},{key:'tina', label: "tina"}],
  200. // group_id: "key",
  201. // group_text: "label"
  202. // });
  203. // console.log("props",gantt);
  204. }
  205. }
  206. </script>
  207. <style>
  208. @import "~dhtmlx-gantt/codebase/dhtmlxgantt.css";
  209. .person_line {
  210. background:#8ecaf8;
  211. border: #20a0ff 1px solid
  212. }
  213. /* .gantt_tooltip{
  214. z-index: 10000;
  215. top: 10px !important;
  216. left: 10px !important;
  217. } */
  218. .tooltiptext{
  219. visibility: visible;
  220. background-color: #fff;
  221. color: #454545;
  222. box-shadow: 3px 3px 3px rgba(0,0,0,.07);
  223. border-left: 1px solid rgba(0,0,0,.07);
  224. border-top: 1px solid rgba(0,0,0,.07);
  225. font-size: 8pt;
  226. line-height: 20px;
  227. padding: 10px;
  228. /* opacity: 0;
  229. transition: 0.5s; */
  230. position: absolute;
  231. z-index: 10000;
  232. bottom: 120%;
  233. left: 25px;
  234. max-width: 300px;
  235. /* word-wrap: break-word;
  236. word-break: break-all; */
  237. white-space: pre-wrap;
  238. }
  239. </style>