2024-01-21 15:35:43 +08:00
|
|
|
import showConfig from '@/components/BpmnDesign/assets/showConfig';
|
2024-01-21 23:53:04 +08:00
|
|
|
import { Moddle, Modeler, Modeling } from 'bpmn';
|
2024-01-21 15:35:43 +08:00
|
|
|
interface Options {
|
2024-01-21 23:53:04 +08:00
|
|
|
modeler: Modeler;
|
2024-01-21 15:35:43 +08:00
|
|
|
element: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (ops: Options) => {
|
|
|
|
const { modeler, element } = ops;
|
|
|
|
|
|
|
|
const elementType = computed(() => {
|
|
|
|
const bizObj = element.businessObject;
|
|
|
|
return bizObj.eventDefinitions ? bizObj.eventDefinitions[0].$type : bizObj.$type;
|
|
|
|
});
|
|
|
|
|
|
|
|
const config = computed(() => showConfig[elementType.value] || {});
|
|
|
|
|
|
|
|
const updateProperties = (properties: any) => {
|
2024-01-21 23:53:04 +08:00
|
|
|
const modeling = modeler.get<Modeling>('modeling');
|
2024-01-21 15:35:43 +08:00
|
|
|
modeling.updateProperties(element, properties);
|
|
|
|
};
|
|
|
|
|
2024-01-21 18:13:15 +08:00
|
|
|
const idChange = (newVal: string) => {
|
|
|
|
if (newVal) {
|
|
|
|
updateProperties({ id: newVal });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const nameChange = (newVal: string) => {
|
|
|
|
if (newVal) {
|
|
|
|
updateProperties({ name: newVal });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const documentationChange = (newVal: string) => {
|
|
|
|
if (newVal) {
|
2024-01-21 23:53:04 +08:00
|
|
|
const documentationElement = modeler.get<Moddle>('moddle').create('bpmn:Documentation', { text: newVal });
|
2024-01-21 18:13:15 +08:00
|
|
|
updateProperties({ documentation: [documentationElement] });
|
|
|
|
} else {
|
2024-01-21 22:35:34 +08:00
|
|
|
updateProperties({ documentation: null });
|
2024-01-21 18:13:15 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-21 15:35:43 +08:00
|
|
|
return {
|
|
|
|
elementType,
|
|
|
|
showConfig: config,
|
|
|
|
|
2024-01-21 18:13:15 +08:00
|
|
|
updateProperties,
|
|
|
|
idChange,
|
|
|
|
nameChange,
|
|
|
|
documentationChange
|
2024-01-21 15:35:43 +08:00
|
|
|
};
|
|
|
|
};
|