更多ruoyi-nbcio功能请看演示系统
gitee源代码地址
前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio
演示地址:RuoYi-Nbcio后台管理系统 http://218.75.87.38:9666/
更多nbcio-boot功能请看演示系统
gitee源代码地址
后端代码: https://gitee.com/nbacheng/nbcio-boot
前端代码:https://gitee.com/nbacheng/nbcio-vue.git
在线演示(包括H5) : http://218.75.87.38:9888
1、原先vue2代码如下:
<template> <div style="margin-top: 16px"> <el-form-item label="消息实例"> <div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap"> <el-select v-model="bindMessageId" @change="updateTaskMessage"> <el-option v-for="id in Object.keys(messageMap)" :value="id" :label="messageMap[id]" :key="id" /> </el-select> <el-button size="small" type="primary" :icon="Plus" style="margin-left: 8px" @click="openMessageModel" /> </div> </el-form-item> <el-dialog v-model="messageModelVisible" :close-on-click-modal="false" title="创建新消息" width="400px" append-to-body destroy-on-close> <el-form :model="newMessageForm" size="small" label-width="90px" @submit.prevent> <el-form-item label="消息ID"> <el-input v-model="newMessageForm.id" clearable /> </el-form-item> <el-form-item label="消息名称"> <el-input v-model="newMessageForm.name" clearable /> </el-form-item> </el-form> <template v-slot:footer> <el-button size="small" type="primary" @click="createNewMessage">确 认</el-button> </template> </el-dialog> </div> </template> <script> import { Plus } from '@element-plus/icons-vue' export default { name: "ReceiveTask", setup() { return { Plus } }, props: { id: String, type: String }, data() { return { bindMessageId: "", newMessageForm: {}, messageMap: {}, messageModelVisible: false }; }, watch: { id: { immediate: true, handler() { this.$nextTick(() => this.getBindMessage()); } } }, created() { this.bpmnMessageRefsMap = Object.create(null); this.bpmnRootElements = window.bpmnInstances.modeler.getDefinitions().rootElements; this.bpmnRootElements .filter(el => el.$type === "bpmn:Message") .forEach(m => { this.bpmnMessageRefsMap[m.id] = m; this.messageMap[m.id] = m.name }); this.messageMap["-1"] = "无" // 添加一个空对象,保证可以取消原消息绑定 }, methods: { getBindMessage() { this.bpmnElement = window.bpmnInstances.bpmnElement; this.bindMessageId = this.bpmnElement.businessObject?.messageRef?.id || "-1"; }, openMessageModel() { this.messageModelVisible = true; this.newMessageForm = {}; }, createNewMessage() { if (this.messageMap[this.newMessageForm.id]) { this.$message.error("该消息已存在,请修改id后重新保存"); return; } const newMessage = window.bpmnInstances.moddle.create("bpmn:Message", this.newMessageForm); this.bpmnRootElements.push(newMessage); this.messageMap[this.newMessageForm.id] = this.newMessageForm.name this.bpmnMessageRefsMap[this.newMessageForm.id] = newMessage; this.messageModelVisible = false; }, updateTaskMessage(messageId) { if (messageId === "-1") { window.bpmnInstances.modeling.updateProperties(this.bpmnElement, { messageRef: null }); } else { window.bpmnInstances.modeling.updateProperties(this.bpmnElement, { messageRef: this.bpmnMessageRefsMap[messageId] }); } } }, beforeUnmount() { this.bpmnElement = null; } }; </script>
2、修改成vue3代码如下:
<template> <div style="margin-top: 16px"> <el-form-item label="消息实例"> <div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap"> <el-select v-model="bindMessageId" @change="updateTaskMessage"> <el-option v-for="id in Object.keys(messageMap)" :value="id" :label="messageMap[id]" :key="id" /> </el-select> <el-button size="small" type="primary" :icon="Plus" style="margin-left: 8px" @click="openMessageModel" /> </div> </el-form-item> <el-dialog v-model="messageModelVisible" :close-on-click-modal="false" title="创建新消息" width="400px" append-to-body destroy-on-close> <el-form :model="newMessageForm" size="small" label-width="90px" @submit.prevent> <el-form-item label="消息ID"> <el-input v-model="newMessageForm.id" clearable /> </el-form-item> <el-form-item label="消息名称"> <el-input v-model="newMessageForm.name" clearable /> </el-form-item> </el-form> <template #footer> <el-button size="small" type="primary" @click="createNewMessage">确 认</el-button> </template> </el-dialog> </div> </template> <script lang="ts" setup> import { Plus } from '@element-plus/icons-vue' defineOptions({ name: 'ReceiveTask' }) const props = defineProps({ id: String, type: String }) const bindMessageId = ref('') const newMessageForm = ref<any>({}) const messageMap = ref<any>({}) const messageModelVisible = ref(false) const bpmnElement = ref<any>() const bpmnMessageRefsMap = ref<any>() const bpmnRootElements = ref<any>() const bpmnInstances = () => (window as any).bpmnInstances const getBindMessage = () => { bpmnElement.value = bpmnInstances().bpmnElement bindMessageId.value = bpmnElement.value.businessObject?.messageRef?.id || '-1' } watch( () => props.id, () => { // bpmnElement.value = bpmnInstances().bpmnElement nextTick(() => { getBindMessage() }) }, { immediate: true } ) const openMessageModel = () => { messageModelVisible.value = true newMessageForm.value = {} } const createNewMessage = () => { if (messageMap.value[newMessageForm.value.id]) { message.error('该消息已存在,请修改id后重新保存') return } const newMessage = bpmnInstances().moddle.create('bpmn:Message', newMessageForm.value) bpmnRootElements.value.push(newMessage) messageMap.value[newMessageForm.value.id] = newMessageForm.value.name bpmnMessageRefsMap.value[newMessageForm.value.id] = newMessage messageModelVisible.value = false } const updateTaskMessage = (messageId) => { if (messageId === '-1') { bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), { messageRef: null }) } else { bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), { messageRef: bpmnMessageRefsMap.value[messageId] }) } } onMounted(() => { bpmnMessageRefsMap.value = Object.create(null) bpmnRootElements.value = bpmnInstances().modeler.getDefinitions().rootElements bpmnRootElements.value .filter((el) => el.$type === 'bpmn:Message') .forEach((m) => { bpmnMessageRefsMap.value[m.id] = m messageMap.value[m.id] = m.name }) messageMap.value['-1'] = '无' }) onBeforeUnmount(() => { bpmnElement.value = null }) </script>
3、效果图如下: