14、Gantt Link

1、添加一个新的依赖链接
 1 var linkId = gantt.addLink({
 2     id:1,
 3     source:1,
 4     target:2,
 5     type:gantt.config.links.finish_to_start
 6 });
 7 // 在将新链接添加到甘特图之前触发
 8 gantt.attachEvent('onBeforeLinkAdd', function (id, link) {
 9   let sourceTask = gantt.getTask(link.source);
10   let targetTask = gantt.getTask(link.target);
11   console.log(sourceTask, targetTask);
12   console.log(sourceTask.type === 'task' && targetTask.type === 'task');
13   // 只能任务指向任务
14   return sourceTask.type === 'task' && targetTask.type === 'task';
15 });
16 gantt.attachEvent("onAfterLinkAdd", function(id,item){
17     //any custom logic here
18 });

2、删除指定的依赖链接
 1 gantt.addLink({
 2     id:1,
 3     source:1,
 4     target:2,
 5     type:1
 6 });
 7  
 8 gantt.deleteLink(1);
 9 gantt.attachEvent("onBeforeLinkDelete", function(id,item){
10     //any custom logic here
11     return true;
12 });
13 gantt.attachEvent("onAfterLinkDelete", function(id,item){
14     //any custom logic here
15 });
3、指定用户创建新依赖链接时显示的工具提示文本
 1 gantt.templates.drag_link = function (from, from_start, to, to_start) {
 2   from = gantt.getTask(from);
 3   let text =
 4     'From:<b> ' +
 5     from.taskSpecification +
 6     '</b> ' +
 7     (from_start ? 'Start' : 'End') +
 8     '<br/>';
 9   if (to) {
10     to = ganttObj.getTask(to);
11     text +=
12       'To:<b> ' + to.taskSpecification + '</b> ' + (to_start ? 'Start' : 'End') + '<br/>';
13   }
14   return text;
15 };

4、指定链接“删除”确认窗口标题中的文本
 1 // 指定链接“删除”确认窗口标题中的文本
 2 gantt.templates.link_description = function (link) {
 3   const from = gantt.getTask(link.source),
 4     to = gantt.getTask(link.target),
 5     types = gantt.config.links;
 6 
 7   const from_start = link.type == types.start_to_start;
 8   const to_start = link.type == types.finish_to_start || link.type == types.start_to_start;
 9   let text =
10     'From <b>' +
11     from.taskSpecification +
12     '</b> ' +
13     (from_start ? 'Start' : 'End') +
14     '<br/>';
15   text +=
16     'To <b>' + to.taskSpecification + '</b> ' + (to_start ? 'Start' : 'End') + '<br/>';
17 
18   return text;
19 };

 

 

 
posted @ 2022-05-07 16:26  你在说啥  阅读(367)  评论(0)    收藏  举报