gaoluyang
2026-06-24 712aa51536236d43e87273e4ce45ac5691dffad8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<script lang="ts" setup>
import { nextTick, onBeforeUnmount, ref, toRaw, watch } from 'vue';
 
import { Textarea } from 'ant-design-vue';
 
defineOptions({ name: 'ElementOtherConfig' });
 
const props = defineProps({
  id: {
    type: String,
    default: '',
  },
});
 
const documentation = ref('');
const bpmnElement = ref();
 
const bpmnInstances = () => (window as any).bpmnInstances;
 
const updateDocumentation = () => {
  (bpmnElement.value && bpmnElement.value.id === props.id) ||
    (bpmnElement.value = bpmnInstances().elementRegistry.get(props.id));
  const documentations = bpmnInstances().bpmnFactory.create(
    'bpmn:Documentation',
    {
      text: documentation.value,
    },
  );
  bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
    documentation: [documentations],
  });
};
 
onBeforeUnmount(() => {
  bpmnElement.value = null;
});
 
watch(
  () => props.id,
  (id) => {
    if (id && id.length > 0) {
      nextTick(() => {
        const documentations =
          bpmnInstances().bpmnElement.businessObject?.documentation;
        documentation.value =
          documentations && documentations.length > 0
            ? documentations[0].text
            : '';
      });
    } else {
      documentation.value = '';
    }
  },
  { immediate: true },
);
</script>
 
<template>
  <div class="px-2 py-1">
    <div class="flex items-start gap-2">
      <div class="w-20 pt-1 text-sm text-gray-700">元素文档:</div>
      <div class="flex-1">
        <Textarea
          v-model:value="documentation"
          :auto-size="{ minRows: 2, maxRows: 4 }"
          @change="updateDocumentation"
          @blur="updateDocumentation"
        />
      </div>
    </div>
  </div>
</template>