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

View File

@ -35,6 +35,7 @@
<a-list-item> <a-list-item>
<template #actions> <template #actions>
<a key="edit" @click="stepEdit(currentTask, item, index)">编辑</a> <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> <a key="remove" @click="stepDelete(currentTask, index)">删除</a>
</template> </template>
<a-list-item-meta> <a-list-item-meta>
@ -70,10 +71,11 @@ import _ from "lodash-es";
import { nanoid } from "nanoid"; import { nanoid } from "nanoid";
import PiStepForm from "../step-form/index.vue"; import PiStepForm from "../step-form/index.vue";
import { message, Modal } from "ant-design-vue"; import { message, Modal } from "ant-design-vue";
import {CopyOutlined} from "@ant-design/icons-vue";
export default { export default {
name: "PiTaskForm", name: "PiTaskForm",
components: { PiStepForm }, components: {CopyOutlined, PiStepForm },
props: { props: {
editMode: { editMode: {
type: Boolean, type: Boolean,
@ -86,7 +88,7 @@ export default {
const stepFormRef: Ref<any> = ref(null); const stepFormRef: Ref<any> = ref(null);
const currentStepIndex = ref(0); const currentStepIndex = ref(0);
provide("currentStepIndex", currentStepIndex); provide("currentStepIndex", currentStepIndex);
const stepAdd = (task: any) => { const stepAdd = (task: any,stepDef:any) => {
currentStepIndex.value = task.steps.length; currentStepIndex.value = task.steps.length;
stepFormRef.value.stepAdd((type: any, value: any) => { stepFormRef.value.stepAdd((type: any, value: any) => {
if (type === "save") { if (type === "save") {
@ -95,7 +97,14 @@ export default {
task.title = value.title; 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) => { const stepEdit = (task: any, step: any, stepIndex: any) => {
currentStepIndex.value = stepIndex; 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(); taskDrawerShow();
}; };
const taskAdd = (emit: any) => { const taskAdd = (emit: any,taskMerge:any) => {
mode.value = "add"; 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); taskOpen(task, emit);
}; };
@ -224,7 +234,7 @@ export default {
taskSave, taskSave,
taskDelete, taskDelete,
rules, rules,
blankFn blankFn,
}; };
} }
return { 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> <fs-icon v-if="editMode" class="add-stage-btn" title="添加新阶段" icon="ion:add-circle" @click="stageAdd(index)"></fs-icon>
</div> </div>
<div class="task"> <div class="task">
<a-button shape="round" @click="taskEdit(stage, index, task, taskIndex)"> <a-button shape="round" @click="taskEdit(stage, index, task, taskIndex)">
{{ task.title }} {{ task.title }}
<pi-status-show :status="task.status?.result"></pi-status-show> <pi-status-show :status="task.status?.result"></pi-status-show>
</a-button> </a-button>
<fs-icon class="copy" v-if="editMode" title="复制" icon="ion:copy-outline" @click="taskCopy(stage, index, task)"></fs-icon>
</div> </div>
</div> </div>
<div v-if="editMode" class="task-container is-add"> <div v-if="editMode" class="task-container is-add">
@ -92,10 +93,13 @@
<div class="flow-line"></div> <div class="flow-line"></div>
</div> </div>
<div class="task"> <div class="task">
<a-button type="dashed" shape="round" @click="taskAdd(stage, index)"> <a-tooltip>
<fs-icon class="font-20" icon="ion:add-circle-outline"></fs-icon> <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-button>
</a-tooltip>
</div> </div>
</div> </div>
</div> </div>
@ -369,7 +373,7 @@ export default defineComponent({
const taskView = useTaskView(); const taskView = useTaskView();
const taskAdd = (stage: any, stageIndex: number, onSuccess?: any) => { const taskAdd = (stage: any, stageIndex: number, onSuccess?: any,taskDef?:any) => {
currentStageIndex.value = stageIndex; currentStageIndex.value = stageIndex;
currentTaskIndex.value = stage.tasks.length; currentTaskIndex.value = stage.tasks.length;
taskFormRef.value.taskAdd((type: any, value: any) => { taskFormRef.value.taskAdd((type: any, value: any) => {
@ -379,8 +383,19 @@ export default defineComponent({
onSuccess(); 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) => { const taskEdit = (stage: any, stageIndex: number, task: any, taskIndex: number, onSuccess?: any) => {
currentStageIndex.value = stageIndex; currentStageIndex.value = stageIndex;
currentTaskIndex.value = taskIndex; 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) { function useStage(useTaskRet: any) {
@ -745,6 +760,16 @@ export default defineComponent({
height: 100%; height: 100%;
z-index: 2; z-index: 2;
.copy{
position: absolute;
right:60px;
top:18px;
cursor: pointer;
&:hover {
color: #1890ff;
}
}
.ant-btn { .ant-btn {
width: 200px; width: 200px;
} }