addRelBatchModal.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <a-modal title="新增实体"
  3. :visible="show"
  4. :maskClosable="false"
  5. :width="800"
  6. @ok="handleOk"
  7. @cancel="handleClose">
  8. <a-input-search v-model="searchValue" size="small" placeholder="请输入名称" enter-button
  9. @keyup.enter="search" @search="search" style="margin-bottom: 10px"/>
  10. <a-table
  11. :dataSource="data"
  12. :columns="columns"
  13. :pagination="pagination"
  14. :rowSelection="{
  15. selectedRowKeys: checkedList,
  16. onChange: onSelectChange
  17. }"
  18. @change="onChangePagination"
  19. :rowKey="(record) => record.entId"
  20. :loading="loading">
  21. </a-table>
  22. </a-modal>
  23. </template>
  24. <script>
  25. import { getRelclsEnt, addRelBatch } from '@/api/graph/relationClass'
  26. export default {
  27. name: 'addRelBatchModal',
  28. components: {},
  29. props: ['relClsId', 'direction', 'isModel', 'entId'],
  30. data() {
  31. return {
  32. searchValue: '',
  33. show: true,
  34. loading: false,
  35. data: [],
  36. columns: [
  37. {
  38. title: "实体ID",
  39. dataIndex: "entId",
  40. },
  41. {
  42. title: "实体名称",
  43. dataIndex: "entName",
  44. },
  45. ],
  46. pagination: {
  47. current: 1,
  48. total: 0,
  49. pageSize: 9
  50. },
  51. checkedList: [],
  52. }
  53. },
  54. mounted() {
  55. this.getEntityList()
  56. },
  57. methods: {
  58. // 获取实体列表
  59. getEntityList(value) {
  60. // relClsId, direction, isModel, current, size
  61. getRelclsEnt(this.relClsId, this.direction, this.entId, this.isModel, value, this.pagination.current, this.pagination.pageSize).then(res => {
  62. this.columns = [
  63. {
  64. title: "实体ID",
  65. dataIndex: "entId",
  66. },
  67. {
  68. title: "实体名称",
  69. dataIndex: "entName",
  70. },
  71. ]
  72. res.headers.forEach(header => {
  73. this.columns.push({
  74. title: header.attrClsName,
  75. dataIndex: header.attrClsID,
  76. })
  77. })
  78. res.data.forEach(item => {
  79. for (let i = 0; i < item.notNullAttrVOList.length; i++) {
  80. item[item.notNullAttrVOList[i].attrClsID] = item.notNullAttrVOList[i].attrValue
  81. }
  82. })
  83. this.pagination.total = res.total
  84. this.data = res.data
  85. })
  86. },
  87. search() {
  88. this.pagination = {
  89. pageSize: 9,
  90. current: 1
  91. }
  92. this.getEntityList(this.searchValue)
  93. },
  94. handleOk() {
  95. const vm = this
  96. let entityRelations = []
  97. this.checkedList.forEach((item, index) => {
  98. let startEntId;
  99. let endEntId;
  100. if (vm.direction === 'START') {
  101. startEntId = vm.entId
  102. endEntId = item
  103. } else {
  104. startEntId = item
  105. endEntId = vm.entId
  106. }
  107. let entityRelation = {
  108. startEntId,
  109. endEntId,
  110. isModel: this.isModel,
  111. relClsId: this.relClsId
  112. }
  113. entityRelations.push(entityRelation)
  114. })
  115. addRelBatch(entityRelations).then(res => {
  116. if (res) {
  117. this.$notification["success"]({
  118. message: "新增成功"
  119. });
  120. this.$close(res)
  121. }
  122. })
  123. },
  124. handleClose() {
  125. this.$close(false)
  126. },
  127. onChangePagination(current) {
  128. this.pagination = current
  129. this.getEntityList()
  130. },
  131. onSelectChange(selectedRowKeys) {
  132. this.checkedList = selectedRowKeys
  133. },
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. </style>