SignalAndMessage.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="panel-tab__content">
  3. <div class="panel-tab__content--title">
  4. <span
  5. ><el-icon style="margin-right: 8px; color: #555555"><Menu /></el-icon>消息列表</span
  6. >
  7. <el-button type="primary" @click="openModel('message')">创建新消息</el-button>
  8. </div>
  9. <el-table :data="messageList" border show-overflow-tooltip>
  10. <el-table-column type="index" label="序号" width="60px" />
  11. <el-table-column label="消息ID" prop="id" max-width="300px" />
  12. <el-table-column label="消息名称" prop="name" max-width="300px" />
  13. </el-table>
  14. <div class="panel-tab__content--title" style="padding-top: 8px; margin-top: 8px; border-top: 1px solid #eeeeee">
  15. <span
  16. ><el-icon style="margin-right: 8px; color: #555555"><Menu /></el-icon>信号列表</span
  17. >
  18. <el-button type="primary" @click="openModel('signal')">创建新信号</el-button>
  19. </div>
  20. <el-table :data="signalList" border>
  21. <el-table-column type="index" label="序号" width="60px" />
  22. <el-table-column label="信号ID" prop="id" max-width="300px" />
  23. <el-table-column label="信号名称" prop="name" max-width="300px" />
  24. </el-table>
  25. <el-dialog v-model="modelVisible" :title="modelConfig.title" :close-on-click-modal="false" width="400px" append-to-body destroy-on-close>
  26. <el-form :model="modelObjectForm" label-width="90px" @submit.prevent>
  27. <el-form-item :label="modelConfig.idLabel">
  28. <el-input v-model="modelObjectForm.id" clearable />
  29. </el-form-item>
  30. <el-form-item :label="modelConfig.nameLabel">
  31. <el-input v-model="modelObjectForm.name" clearable />
  32. </el-form-item>
  33. </el-form>
  34. <template v-slot:footer>
  35. <el-button @click="modelVisible = false">取 消</el-button>
  36. <el-button type="primary" @click="addNewObject">保 存</el-button>
  37. </template>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. export default {
  43. name: "SignalAndMassage",
  44. data() {
  45. return {
  46. signalList: [],
  47. messageList: [],
  48. modelVisible: false,
  49. modelType: "",
  50. modelObjectForm: {}
  51. };
  52. },
  53. computed: {
  54. modelConfig() {
  55. if (this.modelType === "message") {
  56. return { title: "创建消息", idLabel: "消息ID", nameLabel: "消息名称" };
  57. } else {
  58. return { title: "创建信号", idLabel: "信号ID", nameLabel: "信号名称" };
  59. }
  60. }
  61. },
  62. mounted() {
  63. this.initDataList();
  64. },
  65. methods: {
  66. initDataList() {
  67. this.rootElements = window.bpmnInstances.modeler.getDefinitions().rootElements;
  68. this.messageIdMap = {};
  69. this.signalIdMap = {};
  70. this.messageList = [];
  71. this.signalList = [];
  72. this.rootElements.forEach((el) => {
  73. if (el.$type === "bpmn:Message") {
  74. this.messageIdMap[el.id] = true;
  75. this.messageList.push({ ...el });
  76. }
  77. if (el.$type === "bpmn:Signal") {
  78. this.signalIdMap[el.id] = true;
  79. this.signalList.push({ ...el });
  80. }
  81. });
  82. },
  83. openModel(type) {
  84. this.modelType = type;
  85. this.modelObjectForm = {};
  86. this.modelVisible = true;
  87. },
  88. addNewObject() {
  89. if (this.modelType === "message") {
  90. if (this.messageIdMap[this.modelObjectForm.id]) {
  91. return this.$message.error("该消息已存在,请修改id后重新保存");
  92. }
  93. const messageRef = window.bpmnInstances.moddle.create("bpmn:Message", this.modelObjectForm);
  94. this.rootElements.push(messageRef);
  95. } else {
  96. if (this.signalIdMap[this.modelObjectForm.id]) {
  97. return this.$message.error("该信号已存在,请修改id后重新保存");
  98. }
  99. const signalRef = window.bpmnInstances.moddle.create("bpmn:Signal", this.modelObjectForm);
  100. this.rootElements.push(signalRef);
  101. }
  102. this.modelVisible = false;
  103. this.initDataList();
  104. }
  105. }
  106. };
  107. </script>