List.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions">
  7. <template v-slot:group-actions-append>
  8. <cluster-namespace :getParams.sync="list.getParams" :ignoreNamespace="true" @refresh="fetchData" class="ml-3" />
  9. </template>
  10. </page-list>
  11. </template>
  12. <script>
  13. import ColumnsMixin from '../mixins/columns'
  14. import SingleActionsMixin from '../mixins/singleActions'
  15. import ClusterNamespace from '@K8S/sections/ClusterNamespace'
  16. import { getNameFilter } from '@/utils/common/tableFilter'
  17. import WindowsMixin from '@/mixins/windows'
  18. import ListMixin from '@/mixins/list'
  19. export default {
  20. name: 'K8SNamespaceList',
  21. components: {
  22. ClusterNamespace,
  23. },
  24. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin],
  25. props: {
  26. id: String,
  27. getParams: {
  28. type: Object,
  29. default: () => ({}),
  30. },
  31. },
  32. data () {
  33. return {
  34. list: this.$list.createList(this, {
  35. id: this.id,
  36. resource: 'namespaces',
  37. apiVersion: 'v1',
  38. getParams: this.getParams,
  39. filterOptions: {
  40. name: getNameFilter(),
  41. },
  42. }),
  43. groupActions: [
  44. {
  45. label: this.$t('k8s.create'),
  46. permission: 'k8s_namespaces_create',
  47. action: () => {
  48. this.$router.push({ path: '/k8s-namespace/create' })
  49. },
  50. meta: () => ({
  51. buttonType: 'primary',
  52. }),
  53. },
  54. {
  55. label: this.$t('k8s.text_201'),
  56. permission: 'k8s_namespaces_delete',
  57. action: () => {
  58. this.createDialog('DeleteResDialog', {
  59. vm: this,
  60. data: this.list.selectedItems,
  61. columns: this.columns,
  62. title: this.$t('k8s.text_284'),
  63. name: this.$t('k8s.text_23'),
  64. onManager: this.onManager,
  65. requestData: {
  66. cluster: this.list.selectedItems[0].clusterID,
  67. },
  68. requestParams: {
  69. id: this.list.selectedItems.map(item => item.id),
  70. },
  71. })
  72. },
  73. meta: () => {
  74. if (this.list.selectedItems.length > 0) {
  75. const namespaces = this.list.selectedItems.map(v => v.namespace)
  76. const unique = Array.from(new Set(namespaces))
  77. if (unique.length > 1) {
  78. return {
  79. validate: false,
  80. tooltip: this.$t('k8s.text_203'),
  81. }
  82. }
  83. return {
  84. validate: true,
  85. tooltip: '',
  86. }
  87. } else {
  88. return {
  89. validate: false,
  90. tooltip: this.$t('k8s.text_204'),
  91. }
  92. }
  93. },
  94. },
  95. ],
  96. }
  97. },
  98. created () {
  99. this.fetchData()
  100. },
  101. methods: {
  102. fetchData () {
  103. if (this.list.getParams.cluster) {
  104. this.list.fetchData()
  105. }
  106. },
  107. handleOpenSidepage (row) {
  108. this.sidePageTriggerHandle(this, 'K8SNamespaceSidePage', {
  109. id: row.id,
  110. resource: 'namespaces',
  111. apiVersion: 'v1',
  112. getParams: this.list.getParams,
  113. }, {
  114. list: this.list,
  115. })
  116. },
  117. },
  118. }
  119. </script>