ElementProperties.vue 5.6 KB

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