wzj-vue/src/components/BpmnDesign/hooks/useParseElement.ts
2024-01-21 18:13:15 +08:00

51 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Ref } from 'vue';
import usePanel from '@/components/BpmnDesign/hooks/usePanel';
interface Options {
modeler: any;
element: any;
}
interface Data {
id: string;
}
export default <T extends Data>(ops: Options) => {
const { modeler, element } = ops;
const formData = ref<any>({});
const parse = () => {
const result = {
...element.businessObject,
...element.businessObject.$attrs
};
// 移除flowable前缀格式化数组
for (const key in result) {
if (key.indexOf('flowable:') === 0) {
const newKey = key.replace('flowable:', '');
result[newKey] = result[key];
delete result[key];
}
}
if ('documentation' in result) {
let str = '';
result.documentation.forEach((item: any) => {
str += item.text;
});
result.documentation = str;
}
formData.value = result;
return formData;
};
onBeforeMount(() => {
parse();
});
return {
parse,
formData: formData as Ref<T>
};
};