feat: [bpm][antd] bpmn 设计器子流程调用问题修复

This commit is contained in:
jason
2025-12-09 23:14:35 +08:00
parent 28e4305916
commit 43ed7aeefb

View File

@@ -1,8 +1,8 @@
<script lang="ts" setup> <script lang="ts" setup>
import { h, inject, nextTick, ref, toRaw, watch } from 'vue'; import { inject, nextTick, onMounted, ref, toRaw, watch } from 'vue';
import { alert } from '@vben/common-ui'; import { confirm, useVbenModal } from '@vben/common-ui';
import { PlusOutlined } from '@vben/icons'; import { IconifyIcon } from '@vben/icons';
import { import {
Button, Button,
@@ -10,12 +10,14 @@ import {
Form, Form,
FormItem, FormItem,
Input, Input,
Modal, Select,
SelectOption,
Switch, Switch,
Table,
TableColumn,
} from 'ant-design-vue'; } from 'ant-design-vue';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getModelList } from '#/api/bpm/model';
interface FormData { interface FormData {
processInstanceName: string; processInstanceName: string;
calledElement: string; calledElement: string;
@@ -44,8 +46,7 @@ const inVariableList = ref<any[]>([]);
const outVariableList = ref<any[]>([]); const outVariableList = ref<any[]>([]);
const variableType = ref<string>(); // 参数类型 const variableType = ref<string>(); // 参数类型
const editingVariableIndex = ref<number>(-1); // 编辑参数下标 const editingVariableIndex = ref<number>(-1); // 编辑参数下标
const variableDialogVisible = ref<boolean>(false); const varialbeFormRef = ref();
const varialbeFormRef = ref<any>();
const varialbeFormData = ref<{ const varialbeFormData = ref<{
source: string; source: string;
target: string; target: string;
@@ -57,10 +58,10 @@ const varialbeFormData = ref<{
const bpmnInstances = () => (window as any)?.bpmnInstances; const bpmnInstances = () => (window as any)?.bpmnInstances;
const bpmnElement = ref<any>(); const bpmnElement = ref<any>();
const otherExtensionList = ref<any[]>([]); const otherExtensionList = ref<any[]>([]);
const childProcessOptions = ref<{ key: string; name: string }[]>([]);
const initCallActivity = () => { const initCallActivity = () => {
bpmnElement.value = bpmnInstances().bpmnElement; bpmnElement.value = bpmnInstances().bpmnElement;
// console.log(bpmnElement.value.businessObject, 'callActivity');
// 初始化所有配置项 // 初始化所有配置项
Object.keys(formData.value).forEach((key: string) => { Object.keys(formData.value).forEach((key: string) => {
@@ -85,11 +86,6 @@ const initCallActivity = () => {
} }
}, },
); );
// 默认添加
// bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
// calledElementType: 'key'
// })
}; };
const updateCallActivityAttr = (attr: keyof FormData) => { const updateCallActivityAttr = (attr: keyof FormData) => {
@@ -98,16 +94,26 @@ const updateCallActivityAttr = (attr: keyof FormData) => {
}); });
}; };
const [VariableModal, variableModalApi] = useVbenModal({
title: '参数配置',
onConfirm: () => {
saveVariable();
},
});
const openVariableForm = (type: string, data: any, index: number) => { const openVariableForm = (type: string, data: any, index: number) => {
editingVariableIndex.value = index; editingVariableIndex.value = index;
variableType.value = type; variableType.value = type;
varialbeFormData.value = index === -1 ? {} : { ...data }; varialbeFormData.value = index === -1 ? {} : { ...data };
variableDialogVisible.value = true; variableModalApi.open();
}; };
const removeVariable = async (type: string, index: number) => { const removeVariable = async (type: string, index: number) => {
try { try {
await alert('是否确认删除?'); await confirm({
title: '提示',
content: '是否确认删除?',
});
if (type === 'in') { if (type === 'in') {
inVariableList.value.splice(index, 1); inVariableList.value.splice(index, 1);
} }
@@ -115,10 +121,19 @@ const removeVariable = async (type: string, index: number) => {
outVariableList.value.splice(index, 1); outVariableList.value.splice(index, 1);
} }
updateElementExtensions(); updateElementExtensions();
} catch {} } catch (error: any) {
console.error(`[removeVariable error ]: ${error.message || error}`);
}
}; };
const saveVariable = () => { const saveVariable = async () => {
try {
await varialbeFormRef.value?.validate();
} catch {
// 验证失败直接返回
return;
}
if (editingVariableIndex.value === -1) { if (editingVariableIndex.value === -1) {
if (variableType.value === 'in') { if (variableType.value === 'in') {
inVariableList.value.push( inVariableList.value.push(
@@ -149,7 +164,7 @@ const saveVariable = () => {
varialbeFormData.value.target; varialbeFormData.value.target;
} }
} }
variableDialogVisible.value = false; variableModalApi.close();
}; };
const updateElementExtensions = () => { const updateElementExtensions = () => {
@@ -176,28 +191,93 @@ watch(
}, },
{ immediate: true }, { immediate: true },
); );
const gridOptions = {
columns: [
{ title: '源', field: 'source', minWidth: 100 },
{ title: '目标', field: 'target', minWidth: 100 },
{
title: '操作',
width: 130,
slots: { default: 'action' },
fixed: 'right' as const,
},
],
border: true,
showOverflow: true,
height: 'auto',
toolbarConfig: { enabled: false },
pagerConfig: { enabled: false },
};
const [InVariableGrid, inVariableGridApi] = useVbenVxeGrid({
gridOptions,
});
const [OutVariableGrid, outVariableGridApi] = useVbenVxeGrid({
gridOptions,
});
// 使用浅层监听,避免无限循环
watch(
() => [...inVariableList.value],
(val) => {
inVariableGridApi.setGridOptions({ data: val });
},
);
watch(
() => [...outVariableList.value],
(val) => {
outVariableGridApi.setGridOptions({ data: val });
},
);
/** 选择子流程, 更新 bpmn callActivity calledElement 和 processInstanceName 属性 */
const handleChildProcessChange = (key: any) => {
if (!key) return;
const selected = childProcessOptions.value.find((item) => item.key === key);
if (selected) {
formData.value.calledElement = selected.key;
formData.value.processInstanceName = selected.name;
updateCallActivityAttr('calledElement');
updateCallActivityAttr('processInstanceName');
}
};
onMounted(async () => {
try {
// 获取流程模型列表
const list = await getModelList(undefined);
childProcessOptions.value = list.map((item) => ({
key: item.key,
name: item.name,
}));
} catch (error) {
console.error('获取子流程列表失败', error);
}
});
</script> </script>
<template> <template>
<div> <div class="-mx-2">
<Form> <Form :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
<FormItem label="实例名称"> <FormItem label="被调用子流程">
<Input <Select
v-model:value="formData.processInstanceName"
allow-clear
placeholder="请输入实例名称"
@change="updateCallActivityAttr('processInstanceName')"
/>
</FormItem>
<!-- TODO 需要可选择已存在的流程 -->
<FormItem label="被调用流程">
<Input
v-model:value="formData.calledElement" v-model:value="formData.calledElement"
placeholder="请选择子流程"
allow-clear allow-clear
placeholder="请输入被调用流程" @change="handleChildProcessChange"
@change="updateCallActivityAttr('calledElement')" >
/> <SelectOption
v-for="item in childProcessOptions"
:key="item.key"
:value="item.key"
:label="item.name"
>
{{ item.name }}
</SelectOption>
</Select>
</FormItem> </FormItem>
<FormItem label="继承变量"> <FormItem label="继承变量">
@@ -223,134 +303,115 @@ watch(
/> />
</FormItem> </FormItem>
<Divider /> <div
<div> class="mb-1 mt-2 flex items-center justify-between border-t border-gray-200 pt-2"
<div class="mb-10px flex"> >
<span>输入参数</span> <span class="flex items-center text-sm font-medium"> 输入参数 </span>
<Button <Button
class="ml-auto" class="flex items-center"
type="primary" size="small"
:icon="h(PlusOutlined)" type="link"
title="添加参数" @click="openVariableForm('in', null, -1)"
size="small"
@click="openVariableForm('in', null, -1)"
/>
</div>
<Table
:data-source="inVariableList"
:scroll="{ y: 240 }"
bordered
:pagination="false"
> >
<TableColumn <template #icon>
title="源" <IconifyIcon icon="ep:plus" />
data-index="source" </template>
:min-width="100" 添加参数
:ellipsis="true" </Button>
/>
<TableColumn
title="目标"
data-index="target"
:min-width="100"
:ellipsis="true"
/>
<TableColumn title="操作" :width="110">
<template #default="{ record, index }">
<Button
type="link"
@click="openVariableForm('in', record, index)"
size="small"
>
编辑
</Button>
<Divider type="vertical" />
<Button
type="link"
size="small"
danger
@click="removeVariable('in', index)"
>
移除
</Button>
</template>
</TableColumn>
</Table>
</div> </div>
<InVariableGrid class="-mx-2 mb-4">
<template #action="{ row, rowIndex }">
<Button
size="small"
type="link"
@click="openVariableForm('in', row, rowIndex)"
>
编辑
</Button>
<Divider type="vertical" />
<Button
size="small"
type="link"
danger
@click="removeVariable('in', rowIndex)"
>
移除
</Button>
</template>
</InVariableGrid>
<Divider /> <div
<div> class="mb-1 mt-2 flex items-center justify-between border-t border-gray-200 pt-2"
<div class="mb-10px flex"> >
<span>输出参数</span> <span class="flex items-center text-sm font-medium"> 输出参数 </span>
<Button <Button
class="ml-auto" class="flex items-center"
type="primary" size="small"
:icon="h(PlusOutlined)" type="link"
title="添加参数" @click="openVariableForm('out', null, -1)"
size="small"
@click="openVariableForm('out', null, -1)"
/>
</div>
<Table
:data-source="outVariableList"
:scroll="{ y: 240 }"
bordered
:pagination="false"
> >
<TableColumn <template #icon>
title="源" <IconifyIcon icon="lucide:plus" class="size-4" />
data-index="source" </template>
:min-width="100" 添加参数
:ellipsis="true" </Button>
/>
<TableColumn
title="目标"
data-index="target"
:min-width="100"
:ellipsis="true"
/>
<TableColumn title="操作" :width="110">
<template #default="{ record, index }">
<Button
type="link"
@click="openVariableForm('out', record, index)"
size="small"
>
编辑
</Button>
<Divider type="vertical" />
<Button
type="link"
size="small"
danger
@click="removeVariable('out', index)"
>
移除
</Button>
</template>
</TableColumn>
</Table>
</div> </div>
<OutVariableGrid class="-mx-2">
<template #action="{ row, rowIndex }">
<Button
size="small"
type="link"
@click="openVariableForm('out', row, rowIndex)"
>
编辑
</Button>
<Divider type="vertical" />
<Button
size="small"
type="link"
danger
@click="removeVariable('out', rowIndex)"
>
移除
</Button>
</template>
</OutVariableGrid>
</Form> </Form>
<!-- 添加或修改参数 --> <VariableModal>
<Modal <Form
v-model:open="variableDialogVisible" :model="varialbeFormData"
title="参数配置" ref="varialbeFormRef"
:width="600" :label-col="{ span: 4 }"
:destroy-on-close="true" :wrapper-col="{ span: 18 }"
@ok="saveVariable" >
@cancel="variableDialogVisible = false" <FormItem
> label="源"
<Form :model="varialbeFormData" ref="varialbeFormRef"> name="source"
<FormItem label="源:" name="source"> :rules="[
{
required: true,
message: '源不能为空',
trigger: ['blur', 'change'],
},
]"
>
<Input v-model:value="varialbeFormData.source" allow-clear /> <Input v-model:value="varialbeFormData.source" allow-clear />
</FormItem> </FormItem>
<FormItem label="目标:" name="target"> <FormItem
label="目标"
name="target"
:rules="[
{
required: true,
message: '目标不能为空',
trigger: ['blur', 'change'],
},
]"
>
<Input v-model:value="varialbeFormData.target" allow-clear /> <Input v-model:value="varialbeFormData.target" allow-clear />
</FormItem> </FormItem>
</Form> </Form>
</Modal> </VariableModal>
</div> </div>
</template> </template>
<style lang="scss" scoped></style>