ElementProperties.vue 5.4 KB

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