ElementProperties.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="panel-tab__content">
  3. <el-table :data="elementPropertyList" max-height="240" border fit show-overflow-tooltip>
  4. <el-table-column label="序号" width="50px" type="index" />
  5. <el-table-column label="属性名" prop="name" min-width="100px" />
  6. <el-table-column label="属性值" prop="value" min-width="100px" />
  7. <el-table-column label="操作" width="90px">
  8. <template v-slot="{ row, $index }">
  9. <el-button link type="" @click="openAttributesForm(row, $index)">编辑</el-button>
  10. <el-divider direction="vertical" />
  11. <el-button link type="" style="color: #ff4d4f" @click="removeAttributes(row, $index)">移除</el-button>
  12. </template>
  13. </el-table-column>
  14. </el-table>
  15. <div class="element-drawer__button">
  16. <el-button type="primary" @click="openAttributesForm(null, -1)">添加属性</el-button>
  17. </div>
  18. <el-dialog v-model="propertyFormModelVisible" title="属性配置" width="600px" append-to-body destroy-on-close>
  19. <el-form :model="propertyForm" label-width="80px" ref="attributeFormRef" @submit.prevent>
  20. <el-form-item label="属性名:" prop="name">
  21. <el-input v-model="propertyForm.name" clearable />
  22. </el-form-item>
  23. <el-form-item label="属性值:" prop="value">
  24. <el-input v-model="propertyForm.value" clearable />
  25. </el-form-item>
  26. </el-form>
  27. <template v-slot:footer>
  28. <el-button @click="propertyFormModelVisible = false">取 消</el-button>
  29. <el-button type="primary" @click="saveAttribute">确 定</el-button>
  30. </template>
  31. </el-dialog>
  32. </div>
  33. </template>
  34. <script>
  35. export default {
  36. name: "ElementProperties",
  37. props: {
  38. id: String,
  39. type: String
  40. },
  41. inject: {
  42. prefix: "prefix",
  43. width: "width"
  44. },
  45. data() {
  46. return {
  47. elementPropertyList: [],
  48. propertyForm: {},
  49. editingPropertyIndex: -1,
  50. propertyFormModelVisible: false
  51. };
  52. },
  53. watch: {
  54. id: {
  55. immediate: true,
  56. handler(val) {
  57. val && val.length && this.resetAttributesList();
  58. }
  59. }
  60. },
  61. methods: {
  62. resetAttributesList() {
  63. this.bpmnElement = window.bpmnInstances.bpmnElement;
  64. this.otherExtensionList = []; // 其他扩展配置
  65. this.bpmnElementProperties =
  66. this.bpmnElement.businessObject?.extensionElements?.values?.filter((ex) => {
  67. if (ex.$type !== `${this.prefix}:Properties`) {
  68. this.otherExtensionList.push(ex);
  69. }
  70. return ex.$type === `${this.prefix}:Properties`;
  71. }) ?? [];
  72. // 保存所有的 扩展属性字段
  73. this.bpmnElementPropertyList = this.bpmnElementProperties.reduce((pre, current) => pre.concat(current.values), []);
  74. // 复制 显示
  75. this.elementPropertyList = JSON.parse(JSON.stringify(this.bpmnElementPropertyList ?? []));
  76. },
  77. openAttributesForm(attr, index) {
  78. this.editingPropertyIndex = index;
  79. this.propertyForm = index === -1 ? {} : JSON.parse(JSON.stringify(attr));
  80. this.propertyFormModelVisible = true;
  81. this.$nextTick(() => {
  82. if (this.$refs["attributeFormRef"]) this.$refs["attributeFormRef"].clearValidate();
  83. });
  84. },
  85. removeAttributes(attr, index) {
  86. this.$confirm("确认移除该属性吗?", "提示", {
  87. confirmButtonText: "确 认",
  88. cancelButtonText: "取 消"
  89. })
  90. .then(() => {
  91. this.elementPropertyList.splice(index, 1);
  92. this.bpmnElementPropertyList.splice(index, 1);
  93. // 新建一个属性字段的保存列表
  94. const propertiesObject = window.bpmnInstances.moddle.create(`${this.prefix}:Properties`, {
  95. values: this.bpmnElementPropertyList
  96. });
  97. this.updateElementExtensions(propertiesObject);
  98. this.resetAttributesList();
  99. })
  100. .catch(() => console.info("操作取消"));
  101. },
  102. saveAttribute() {
  103. const { name, value } = this.propertyForm;
  104. console.log(this.bpmnElementPropertyList);
  105. if (this.editingPropertyIndex !== -1) {
  106. window.bpmnInstances.modeling.updateModdleProperties(this.bpmnElement, this.bpmnElementPropertyList[this.editingPropertyIndex], {
  107. name,
  108. value
  109. });
  110. } else {
  111. // 新建属性字段
  112. const newPropertyObject = window.bpmnInstances.moddle.create(`${this.prefix}:Property`, { name, value });
  113. // 新建一个属性字段的保存列表
  114. const propertiesObject = window.bpmnInstances.moddle.create(`${this.prefix}:Properties`, {
  115. values: this.bpmnElementPropertyList.concat([newPropertyObject])
  116. });
  117. this.updateElementExtensions(propertiesObject);
  118. }
  119. this.propertyFormModelVisible = false;
  120. this.resetAttributesList();
  121. },
  122. updateElementExtensions(properties) {
  123. const extensions = window.bpmnInstances.moddle.create("bpmn:ExtensionElements", {
  124. values: this.otherExtensionList.concat([properties])
  125. });
  126. window.bpmnInstances.modeling.updateProperties(this.bpmnElement, {
  127. extensionElements: extensions
  128. });
  129. }
  130. }
  131. };
  132. </script>