ElementProperties.vue 5.6 KB

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