当前位置:   article > 正文

ruoyi-nbcio-plus基于vue3的flowable接收任务的升级修改_vue3 + flowable modeler

vue3 + flowable modeler

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统 http://122.227.135.243:9666/

更多nbcio-boot功能请看演示系统 

gitee源代码地址

后端代码: https://gitee.com/nbacheng/nbcio-boot

前端代码:https://gitee.com/nbacheng/nbcio-vue.git

在线演示(包括H5) : http://122.227.135.243:9888

1、原先vue2代码如下:

  1. <template>
  2. <div style="margin-top: 16px">
  3. <el-form-item label="消息实例">
  4. <div style="display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap">
  5. <el-select v-model="bindMessageId" @change="updateTaskMessage">
  6. <el-option v-for="id in Object.keys(messageMap)" :value="id" :label="messageMap[id]" :key="id" />
  7. </el-select>
  8. <el-button size="small" type="primary" :icon="Plus" style="margin-left: 8px" @click="openMessageModel" />
  9. </div>
  10. </el-form-item>
  11. <el-dialog v-model="messageModelVisible" :close-on-click-modal="false" title="创建新消息" width="400px" append-to-body destroy-on-close>
  12. <el-form :model="newMessageForm" size="small" label-width="90px" @submit.prevent>
  13. <el-form-item label="消息ID">
  14. <el-input v-model="newMessageForm.id" clearable />
  15. </el-form-item>
  16. <el-form-item label="消息名称">
  17. <el-input v-model="newMessageForm.name" clearable />
  18. </el-form-item>
  19. </el-form>
  20. <template v-slot:footer>
  21. <el-button size="small" type="primary" @click="createNewMessage">确 认</el-button>
  22. </template>
  23. </el-dialog>
  24. </div>
  25. </template>
  26. <script>
  27. import { Plus } from '@element-plus/icons-vue'
  28. export default {
  29. name: "ReceiveTask",
  30. setup() {
  31. return {
  32. Plus
  33. }
  34. },
  35. props: {
  36. id: String,
  37. type: String
  38. },
  39. data() {
  40. return {
  41. bindMessageId: "",
  42. newMessageForm: {},
  43. messageMap: {},
  44. messageModelVisible: false
  45. };
  46. },
  47. watch: {
  48. id: {
  49. immediate: true,
  50. handler() {
  51. this.$nextTick(() => this.getBindMessage());
  52. }
  53. }
  54. },
  55. created() {
  56. this.bpmnMessageRefsMap = Object.create(null);
  57. this.bpmnRootElements = window.bpmnInstances.modeler.getDefinitions().rootElements;
  58. this.bpmnRootElements
  59. .filter(el => el.$type === "bpmn:Message")
  60. .forEach(m => {
  61. this.bpmnMessageRefsMap[m.id] = m;
  62. this.messageMap[m.id] = m.name
  63. });
  64. this.messageMap["-1"] = "无" // 添加一个空对象,保证可以取消原消息绑定
  65. },
  66. methods: {
  67. getBindMessage() {
  68. this.bpmnElement = window.bpmnInstances.bpmnElement;
  69. this.bindMessageId = this.bpmnElement.businessObject?.messageRef?.id || "-1";
  70. },
  71. openMessageModel() {
  72. this.messageModelVisible = true;
  73. this.newMessageForm = {};
  74. },
  75. createNewMessage() {
  76. if (this.messageMap[this.newMessageForm.id]) {
  77. this.$message.error("该消息已存在,请修改id后重新保存");
  78. return;
  79. }
  80. const newMessage = window.bpmnInstances.moddle.create("bpmn:Message", this.newMessageForm);
  81. this.bpmnRootElements.push(newMessage);
  82. this.messageMap[this.newMessageForm.id] = this.newMessageForm.name
  83. this.bpmnMessageRefsMap[this.newMessageForm.id] = newMessage;
  84. this.messageModelVisible = false;
  85. },
  86. updateTaskMessage(messageId) {
  87. if (messageId === "-1") {
  88. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  89. messageRef: null
  90. });
  91. } else {
  92. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  93. messageRef: this.bpmnMessageRefsMap[messageId]
  94. });
  95. }
  96. }
  97. },
  98. beforeUnmount() {
  99. this.bpmnElement = null;
  100. }
  101. };
  102. </script>

2、修改成vue3代码如下:

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

3、效果图如下:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/418052
推荐阅读
相关标签
  

闽ICP备14008679号