1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
| <template>
| <div ref="gantt"></div>
| </template>
|
| <script>
| import 'dhtmlx-gantt'
| export default {
| name: 'indexGantt',
| props: {
| tasks: {
| type: Object,
| default () {
| return {data: [], links: []}
| }
| }
| },
| watch: {
| tasks: {
| deep: true,
| handler() {
| //重载
| gantt.init(this.$refs.gantt)
| gantt.clearAll();
| gantt.parse(this.tasks);
| }
| }
| },
| mounted() {
| gantt.config.min_column_width = 50;
| gantt.config.scale_height = 90;
| //左侧是否自适应
| gantt.config.autofit = true;
| //左侧宽
| gantt.config.grid_width = 500;
| //自动调整图表坐标轴区间用于适配task的长度
| gantt.config.fit_tasks = true;
| //日期格式化
| gantt.config.xml_date = "%Y-%m-%d";
| //只读
| gantt.config.readonly = true;
| //汉化
| gantt.locale={
| date: {
| month_full: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"],
| month_short: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
| day_full: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
| day_short: ["日", "一", "二", "三", "四", "五", "六"]
| },
| labels: {
| dhx_cal_today_button: "今天",
| day_tab: "日",
| week_tab: "周",
| month_tab: "月",
| new_event: "新建日程",
| icon_save: "保存",
| icon_cancel: "关闭",
| icon_details: "详细",
| icon_edit: "编辑",
| icon_delete: "删除",
| confirm_closing: "请确认是否撤销修改!", //Your changes will be lost, are your sure?
| confirm_deleting: "是否删除计划?",
| section_description: "描述:",
| section_time: "时间范围:",
| section_type: "类型",
| section_text: "计划名称:",
| section_color: "颜色:",
|
| /* grid columns */
|
| column_text: "计划名称",
| column_start_date: "开始时间",
| column_duration: "持续时间",
| column_add: "",
|
| /* link confirmation */
|
| link: "关联",
| confirm_link_deleting: "将被删除",
| link_start: " (开始)",
| link_end: " (结束)",
|
| type_task: "任务",
| type_project: "项目",
| type_milestone: "里程碑",
|
| minutes: "分钟",
| hours: "小时",
| days: "天",
| weeks: "周",
| months: "月",
| years: "年"
| }
| }
| gantt.config.columns=[
| {name:"text", label:"项目名称", tree:true, width:'*' },
| {name:"start_date", label:"开始时间", align: "center" },
| {name:"end_date", label:"结束时间", align: "center" },
| {name:"progress", label:"进度" , align: "center",
| template:function(obj){
| if(!obj){
| return ''
| }
| return (Math.floor(obj.progress*100)).toString()+'%'
| }
| },
| // {name:"add", label:"" },
| ];
|
| gantt.plugins({
| marker: true,
| tooltip: true,
| fullscreen: true
| });
| gantt.addMarker({
| start_date: new Date(),
| text: '今日'
| });
|
| // 自定义tooltip内容
| gantt.templates.tooltip_text = function(start,end,task){
| return "<b>项目:</b> "+task.text+"<br/><b>开始日期:</b> " +
| gantt.templates.tooltip_date_format(start)+
| "<br/><b>结束日期:</b> "+gantt.templates.tooltip_date_format(end);
| };
|
|
| /*
| //右侧文字提示
| gantt.templates.rightside_text = function(start, end, task){
| return "耗时" + task.duration + " 天";
| };
| */
|
| //显示周末
| /* gantt.config.work_time = true;
|
| gantt.templates.scale_cell_class = function(date){
| if(!gantt.isWorkTime(date)){
| return "weekend";
| }
| };*/
|
| gantt.templates.task_class = function(start, end, task){
| return "";
| };
|
|
| //显示季度
| function quarterLabel(date) {
| var month = date.getMonth();
| var q_num;
|
| if (month >= 9) {
| q_num = 4;
| } else if (month >= 6) {
| q_num = 3;
| } else if (month >= 3) {
| q_num = 2;
| } else {
| q_num = 1;
| }
|
| return "Q" + q_num;
| }
|
| //时间
| gantt.config.scales = [
| {unit: "year", step: 1, format: "%Y"},
| {unit: "quarter", step: 1, format: quarterLabel},
| {unit: "month", step: 1, format: "%M"}
| ];
|
| gantt.init(this.$refs.gantt)
| gantt.parse(this.tasks);
| }
| }
| </script>
|
| <style scoped>
|
| </style>
|
|