ElementProperties.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 bpmnInstances = () => (window as any)?.bpmnInstances
  71. const resetAttributesList = () => {
  72. console.log(window, 'windowwindowwindowwindowwindowwindowwindow')
  73. bpmnElement.value = bpmnInstances().bpmnElement
  74. otherExtensionList.value = [] // 其他扩展配置
  75. bpmnElementProperties.value =
  76. // bpmnElement.value.businessObject?.extensionElements?.filter((ex) => {
  77. bpmnElement.value.businessObject?.extensionElements?.values.filter((ex) => {
  78. if (ex.$type !== `${prefix}:Properties`) {
  79. otherExtensionList.value.push(ex)
  80. }
  81. return ex.$type === `${prefix}:Properties`
  82. }) ?? []
  83. // 保存所有的 扩展属性字段
  84. bpmnElementPropertyList.value = bpmnElementProperties.value.reduce(
  85. (pre, current) => pre.concat(current.values),
  86. []
  87. )
  88. // 复制 显示
  89. elementPropertyList.value = JSON.parse(JSON.stringify(bpmnElementPropertyList.value ?? []))
  90. }
  91. const openAttributesForm = (attr, index) => {
  92. editingPropertyIndex.value = index
  93. propertyForm.value = index === -1 ? {} : JSON.parse(JSON.stringify(attr))
  94. propertyFormModelVisible.value = true
  95. nextTick(() => {
  96. if (attributeFormRef.value) attributeFormRef.value.clearValidate()
  97. })
  98. }
  99. const removeAttributes = (attr, index) => {
  100. console.log(attr, 'attr')
  101. ElMessageBox.confirm('确认移除该属性吗?', '提示', {
  102. confirmButtonText: '确 认',
  103. cancelButtonText: '取 消'
  104. })
  105. .then(() => {
  106. elementPropertyList.value.splice(index, 1)
  107. bpmnElementPropertyList.value.splice(index, 1)
  108. // 新建一个属性字段的保存列表
  109. const propertiesObject = bpmnInstances().moddle.create(`${prefix}:Properties`, {
  110. values: bpmnElementPropertyList.value
  111. })
  112. updateElementExtensions(propertiesObject)
  113. resetAttributesList()
  114. })
  115. .catch(() => console.info('操作取消'))
  116. }
  117. const saveAttribute = () => {
  118. console.log(propertyForm.value, 'propertyForm.value')
  119. const { name, value } = propertyForm.value
  120. if (editingPropertyIndex.value !== -1) {
  121. bpmnInstances().modeling.updateModdleProperties(
  122. toRaw(bpmnElement.value),
  123. toRaw(bpmnElementPropertyList.value)[toRaw(editingPropertyIndex.value)],
  124. {
  125. name,
  126. value
  127. }
  128. )
  129. } else {
  130. // 新建属性字段
  131. const newPropertyObject = bpmnInstances().moddle.create(`${prefix}:Property`, {
  132. name,
  133. value
  134. })
  135. // 新建一个属性字段的保存列表
  136. const propertiesObject = bpmnInstances().moddle.create(`${prefix}:Properties`, {
  137. values: bpmnElementPropertyList.value.concat([newPropertyObject])
  138. })
  139. updateElementExtensions(propertiesObject)
  140. }
  141. propertyFormModelVisible.value = false
  142. resetAttributesList()
  143. }
  144. const updateElementExtensions = (properties) => {
  145. const extensions = bpmnInstances().moddle.create('bpmn:ExtensionElements', {
  146. values: otherExtensionList.value.concat([properties])
  147. })
  148. bpmnInstances().modeling.updateProperties(toRaw(bpmnElement.value), {
  149. extensionElements: extensions
  150. })
  151. }
  152. watch(
  153. () => props.id,
  154. (val) => {
  155. if (val) {
  156. val && val.length && resetAttributesList()
  157. }
  158. },
  159. { immediate: true }
  160. )
  161. </script>