Commit 8ba6f51c authored by arvin's avatar arvin

装配单元路线

parent e13caab2
......@@ -143,7 +143,31 @@ export default {
}
},
calcCriticalPath(link) {
// 找出当前link 同级 task link
const peerTasks = this.getPeerTasks(link)
const peerLinks = this.getPeerLinks(peerTasks)
if (peerLinks.length === 0) {
return
}
const peerGroups = this.getPeerGroups(peerLinks)
// 获取关键路径上的link
const isCriticalLinks = this.getIsCriticalLinks(peerGroups, peerTasks)
// 取消原有 关键字
peerLinks.filter(l => !isCriticalLinks.includes(l.id + ''))
.forEach(l => {
if (l.isCritical) {
l.isCritical = false
this.modifyLink(l, 'MODIFY')
}
})
// 设置新的 关键字
peerLinks.filter(l => isCriticalLinks.includes(l.id + ''))
.forEach(l => {
if (!l.isCritical) {
l.isCritical = true
this.modifyLink(l, 'MODIFY')
}
})
},
modifyLink(link, operator) {
const _link = {
......@@ -157,11 +181,15 @@ export default {
// 判断是否为恢复旧数据
const item = this.modifyData.links.find(l => l.sourceId === _link.sourceId && l.targetId === _link.targetId)
if (item) {
if (item.id) {
item.operator = ''
} else {
this.modifyData.links.push(_link)
item.operator = 'ADD'
}
} else {
this.modifyData.links.push(_link)
}
} else if (operator === 'REMOVE') {
// 判断是为删除新数据
const itemIdx = this.modifyData.links.findIndex(l => !l.id && l.sourceId === _link.sourceId && l.targetId === _link.targetId)
if (itemIdx > -1) {
......@@ -174,7 +202,60 @@ export default {
} else {
this.modifyData.links.push(_link)
}
} else {
// 判断是为删除新数据
const itemIdx = this.modifyData.links.findIndex(l => !l.id && l.sourceId === _link.sourceId && l.targetId === _link.targetId)
if (itemIdx > -1) {
this.modifyData.links[itemIdx] = { ..._link }
} else {
this.modifyData.links.push(_link)
}
}
},
getMaxWorkHour(peerTasks) {
let maxWorkHour = 0
peerTasks.forEach(t => {
if (t.duration > maxWorkHour) {
maxWorkHour = t.duration
}
})
return maxWorkHour
},
getIsCriticalLinks(peerGroups, peerTasks) {
let maxWorkHour = this.getMaxWorkHour(peerTasks)
let isCriticalLinks = []
peerGroups.forEach(g => {
let _max = 0
g.tasks.forEach(id => {
const task = peerTasks.find(t => t.id === id)
if (task) {
_max = _max + task.duration
}
})
if (_max > maxWorkHour) {
maxWorkHour = _max
isCriticalLinks = g.links
}
})
return isCriticalLinks
},
getPeerGroups(links) {
const str = links.map(l => l.id).join()
const allGroups = this.gantt.getConnectedGroup()
return allGroups.filter(g => g.links.find(id => str.includes(id + '')))
},
getPeerTasks(link) {
const allTasks = this.gantt.getTableData().data.data
const target = Number(link.target)
const targetTask = allTasks.find(t => t.id === target)
if (!targetTask) {
return []
}
return allTasks.filter(t => t.parenId === targetTask.parenId)
},
getPeerLinks(tasks) {
const allLinks = this.gantt.getTableData().data.links
return allLinks.filter(l => tasks.find(t => t.id === Number(l.target)))
},
getData(flag) {
if (!flag && this.loading && (this.currentId === this.node.id)) {
......@@ -477,13 +558,15 @@ export default {
return text
}
ganttAss.attachEvent('onAfterLinkAdd', function(id, item) {
that.calcCriticalPath(item)
that.modifyLink(item, 'ADD')
console.log('onAfterLinkAdd', id, item)
ganttAss.render()
})
// 删除连接后触发
ganttAss.attachEvent('onAfterLinkDelete', function(id, item) {
console.log('onAfterLinkDelete', id, item)
var target = ganttAss.getTask(item.target)
that.calcCriticalPath(item)
that.modifyLink(item, 'REMOVE')
var targetLength = target.$target.length
if (!targetLength) {
......@@ -637,5 +720,15 @@ export default {
.gatt{
height: calc(100% - 40px );
}
.critical_path{
.gantt_line_wrapper {
div{
background-color: #e63030;
}
}
.gantt_link_arrow_right{
border-left-color: #e63030;
}
}
}
</style>
......@@ -440,14 +440,14 @@ export default {
.gatt{
height: calc(100% - 40px );
}
.gantt_critical_task{
background: #f39c4f;
border: 1px solid #f39c4f;
}
.gantt_task_line{
&.workday_over{
background: #f39c4f;
border: 1px solid #f39c4f;
.critical_path{
.gantt_line_wrapper {
div{
background-color: #e63030;
}
}
.gantt_link_arrow_right{
border-left-color: #e63030;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment