Commit 3c449556 authored by arvin's avatar arvin

update

parent 4561150d
......@@ -21,6 +21,138 @@ export default {
critical_path: true,
auto_scheduling: true
})
},
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.gantt.refreshLink(l.id)
this.modifyLink(l, 'MODIFY')
}
})
// 设置新的 关键字
peerLinks.filter(l => isCriticalLinks.includes(l.id + ''))
.forEach(l => {
if (!l.isCritical) {
l.isCritical = true
this.gantt.refreshLink(l.id)
this.modifyLink(l, 'MODIFY')
}
})
},
modifyTask(task, operator) {
const _task = {
id: task.id,
duration: task.duration,
operator
}
const item = this.modifyData.tasks.find(t => t.id === _task.id)
if (item) {
item.duration = _task.duration
} else {
this.modifyData.tasks.push(_task)
}
},
modifyLink(link, operator) {
const _link = {
sourceId: Number(link.source),
targetId: Number(link.target),
isCritical: link.isCritical,
id: link.cid,
operator
}
if (operator === 'ADD') {
// 判断是否为恢复旧数据
const item = this.modifyData.links.find(l => l.sourceId === _link.sourceId && l.targetId === _link.targetId)
if (item) {
if (item.id) {
item.operator = ''
} else {
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) {
const item = this.modifyData.links[itemIdx]
if (item.id) {
item.operator = 'REMOVE'
} else {
this.modifyData.links.splice(itemIdx, 1)
}
} else {
this.modifyData.links.push(_link)
}
} else {
// 判断是为删除新数据
const item = this.modifyData.links.find(l => !l.id && l.sourceId === _link.sourceId && l.targetId === _link.targetId)
if (item) {
item.isCritical = _link.isCritical
} 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
}
})
console.log(peerGroups, isCriticalLinks)
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)))
}
}
......
......@@ -142,121 +142,7 @@ export default {
duration: this.toDuration(n.workHour)
}
},
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 = {
sourceId: Number(link.source),
targetId: Number(link.target),
isCritical: link.isCritical,
id: link.cid,
operator
}
if (operator === 'ADD') {
// 判断是否为恢复旧数据
const item = this.modifyData.links.find(l => l.sourceId === _link.sourceId && l.targetId === _link.targetId)
if (item) {
if (item.id) {
item.operator = ''
} else {
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) {
const item = this.modifyData.links[itemIdx]
if (item.id) {
item.operator = 'REMOVE'
} else {
this.modifyData.links.splice(itemIdx, 1)
}
} 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)) {
return
......@@ -660,10 +546,7 @@ export default {
CsvExportor.downloadCsv(tableData, { header }, '装配单元路线.csv')
},
search() {
if (!this.AOname) {
return
}
const tasks = this.params.data.filter(task => task.$level === 2 && (task.right_text.includes(this.AOname) || task.text.includes(this.AOname)))
const tasks = this.params.data.filter(task => task.$level === 1 && (!this.AOname || task.right_text.includes(this.AOname) || task.text.includes(this.AOname)))
const parentTasks = []
if (tasks.length) {
tasks.forEach(task => {
......
......@@ -402,10 +402,7 @@ export default {
CsvExportor.downloadCsv(tableData, { header }, '架次视图路线.csv')
},
search() {
if (!this.AOname) {
return
}
const tasks = this.params.data.filter(task => task.$level === 2 && (task.right_text.includes(this.AOname) || task.text.includes(this.AOname)))
const tasks = this.params.data.filter(task => task.$level === 2 && (!this.AOname || task.right_text.includes(this.AOname) || task.text.includes(this.AOname)))
const parentTasks = []
if (tasks.length) {
tasks.forEach(task => {
......
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