hookehuyr

新增流程版本复制功能

......@@ -324,7 +324,7 @@
<span v-if="item.code === state.current_enable_version" style="background: #edf9f1; border-color: #46c26f; color: #46c26f; font-size: 10px; padding: 0 5px; border-radius: 3px; margin-left: 8px;">启用中</span>
<!-- <span @click="showEditFlowVersion(item.id, item.code, item.note)" style="margin-left: 10px;">
<i class="el-icon-edit-outline"></i>
</span> -->
-->
</el-dropdown-item>
<el-dropdown-item @click.native="addFlowVersion" style="justify-content: center;">
<i class="el-icon-circle-plus-outline"></i>新增流程
......@@ -364,6 +364,17 @@
</el-popconfirm>
<el-popconfirm
v-if="state.current_enable_version !== state.versionForm.code"
title="是否确认复制该版本流程?"
width="220px"
confirm-button-text="确认"
cancel-button-text="取消"
@confirm="copyFLowVersion">
<template #reference>
<el-button type="warning">复制流程</el-button>
</template>
</el-popconfirm>
<el-popconfirm
v-if="state.current_enable_version !== state.versionForm.code"
title="是否确认删除该版本流程?"
width="220px"
confirm-button-text="确认"
......@@ -768,6 +779,70 @@ export default {
}
}
const copyFLowVersion = async () => { // 复制版本流程
let { nodes, edges } = editor.editorState.graph.save();
// 使用时需要把自定义节点的类型带过去 activity/control
nodes.forEach((node: { [x: string]: string; shape: string }) => {
if (node.shape === 'control') {
node['control'] = node['control']
}
});
nodes = nodes.map(
({ data, id, label, shape, x, y, text, desc, img, control }) => ({
data,
id,
label,
shape,
x,
y,
text,
desc,
img,
control,
}),
);
edges = edges.map(({ shape, source, sourceAnchor, target, targetAnchor }) => ({
shape,
source,
sourceAnchor,
target,
targetAnchor,
}));
// 检查路径有效性
const paths = [];
findPathsToEndNode(edges, 'start-node', [], paths);
state.dialogVersionFormVisible = false; // 关闭弹框
if (paths.length) {
const { code, data } = await saveFlowAPI({ form_id: +form_id, flow_id: '', data: JSON.stringify({ nodes, edges }) });
if (code) {
state.reloadLoading = true; // 打开 loading
ElMessage({
type: 'success',
message: '复制成功',
});
updateFlowId(data); // 更新缓存 flow_id
getFlowData(data); // 更新流程图数据
const flow_version = await flowVersionAPI({ form_id });
if (flow_version.code) {
state.version_list = flow_version.data; // 更新版本列表
state.version_list.forEach((ele) => {
if (ele.id === +data) {
state.select_flow_version = ele.code; // 选中新增的版本
}
});
}
}
} else {
ElNotification.error('缺少一条从开始节点到结束节点的完整流程!');
}
}
/**
* 编辑版本
*/
......@@ -1569,6 +1644,7 @@ export default {
showEditFlowVersion,
addFlowVersion,
setFLowVersionEnable,
copyFLowVersion,
editFlowVersion,
deleteFlowVersion,
saveFlowVersionNote,
......