perf: 增加任务复制功能

pull/68/head
xiaojunnuo 2024-05-28 17:07:20 +08:00
parent 83d1bda56a
commit 39ad7597fa
3 changed files with 68 additions and 21 deletions

View File

@ -68,6 +68,7 @@
{ value: 1, label: '成功后跳过' }
]
},
helper:'该任务运行成功一次之后下次运行是否跳过,证书申请任务务必选择正常运行',
rules: [{ required: true, message: '此项必填' }]
}"
:get-context-fn="blankFn"
@ -89,9 +90,10 @@ import { message, Modal } from "ant-design-vue";
import { computed, inject, Ref, ref } from "vue";
import _ from "lodash-es";
import { nanoid } from "nanoid";
import { compute } from "@fast-crud/fast-crud";
import {CopyOutlined} from "@ant-design/icons-vue";
export default {
name: "PiStepForm",
components:{CopyOutlined},
props: {
editMode: {
type: Boolean,
@ -171,7 +173,7 @@ export default {
stepDrawerShow();
};
const stepAdd = (emit: any) => {
const stepAdd = (emit: any,stepDef:any) => {
mode.value = "add";
const step: any = {
id: nanoid(),
@ -181,6 +183,7 @@ export default {
input: {},
status: null
};
_.merge(step,stepDef)
stepOpen(step, emit);
};
@ -250,6 +253,14 @@ export default {
});
};
const stepCopy = () => {
const step = _.cloneDeep(currentStep.value);
step.id = nanoid();
step.title = `${step.title}-copy`;
callback.value("copy", step);
stepDrawerClose();
};
const blankFn = () => {
return {};
};
@ -270,7 +281,8 @@ export default {
stepSave,
stepDelete,
rules,
blankFn
blankFn,
stepCopy
};
}

View File

@ -35,6 +35,7 @@
<a-list-item>
<template #actions>
<a key="edit" @click="stepEdit(currentTask, item, index)">编辑</a>
<a key="edit" @click="stepCopy(currentTask, item, index)">复制</a>
<a key="remove" @click="stepDelete(currentTask, index)">删除</a>
</template>
<a-list-item-meta>
@ -70,10 +71,11 @@ import _ from "lodash-es";
import { nanoid } from "nanoid";
import PiStepForm from "../step-form/index.vue";
import { message, Modal } from "ant-design-vue";
import {CopyOutlined} from "@ant-design/icons-vue";
export default {
name: "PiTaskForm",
components: { PiStepForm },
components: {CopyOutlined, PiStepForm },
props: {
editMode: {
type: Boolean,
@ -86,7 +88,7 @@ export default {
const stepFormRef: Ref<any> = ref(null);
const currentStepIndex = ref(0);
provide("currentStepIndex", currentStepIndex);
const stepAdd = (task: any) => {
const stepAdd = (task: any,stepDef:any) => {
currentStepIndex.value = task.steps.length;
stepFormRef.value.stepAdd((type: any, value: any) => {
if (type === "save") {
@ -95,7 +97,14 @@ export default {
task.title = value.title;
}
}
});
},stepDef);
};
const stepCopy = (task: any, step: any, stepIndex: any) => {
step = _.cloneDeep(step)
step.id = nanoid()
step.title = step.title +"_copy"
stepAdd(task,step)
};
const stepEdit = (task: any, step: any, stepIndex: any) => {
currentStepIndex.value = stepIndex;
@ -126,7 +135,7 @@ export default {
});
};
return { stepAdd, stepEdit, stepDelete, stepFormRef };
return { stepAdd, stepEdit,stepCopy, stepDelete, stepFormRef };
}
/**
@ -168,9 +177,10 @@ export default {
taskDrawerShow();
};
const taskAdd = (emit: any) => {
const taskAdd = (emit: any,taskMerge:any) => {
mode.value = "add";
const task: any = { id: nanoid(), title: "新任务", steps: [], status: null };
const blankTask = { id: nanoid(), title: "新任务", steps: [], status: null }
const task: any = _.merge(blankTask,taskMerge) ;
taskOpen(task, emit);
};
@ -224,7 +234,7 @@ export default {
taskSave,
taskDelete,
rules,
blankFn
blankFn,
};
}
return {

View File

@ -81,10 +81,11 @@
<fs-icon v-if="editMode" class="add-stage-btn" title="添加新阶段" icon="ion:add-circle" @click="stageAdd(index)"></fs-icon>
</div>
<div class="task">
<a-button shape="round" @click="taskEdit(stage, index, task, taskIndex)">
{{ task.title }}
<pi-status-show :status="task.status?.result"></pi-status-show>
</a-button>
<a-button shape="round" @click="taskEdit(stage, index, task, taskIndex)">
{{ task.title }}
<pi-status-show :status="task.status?.result"></pi-status-show>
</a-button>
<fs-icon class="copy" v-if="editMode" title="复制" icon="ion:copy-outline" @click="taskCopy(stage, index, task)"></fs-icon>
</div>
</div>
<div v-if="editMode" class="task-container is-add">
@ -92,10 +93,13 @@
<div class="flow-line"></div>
</div>
<div class="task">
<a-button type="dashed" shape="round" @click="taskAdd(stage, index)">
<fs-icon class="font-20" icon="ion:add-circle-outline"></fs-icon>
并行任务
</a-button>
<a-tooltip>
<a-button type="dashed" shape="round" @click="taskAdd(stage, index)">
<fs-icon class="font-20" icon="ion:add-circle-outline"></fs-icon>
并行任务
</a-button>
</a-tooltip>
</div>
</div>
</div>
@ -369,7 +373,7 @@ export default defineComponent({
const taskView = useTaskView();
const taskAdd = (stage: any, stageIndex: number, onSuccess?: any) => {
const taskAdd = (stage: any, stageIndex: number, onSuccess?: any,taskDef?:any) => {
currentStageIndex.value = stageIndex;
currentTaskIndex.value = stage.tasks.length;
taskFormRef.value.taskAdd((type: any, value: any) => {
@ -379,8 +383,19 @@ export default defineComponent({
onSuccess();
}
}
});
},taskDef);
};
const taskCopy = (stage: any, stageIndex: number, task: any ) => {
task = _.cloneDeep(task)
task.id = nanoid()
task.title= task.title+"_copy"
for (const step of task.steps) {
step.id = nanoid()
}
taskAdd(stage,stageIndex,null,task)
};
const taskEdit = (stage: any, stageIndex: number, task: any, taskIndex: number, onSuccess?: any) => {
currentStageIndex.value = stageIndex;
currentTaskIndex.value = taskIndex;
@ -408,7 +423,7 @@ export default defineComponent({
}
};
return { taskAdd, taskEdit, taskFormRef, ...taskView };
return { taskAdd, taskEdit, taskCopy,taskFormRef, ...taskView };
}
function useStage(useTaskRet: any) {
@ -745,6 +760,16 @@ export default defineComponent({
height: 100%;
z-index: 2;
.copy{
position: absolute;
right:60px;
top:18px;
cursor: pointer;
&:hover {
color: #1890ff;
}
}
.ant-btn {
width: 200px;
}