gaoluyang
2026-06-24 c0cb161bb52ce0fbdce5c66ec391d107c75e2452
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<script lang="ts" setup>
import { nextTick, onBeforeUnmount, ref, toRaw, watch } from 'vue';
 
import {
  Form,
  FormItem,
  Input,
  Select,
  SelectOption,
  Textarea,
} from 'ant-design-vue';
 
defineOptions({ name: 'ScriptTask' });
const props = defineProps({
  id: {
    type: String,
    default: '',
  },
  type: {
    type: String,
    default: '',
  },
});
const defaultTaskForm = ref({
  scriptFormat: '',
  script: '',
  resource: '',
  resultVariable: '',
});
const scriptTaskForm = ref<any>({});
const bpmnElement = ref();
 
const bpmnInstances = () => (window as any)?.bpmnInstances;
 
const resetTaskForm = () => {
  for (const key in defaultTaskForm.value) {
    scriptTaskForm.value[key] =
      bpmnElement.value?.businessObject[
        key as keyof typeof defaultTaskForm.value
      ] || defaultTaskForm.value[key as keyof typeof defaultTaskForm.value];
  }
  scriptTaskForm.value.scriptType = scriptTaskForm.value.script
    ? 'inline'
    : 'external';
};
const updateElementTask = () => {
  const taskAttr = Object.create(null);
  taskAttr.scriptFormat = scriptTaskForm.value.scriptFormat || null;
  taskAttr.resultVariable = scriptTaskForm.value.resultVariable || null;
  if (scriptTaskForm.value.scriptType === 'inline') {
    taskAttr.script = scriptTaskForm.value.script || null;
    taskAttr.resource = null;
  } else {
    taskAttr.resource = scriptTaskForm.value.resource || null;
    taskAttr.script = null;
  }
  bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), taskAttr);
};
 
onBeforeUnmount(() => {
  bpmnElement.value = null;
});
 
watch(
  () => props.id,
  () => {
    bpmnElement.value = bpmnInstances().bpmnElement;
    nextTick(() => {
      resetTaskForm();
    });
  },
  { immediate: true },
);
</script>
 
<template>
  <div class="mt-4">
    <Form :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
      <FormItem label="脚本格式">
        <Input
          v-model:value="scriptTaskForm.scriptFormat"
          allow-clear
          @input="updateElementTask()"
          @change="updateElementTask()"
        />
      </FormItem>
      <!-- TODO scriptType  外部资源 和 内联脚本,  flowable 文档 https://www.flowable.com/open-source/docs/bpmn/ch07b-BPMN-Constructs#script-task  没看到到有相应的属性 -->
      <FormItem label="脚本类型">
        <Select v-model:value="scriptTaskForm.scriptType">
          <SelectOption value="inline">内联脚本</SelectOption>
          <SelectOption value="external">外部资源</SelectOption>
        </Select>
      </FormItem>
      <FormItem label="脚本" v-show="scriptTaskForm.scriptType === 'inline'">
        <Textarea
          v-model:value="scriptTaskForm.script"
          :auto-size="{ minRows: 2, maxRows: 4 }"
          allow-clear
          @input="updateElementTask()"
          @change="updateElementTask()"
        />
      </FormItem>
      <FormItem
        label="资源地址"
        v-show="scriptTaskForm.scriptType === 'external'"
      >
        <Input
          v-model:value="scriptTaskForm.resource"
          allow-clear
          @input="updateElementTask()"
          @change="updateElementTask()"
        />
      </FormItem>
      <FormItem label="结果变量">
        <Input
          v-model:value="scriptTaskForm.resultVariable"
          allow-clear
          @input="updateElementTask()"
          @change="updateElementTask()"
        />
      </FormItem>
    </Form>
  </div>
</template>