gantt.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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: [this.$t('yiYue'), this.$t('erYue'), this.$t('sanYue'), this.$t('siYue'), this.$t('thisTWuyue'), this.$t('liuYue'), this.$t('qiYue'), this.$t('baYue'), this.$t('jiuYue'), this.$t('shiYue'), this.$t('shiYiYue'), this.$t('shiErYue')],
  33. month_short: [this.$t('1Yue'), this.$t('2Yue'), this.$t('3Yue'), this.$t('4Yue'), this.$t('5Yue'), this.$t('6Yue'), this.$t('7Yue'), this.$t('8Yue'), this.$t('9Yue'), this.$t('10Yue'), this.$t('11Yue'), this.$t('12Yue')],
  34. day_full: [this.$t('xingQiRi'), this.$t('xingQiYi'), this.$t('xingQiEr'), this.$t('xingQiSan'), this.$t('xingQiSi'), this.$t('xingQiWu'), this.$t('xingQiLiu')],
  35. day_short: [this.$t('ri'), "一", "二", "三", "四", "五", "六"]
  36. },
  37. labels: {
  38. dhx_cal_today_button: this.$t('jinTian'),
  39. day_tab: this.$t('weekDay.day'),
  40. week_tab: this.$t('zhou'),
  41. month_tab: this.$t('weekDay.month'),
  42. new_event: this.$t('xinJianRiCheng'),
  43. icon_save: this.$t('save'),
  44. icon_cancel: this.$t('Shutdown'),
  45. icon_details: this.$t('xiangXi'),
  46. icon_edit: this.$t('bian-ji'),
  47. icon_delete: this.$t('btn.delete'),
  48. confirm_closing: this.$t('qingQueRenShiFouCheXiaoXiuGai'), //Your changes will be lost, are your sure?
  49. confirm_deleting: this.$t('shiFouShanChuRiCheng'),
  50. section_description: this.$t('other.describe'),
  51. section_time: this.$t('shiJianFanWei'),
  52. section_type: this.$t('types'),
  53. /* grid columns */
  54. column_text: this.$t('renWuMing'),
  55. column_start_date: this.$t('starttimes'),
  56. column_duration: this.$t('chiXuShiJian'),
  57. column_add: "",
  58. /* link confirmation */
  59. link: this.$t('guanLian'),
  60. confirm_link_deleting: this.$t('jiangBeiShanChu'),
  61. link_start: this.$t('kaiShi'),
  62. link_end: this.$t('jieShu'),
  63. type_task: this.$t('other.task'),
  64. type_project: this.$t('other.project'),
  65. type_milestone: this.$t('other.milestone'),
  66. minutes: this.$t('fenZhong'),
  67. hours: this.$t('time.hour'),
  68. days: this.$t('time.day'),
  69. weeks: this.$t('zhou'),
  70. months: this.$t('weekDay.month'),
  71. years: this.$t('nian')
  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 == this.$t('anRenYuanChaKan') ? this.$t('lable.name') : this.$t('headerTop.projectName')), 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: 1px solid;
  212. @include border_color("border_color");
  213. }
  214. /* .gantt_tooltip{
  215. z-index: 10000;
  216. top: 10px !important;
  217. left: 10px !important;
  218. } */
  219. .tooltiptext{
  220. visibility: visible;
  221. background-color: #fff;
  222. color: #454545;
  223. box-shadow: 3px 3px 3px rgba(0,0,0,.07);
  224. border-left: 1px solid rgba(0,0,0,.07);
  225. border-top: 1px solid rgba(0,0,0,.07);
  226. font-size: 8pt;
  227. line-height: 20px;
  228. padding: 10px;
  229. /* opacity: 0;
  230. transition: 0.5s; */
  231. position: absolute;
  232. z-index: 10000;
  233. bottom: 120%;
  234. left: 25px;
  235. max-width: 300px;
  236. /* word-wrap: break-word;
  237. word-break: break-all; */
  238. white-space: pre-wrap;
  239. }
  240. </style>