List.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :noDataText="noDataText"
  6. :group-actions="groupActions"
  7. :single-actions="singleActions"
  8. :showSearchbox="showSearchbox"
  9. :showGroupActions="showGroupActions">
  10. <template v-slot:group-actions-append>
  11. <cluster-namespace :getParams.sync="list.getParams" :namespaceMap="namespaceMap" @refresh="fetchData" class="ml-3" />
  12. </template>
  13. </page-list>
  14. </template>
  15. <script>
  16. import ColumnsMixin from '../mixins/columns'
  17. import SingleActionsMixin from '../mixins/singleActions'
  18. import ClusterNamespace from '@K8S/sections/ClusterNamespace'
  19. import releaseMixin from '@K8S/mixins/releaseSidepage'
  20. import clusterNamespaceMixin from '@K8S/mixins/clusterNamespace'
  21. import { getNameFilter } from '@/utils/common/tableFilter'
  22. import WindowsMixin from '@/mixins/windows'
  23. import ListMixin from '@/mixins/list'
  24. import expectStatus from '@/constants/expectStatus'
  25. export default {
  26. name: 'K8SRbacRoleList',
  27. components: {
  28. ClusterNamespace,
  29. },
  30. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin, clusterNamespaceMixin, releaseMixin],
  31. props: {
  32. id: String,
  33. getParams: {
  34. type: Object,
  35. default: () => ({}),
  36. },
  37. },
  38. data () {
  39. return {
  40. list: this.$list.createList(this, {
  41. id: this.id,
  42. resource: 'rbacroles',
  43. apiVersion: 'v1',
  44. getParams: this.getParams,
  45. filterOptions: {
  46. name: getNameFilter(),
  47. },
  48. steadyStatus: {
  49. status: Object.values(expectStatus.k8s_resource).flat(),
  50. },
  51. responseData: this.responseData,
  52. }),
  53. deleteGroupOpsValid: arr => arr.every(item => item.type === arr[0].type),
  54. groupActions: [
  55. {
  56. label: this.$t('common.create'),
  57. permission: 'k8s_rbacroles_create',
  58. action: () => {
  59. this.$router.push('/k8s-rbacrole/create')
  60. },
  61. meta: () => ({
  62. buttonType: 'primary',
  63. }),
  64. },
  65. {
  66. label: this.$t('k8s.text_201'),
  67. permission: 'k8s_rbacroles_delete',
  68. action: () => {
  69. this.createDialog('DeleteResDialog', {
  70. vm: this,
  71. data: this.list.selectedItems,
  72. columns: this.columns,
  73. title: this.$t('k8s.text_328'),
  74. name: this.$t('k8s.text_24'),
  75. onManager: this.onManager,
  76. ok: (ids, data) => {
  77. return new this.$Manager('rbacroles', 'v1').batchDelete({
  78. ids,
  79. data: {
  80. cluster: data[0].clusterID,
  81. namespace: data[0].namespace,
  82. },
  83. }).then(() => {
  84. this.refresh()
  85. return true
  86. }).catch(error => {
  87. throw error
  88. })
  89. },
  90. })
  91. },
  92. meta: () => {
  93. if (this.list.selectedItems.length > 0) {
  94. const namespaces = this.list.selectedItems.map(v => v.namespace)
  95. const unique = Array.from(new Set(namespaces))
  96. if (unique.length === 1) {
  97. return {
  98. validate: true,
  99. }
  100. } else {
  101. return {
  102. validate: this.deleteGroupOpsValid(this.list.selectedItems),
  103. tooltip: !this.deleteGroupOpsValid(this.list.selectedItems) ? this.$t('k8s.text_329') : '',
  104. }
  105. }
  106. } else {
  107. return {
  108. validate: false,
  109. tooltip: this.$t('k8s.text_204'),
  110. }
  111. }
  112. },
  113. },
  114. ],
  115. }
  116. },
  117. created () {
  118. this.list.fetchData()
  119. },
  120. methods: {
  121. handleOpenSidepage (row) {
  122. this.sidePageTriggerHandle(this, 'K8SRbacRoleSidePage', {
  123. id: row.id,
  124. resource: 'rbacroles',
  125. apiVersion: 'v1',
  126. getParams: this.list.getParams,
  127. }, {
  128. list: this.list,
  129. })
  130. },
  131. },
  132. }
  133. </script>