fix: [bpm][antd] bpm 设计器添加属性问题修复
This commit is contained in:
@@ -1,19 +1,13 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { inject, nextTick, ref, toRaw, watch } from 'vue';
|
import { inject, nextTick, ref, toRaw, watch } from 'vue';
|
||||||
|
|
||||||
|
import { confirm, useVbenModal } from '@vben/common-ui';
|
||||||
import { IconifyIcon } from '@vben/icons';
|
import { IconifyIcon } from '@vben/icons';
|
||||||
import { cloneDeep } from '@vben/utils';
|
import { cloneDeep } from '@vben/utils';
|
||||||
|
|
||||||
import {
|
import { Button, Divider, Form, FormItem, Input } from 'ant-design-vue';
|
||||||
Button,
|
|
||||||
Divider,
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
Form,
|
|
||||||
FormItem,
|
|
||||||
Input,
|
|
||||||
Modal,
|
|
||||||
Table,
|
|
||||||
TableColumn,
|
|
||||||
} from 'ant-design-vue';
|
|
||||||
|
|
||||||
defineOptions({ name: 'ElementProperties' });
|
defineOptions({ name: 'ElementProperties' });
|
||||||
|
|
||||||
@@ -29,12 +23,10 @@ const props = defineProps({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const prefix = inject('prefix');
|
const prefix = inject('prefix');
|
||||||
// const width = inject('width')
|
|
||||||
|
|
||||||
const elementPropertyList = ref<Array<{ name: string; value: string }>>([]);
|
const elementPropertyList = ref<Array<{ name: string; value: string }>>([]);
|
||||||
const propertyForm = ref<{ name?: string; value?: string }>({});
|
const propertyForm = ref<{ name?: string; value?: string }>({});
|
||||||
const editingPropertyIndex = ref(-1);
|
const editingPropertyIndex = ref(-1);
|
||||||
const propertyFormModelVisible = ref(false);
|
|
||||||
const bpmnElement = ref<any>();
|
const bpmnElement = ref<any>();
|
||||||
const otherExtensionList = ref<any[]>([]);
|
const otherExtensionList = ref<any[]>([]);
|
||||||
const bpmnElementProperties = ref<any[]>([]);
|
const bpmnElementProperties = ref<any[]>([]);
|
||||||
@@ -44,9 +36,8 @@ const bpmnInstances = () => (window as any)?.bpmnInstances;
|
|||||||
|
|
||||||
const resetAttributesList = () => {
|
const resetAttributesList = () => {
|
||||||
bpmnElement.value = bpmnInstances().bpmnElement;
|
bpmnElement.value = bpmnInstances().bpmnElement;
|
||||||
otherExtensionList.value = []; // 其他扩展配置
|
otherExtensionList.value = [];
|
||||||
bpmnElementProperties.value =
|
bpmnElementProperties.value =
|
||||||
// bpmnElement.value.businessObject?.extensionElements?.filter((ex) => {
|
|
||||||
bpmnElement.value.businessObject?.extensionElements?.values?.filter(
|
bpmnElement.value.businessObject?.extensionElements?.values?.filter(
|
||||||
(ex: any) => {
|
(ex: any) => {
|
||||||
if (ex.$type !== `${prefix}:Properties`) {
|
if (ex.$type !== `${prefix}:Properties`) {
|
||||||
@@ -56,57 +47,41 @@ const resetAttributesList = () => {
|
|||||||
},
|
},
|
||||||
) ?? [];
|
) ?? [];
|
||||||
|
|
||||||
// 保存所有的 扩展属性字段
|
|
||||||
bpmnElementPropertyList.value = bpmnElementProperties.value.flatMap(
|
bpmnElementPropertyList.value = bpmnElementProperties.value.flatMap(
|
||||||
(current: any) => current.values,
|
(current: any) => current.values,
|
||||||
);
|
);
|
||||||
// 复制 显示
|
|
||||||
elementPropertyList.value = cloneDeep(bpmnElementPropertyList.value ?? []);
|
elementPropertyList.value = cloneDeep(bpmnElementPropertyList.value ?? []);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openAttributesForm = (
|
|
||||||
attr: null | { name: string; value: string },
|
|
||||||
index: number,
|
|
||||||
) => {
|
|
||||||
editingPropertyIndex.value = index;
|
|
||||||
// @ts-ignore
|
|
||||||
propertyForm.value = index === -1 ? {} : cloneDeep(attr);
|
|
||||||
propertyFormModelVisible.value = true;
|
|
||||||
nextTick(() => {
|
|
||||||
if (attributeFormRef.value) attributeFormRef.value.clearValidate();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeAttributes = (
|
const removeAttributes = (
|
||||||
_attr: { name: string; value: string },
|
_attr: { name: string; value: string },
|
||||||
index: number,
|
index: number,
|
||||||
) => {
|
) => {
|
||||||
Modal.confirm({
|
confirm({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: '确认移除该属性吗?',
|
content: '确认移除该属性吗?',
|
||||||
okText: '确 认',
|
}).then(() => {
|
||||||
cancelText: '取 消',
|
elementPropertyList.value.splice(index, 1);
|
||||||
onOk() {
|
bpmnElementPropertyList.value.splice(index, 1);
|
||||||
elementPropertyList.value.splice(index, 1);
|
const propertiesObject = bpmnInstances().moddle.create(
|
||||||
bpmnElementPropertyList.value.splice(index, 1);
|
`${prefix}:Properties`,
|
||||||
// 新建一个属性字段的保存列表
|
{
|
||||||
const propertiesObject = bpmnInstances().moddle.create(
|
values: bpmnElementPropertyList.value,
|
||||||
`${prefix}:Properties`,
|
},
|
||||||
{
|
);
|
||||||
values: bpmnElementPropertyList.value,
|
updateElementExtensions(propertiesObject);
|
||||||
},
|
resetAttributesList();
|
||||||
);
|
|
||||||
updateElementExtensions(propertiesObject);
|
|
||||||
resetAttributesList();
|
|
||||||
},
|
|
||||||
onCancel() {
|
|
||||||
// console.info('操作取消');
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveAttribute = () => {
|
const saveAttribute = async () => {
|
||||||
// console.log(propertyForm.value, 'propertyForm.value');
|
try {
|
||||||
|
await attributeFormRef.value?.validate();
|
||||||
|
} catch {
|
||||||
|
// 校验未通过,直接返回
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { name, value } = propertyForm.value;
|
const { name, value } = propertyForm.value;
|
||||||
if (editingPropertyIndex.value === -1) {
|
if (editingPropertyIndex.value === -1) {
|
||||||
// 新建属性字段
|
// 新建属性字段
|
||||||
@@ -135,7 +110,7 @@ const saveAttribute = () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
propertyFormModelVisible.value = false;
|
fieldModalApi.close();
|
||||||
resetAttributesList();
|
resetAttributesList();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -148,11 +123,61 @@ const updateElementExtensions = (properties: any) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
|
gridOptions: {
|
||||||
|
columns: [
|
||||||
|
{ type: 'seq', width: 50, title: '序号' },
|
||||||
|
{ field: 'name', title: '属性名', minWidth: 120 },
|
||||||
|
{ field: 'value', title: '属性值', minWidth: 120 },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
width: 120,
|
||||||
|
slots: { default: 'action' },
|
||||||
|
fixed: 'right',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
border: true,
|
||||||
|
showOverflow: true,
|
||||||
|
height: 'auto',
|
||||||
|
toolbarConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
pagerConfig: {
|
||||||
|
enabled: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const [FieldModal, fieldModalApi] = useVbenModal({
|
||||||
|
title: '属性配置',
|
||||||
|
onConfirm: saveAttribute,
|
||||||
|
});
|
||||||
|
|
||||||
|
const openAttributesForm = (
|
||||||
|
attr: null | { name: string; value: string },
|
||||||
|
index: number,
|
||||||
|
) => {
|
||||||
|
editingPropertyIndex.value = index;
|
||||||
|
propertyForm.value = index === -1 ? {} : cloneDeep(attr || {});
|
||||||
|
fieldModalApi.open();
|
||||||
|
nextTick(() => {
|
||||||
|
if (attributeFormRef.value) attributeFormRef.value.clearValidate();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
elementPropertyList,
|
||||||
|
(val) => {
|
||||||
|
gridApi.setGridOptions({ data: val });
|
||||||
|
},
|
||||||
|
{ deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.id,
|
() => props.id,
|
||||||
(val) => {
|
(val) => {
|
||||||
if (val) {
|
if (val && val.length > 0) {
|
||||||
val && val.length > 0 && resetAttributesList();
|
resetAttributesList();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
@@ -160,38 +185,34 @@ watch(
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="panel-tab__content">
|
<div class="-mx-2">
|
||||||
<Table :data="elementPropertyList" size="small" bordered>
|
<Grid :data="elementPropertyList">
|
||||||
<TableColumn title="序号" width="50">
|
<template #action="{ row, rowIndex }">
|
||||||
<template #default="{ index }">
|
<Button
|
||||||
{{ index + 1 }}
|
size="small"
|
||||||
</template>
|
type="link"
|
||||||
</TableColumn>
|
@click="openAttributesForm(row, rowIndex)"
|
||||||
<TableColumn title="属性名" data-index="name" />
|
>
|
||||||
<TableColumn title="属性值" data-index="value" />
|
编辑
|
||||||
<TableColumn title="操作">
|
</Button>
|
||||||
<template #default="{ record, index }">
|
<Divider type="vertical" />
|
||||||
<Button
|
<Button
|
||||||
type="link"
|
size="small"
|
||||||
@click="openAttributesForm(record, index)"
|
type="link"
|
||||||
size="small"
|
danger
|
||||||
>
|
@click="removeAttributes(row, rowIndex)"
|
||||||
编辑
|
>
|
||||||
</Button>
|
移除
|
||||||
<Divider type="vertical" />
|
</Button>
|
||||||
<Button
|
</template>
|
||||||
type="link"
|
</Grid>
|
||||||
size="small"
|
<div class="mt-1 flex w-full items-center justify-center gap-2 px-2">
|
||||||
danger
|
<Button
|
||||||
@click="removeAttributes(record, index)"
|
class="flex flex-1 items-center justify-center"
|
||||||
>
|
type="primary"
|
||||||
移除
|
size="small"
|
||||||
</Button>
|
@click="openAttributesForm(null, -1)"
|
||||||
</template>
|
>
|
||||||
</TableColumn>
|
|
||||||
</Table>
|
|
||||||
<div class="element-drawer__button">
|
|
||||||
<Button type="primary" @click="openAttributesForm(null, -1)">
|
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<IconifyIcon icon="ep:plus" />
|
<IconifyIcon icon="ep:plus" />
|
||||||
</template>
|
</template>
|
||||||
@@ -199,24 +220,28 @@ watch(
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Modal
|
<FieldModal class="w-3/5">
|
||||||
v-model:open="propertyFormModelVisible"
|
<Form
|
||||||
title="属性配置"
|
:model="propertyForm"
|
||||||
:width="600"
|
ref="attributeFormRef"
|
||||||
:destroy-on-close="true"
|
:label-col="{ span: 5 }"
|
||||||
>
|
:wrapper-col="{ span: 17 }"
|
||||||
<Form :model="propertyForm" ref="attributeFormRef">
|
>
|
||||||
<FormItem label="属性名:" name="name">
|
<FormItem
|
||||||
|
label="属性名:"
|
||||||
|
name="name"
|
||||||
|
:rules="[{ required: true, message: '请输入属性名' }]"
|
||||||
|
>
|
||||||
<Input v-model:value="propertyForm.name" allow-clear />
|
<Input v-model:value="propertyForm.name" allow-clear />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem label="属性值:" name="value">
|
<FormItem
|
||||||
|
label="属性值:"
|
||||||
|
name="value"
|
||||||
|
:rules="[{ required: true, message: '请输入属性值' }]"
|
||||||
|
>
|
||||||
<Input v-model:value="propertyForm.value" allow-clear />
|
<Input v-model:value="propertyForm.value" allow-clear />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
</Form>
|
</Form>
|
||||||
<template #footer>
|
</FieldModal>
|
||||||
<Button @click="propertyFormModelVisible = false">取 消</Button>
|
|
||||||
<Button type="primary" @click="saveAttribute">确 定</Button>
|
|
||||||
</template>
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user