提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<div style="margin-top: 16px"> |
|
3 |
<el-form-item label="消息实例"> |
|
4 |
<div |
|
5 |
style=" |
|
6 |
display: flex; |
|
7 |
align-items: center; |
|
8 |
justify-content: space-between; |
|
9 |
flex-wrap: nowrap; |
|
10 |
" |
|
11 |
> |
|
12 |
<el-select v-model="bindMessageId" @change="updateTaskMessage"> |
|
13 |
<el-option |
|
14 |
v-for="key in Object.keys(messageMap)" |
|
15 |
:value="key" |
|
16 |
:label="messageMap[key]" |
|
17 |
:key="key" |
|
18 |
/> |
|
19 |
</el-select> |
|
20 |
<XButton |
|
21 |
type="primary" |
|
22 |
preIcon="ep:plus" |
|
23 |
style="margin-left: 8px" |
|
24 |
@click="openMessageModel" |
|
25 |
/> |
|
26 |
</div> |
|
27 |
</el-form-item> |
|
28 |
<el-dialog |
|
29 |
v-model="messageModelVisible" |
|
30 |
:close-on-click-modal="false" |
|
31 |
title="创建新消息" |
|
32 |
width="400px" |
|
33 |
append-to-body |
|
34 |
destroy-on-close |
|
35 |
> |
|
36 |
<el-form :model="newMessageForm" size="small" label-width="90px"> |
|
37 |
<el-form-item label="消息ID"> |
|
38 |
<el-input v-model="newMessageForm.id" clearable /> |
|
39 |
</el-form-item> |
|
40 |
<el-form-item label="消息名称"> |
|
41 |
<el-input v-model="newMessageForm.name" clearable /> |
|
42 |
</el-form-item> |
|
43 |
</el-form> |
|
44 |
<template #footer> |
|
45 |
<el-button size="small" type="primary" @click="createNewMessage">确 认</el-button> |
|
46 |
</template> |
|
47 |
</el-dialog> |
|
48 |
</div> |
|
49 |
</template> |
|
50 |
|
|
51 |
<script lang="ts" setup> |
|
52 |
defineOptions({ name: 'ReceiveTask' }) |
|
53 |
const props = defineProps({ |
|
54 |
id: String, |
|
55 |
type: String |
|
56 |
}) |
|
57 |
|
|
58 |
const message = useMessage() |
|
59 |
|
|
60 |
const bindMessageId = ref('') |
|
61 |
const newMessageForm = ref<any>({}) |
|
62 |
const messageMap = ref<any>({}) |
|
63 |
const messageModelVisible = ref(false) |
|
64 |
const bpmnElement = ref<any>() |
|
65 |
const bpmnMessageRefsMap = ref<any>() |
|
66 |
const bpmnRootElements = ref<any>() |
|
67 |
|
|
68 |
const bpmnInstances = () => (window as any).bpmnInstances |
|
69 |
const getBindMessage = () => { |
|
70 |
bpmnElement.value = bpmnInstances().bpmnElement |
|
71 |
bindMessageId.value = bpmnElement.value.businessObject?.messageRef?.id || '-1' |
|
72 |
} |
|
73 |
const openMessageModel = () => { |
|
74 |
messageModelVisible.value = true |
|
75 |
newMessageForm.value = {} |
|
76 |
} |
|
77 |
const createNewMessage = () => { |
|
78 |
if (messageMap.value[newMessageForm.value.id]) { |
|
79 |
message.error('该消息已存在,请修改id后重新保存') |
|
80 |
return |
|
81 |
} |
|
82 |
const newMessage = bpmnInstances().moddle.create('bpmn:Message', newMessageForm.value) |
|
83 |
bpmnRootElements.value.push(newMessage) |
|
84 |
messageMap.value[newMessageForm.value.id] = newMessageForm.value.name |
|
85 |
bpmnMessageRefsMap.value[newMessageForm.value.id] = newMessage |
|
86 |
messageModelVisible.value = false |
|
87 |
} |
|
88 |
const updateTaskMessage = (messageId) => { |
|
89 |
if (messageId === '-1') { |
|
90 |
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), { |
|
91 |
messageRef: null |
|
92 |
}) |
|
93 |
} else { |
|
94 |
bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), { |
|
95 |
messageRef: bpmnMessageRefsMap.value[messageId] |
|
96 |
}) |
|
97 |
} |
|
98 |
} |
|
99 |
|
|
100 |
onMounted(() => { |
|
101 |
bpmnMessageRefsMap.value = Object.create(null) |
|
102 |
bpmnRootElements.value = bpmnInstances().modeler.getDefinitions().rootElements |
|
103 |
bpmnRootElements.value |
|
104 |
.filter((el) => el.$type === 'bpmn:Message') |
|
105 |
.forEach((m) => { |
|
106 |
bpmnMessageRefsMap.value[m.id] = m |
|
107 |
messageMap.value[m.id] = m.name |
|
108 |
}) |
|
109 |
messageMap.value['-1'] = '无' |
|
110 |
}) |
|
111 |
|
|
112 |
onBeforeUnmount(() => { |
|
113 |
bpmnElement.value = null |
|
114 |
}) |
|
115 |
watch( |
|
116 |
() => props.id, |
|
117 |
() => { |
|
118 |
// bpmnElement.value = bpmnInstances().bpmnElement |
|
119 |
nextTick(() => { |
|
120 |
getBindMessage() |
|
121 |
}) |
|
122 |
}, |
|
123 |
{ immediate: true } |
|
124 |
) |
|
125 |
</script> |