|
|
|
@ -22,7 +22,12 @@ import { formatParams } from '@/views/projects/task/components/node/format-data'
|
|
|
|
|
import { useCellUpdate } from './dag-hooks' |
|
|
|
|
import type { Ref } from 'vue' |
|
|
|
|
import type { Graph } from '@antv/x6' |
|
|
|
|
import type { Coordinate, NodeData, WorkflowDefinition } from './types' |
|
|
|
|
import type { |
|
|
|
|
Coordinate, |
|
|
|
|
NodeData, |
|
|
|
|
WorkflowDefinition, |
|
|
|
|
EditWorkflowDefinition |
|
|
|
|
} from './types' |
|
|
|
|
|
|
|
|
|
interface Options { |
|
|
|
|
graph: Ref<Graph | undefined> |
|
|
|
@ -36,10 +41,18 @@ interface Options {
|
|
|
|
|
*/ |
|
|
|
|
export function useTaskEdit(options: Options) { |
|
|
|
|
const { graph, definition } = options |
|
|
|
|
const { addNode, setNodeName, setNodeEdge } = useCellUpdate({ graph }) |
|
|
|
|
const taskDefinitions = ref<NodeData[]>( |
|
|
|
|
definition.value?.taskDefinitionList || [] |
|
|
|
|
) |
|
|
|
|
const { addNode, removeNode, getSources, setNodeName, setNodeEdge } = |
|
|
|
|
useCellUpdate({ |
|
|
|
|
graph |
|
|
|
|
}) |
|
|
|
|
const processDefinition = ref( |
|
|
|
|
definition?.value || { |
|
|
|
|
processDefinition: {}, |
|
|
|
|
processTaskRelationList: [], |
|
|
|
|
taskDefinitionList: [] |
|
|
|
|
} |
|
|
|
|
) as Ref<EditWorkflowDefinition> |
|
|
|
|
|
|
|
|
|
const currTask = ref<NodeData>({ |
|
|
|
|
taskType: 'SHELL', |
|
|
|
|
code: 0, |
|
|
|
@ -52,7 +65,7 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
*/ |
|
|
|
|
function appendTask(code: number, type: TaskType, coordinate: Coordinate) { |
|
|
|
|
addNode(code + '', type, '', 'YES', coordinate) |
|
|
|
|
taskDefinitions.value.push({ |
|
|
|
|
processDefinition.value.taskDefinitionList.push({ |
|
|
|
|
code, |
|
|
|
|
taskType: type, |
|
|
|
|
name: '' |
|
|
|
@ -72,7 +85,9 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
coordinate: Coordinate |
|
|
|
|
) { |
|
|
|
|
addNode(code + '', type, name, flag, coordinate) |
|
|
|
|
const definition = taskDefinitions.value.find((t) => t.code === targetCode) |
|
|
|
|
const definition = processDefinition.value.taskDefinitionList.find( |
|
|
|
|
(t) => t.code === targetCode |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const newDefinition = { |
|
|
|
|
...definition, |
|
|
|
@ -80,7 +95,7 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
name |
|
|
|
|
} as NodeData |
|
|
|
|
|
|
|
|
|
taskDefinitions.value.push(newDefinition) |
|
|
|
|
processDefinition.value.taskDefinitionList.push(newDefinition) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -88,9 +103,10 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
* @param {number} code |
|
|
|
|
*/ |
|
|
|
|
function removeTasks(codes: number[]) { |
|
|
|
|
taskDefinitions.value = taskDefinitions.value.filter( |
|
|
|
|
(task) => !codes.includes(task.code) |
|
|
|
|
) |
|
|
|
|
processDefinition.value.taskDefinitionList = |
|
|
|
|
processDefinition.value.taskDefinitionList.filter( |
|
|
|
|
(task) => !codes.includes(task.code) |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function openTaskModal(task: NodeData) { |
|
|
|
@ -103,10 +119,13 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
* @param {number} code |
|
|
|
|
*/ |
|
|
|
|
function editTask(code: number) { |
|
|
|
|
const definition = taskDefinitions.value.find((t) => t.code === code) |
|
|
|
|
const definition = processDefinition.value.taskDefinitionList.find( |
|
|
|
|
(t) => t.code === code |
|
|
|
|
) |
|
|
|
|
if (definition) { |
|
|
|
|
currTask.value = definition |
|
|
|
|
} |
|
|
|
|
updatePreTasks(getSources(String(code)), code) |
|
|
|
|
taskModalVisible.value = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -118,19 +137,22 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
function taskConfirm({ data }: any) { |
|
|
|
|
const taskDef = formatParams(data).taskDefinitionJsonObj as NodeData |
|
|
|
|
// override target config
|
|
|
|
|
taskDefinitions.value = taskDefinitions.value.map((task) => { |
|
|
|
|
if (task.code === currTask.value?.code) { |
|
|
|
|
setNodeName(task.code + '', taskDef.name) |
|
|
|
|
updatePreTasks(data.preTasks, task.code) |
|
|
|
|
return { |
|
|
|
|
...taskDef, |
|
|
|
|
version: task.version, |
|
|
|
|
code: task.code, |
|
|
|
|
taskType: currTask.value.taskType |
|
|
|
|
processDefinition.value.taskDefinitionList = |
|
|
|
|
processDefinition.value.taskDefinitionList.map((task) => { |
|
|
|
|
if (task.code === currTask.value?.code) { |
|
|
|
|
setNodeName(task.code + '', taskDef.name) |
|
|
|
|
|
|
|
|
|
setNodeEdge(String(task.code), data.preTasks) |
|
|
|
|
updatePreTasks(data.preTasks, task.code) |
|
|
|
|
return { |
|
|
|
|
...taskDef, |
|
|
|
|
version: task.version, |
|
|
|
|
code: task.code, |
|
|
|
|
taskType: currTask.value.taskType |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return task |
|
|
|
|
}) |
|
|
|
|
return task |
|
|
|
|
}) |
|
|
|
|
taskModalVisible.value = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -139,19 +161,25 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
*/ |
|
|
|
|
function taskCancel() { |
|
|
|
|
taskModalVisible.value = false |
|
|
|
|
if (!currTask.value.name) { |
|
|
|
|
removeNode(String(currTask.value.code)) |
|
|
|
|
remove( |
|
|
|
|
processDefinition.value.taskDefinitionList, |
|
|
|
|
(task) => task.code === currTask.value.code |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function updatePreTasks(preTasks: number[], code: number) { |
|
|
|
|
if (!preTasks?.length) return |
|
|
|
|
setNodeEdge(String(code), preTasks) |
|
|
|
|
if (definition.value?.processTaskRelationList?.length) { |
|
|
|
|
if (processDefinition.value?.processTaskRelationList?.length) { |
|
|
|
|
remove( |
|
|
|
|
definition.value.processTaskRelationList, |
|
|
|
|
processDefinition.value.processTaskRelationList, |
|
|
|
|
(process) => process.postTaskCode === code |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
if (!preTasks?.length) return |
|
|
|
|
preTasks.forEach((task) => { |
|
|
|
|
definition.value?.processTaskRelationList.push({ |
|
|
|
|
processDefinition.value?.processTaskRelationList.push({ |
|
|
|
|
postTaskCode: code, |
|
|
|
|
preTaskCode: task, |
|
|
|
|
name: '', |
|
|
|
@ -173,18 +201,18 @@ export function useTaskEdit(options: Options) {
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
watch(definition, () => { |
|
|
|
|
taskDefinitions.value = definition.value?.taskDefinitionList || [] |
|
|
|
|
if (definition.value) processDefinition.value = definition.value |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
currTask, |
|
|
|
|
taskModalVisible, |
|
|
|
|
processDefinition, |
|
|
|
|
taskConfirm, |
|
|
|
|
taskCancel, |
|
|
|
|
appendTask, |
|
|
|
|
editTask, |
|
|
|
|
copyTask, |
|
|
|
|
taskDefinitions, |
|
|
|
|
removeTasks |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|