List.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 * as R from 'ramda'
  17. import ColumnsMixin from '../mixins/columns'
  18. import SingleActionsMixin from '../mixins/singleActions'
  19. import ClusterNamespace from '@K8S/sections/ClusterNamespace'
  20. import releaseMixin from '@K8S/mixins/releaseSidepage'
  21. import clusterNamespaceMixin from '@K8S/mixins/clusterNamespace'
  22. import expectStatus from '@/constants/expectStatus'
  23. import WindowsMixin from '@/mixins/windows'
  24. import ListMixin from '@/mixins/list'
  25. import { getNameFilter } from '@/utils/common/tableFilter'
  26. export default {
  27. name: 'K8SStatefulsetList',
  28. components: {
  29. ClusterNamespace,
  30. },
  31. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin, clusterNamespaceMixin, releaseMixin],
  32. props: {
  33. id: String,
  34. getParams: {
  35. type: Object,
  36. default: () => ({}),
  37. },
  38. },
  39. data () {
  40. return {
  41. list: this.$list.createList(this, {
  42. id: this.id,
  43. resource: 'statefulsets',
  44. apiVersion: 'v1',
  45. getParams: this.getParams,
  46. filterOptions: {
  47. name: getNameFilter(),
  48. },
  49. steadyStatus: {
  50. status: Object.values(expectStatus.k8s_resource).flat(),
  51. },
  52. itemGetParams: {
  53. cluster: '',
  54. namespace: '',
  55. },
  56. responseData: this.responseData,
  57. }),
  58. groupActions: [
  59. {
  60. label: this.$t('k8s.create'),
  61. permission: 'k8s_statefulsets_create',
  62. action: () => {
  63. this.$router.push({ path: '/k8s-statefulset/create' })
  64. },
  65. meta: () => ({
  66. buttonType: 'primary',
  67. }),
  68. },
  69. {
  70. label: this.$t('k8s.text_201'),
  71. permission: 'k8s_statefulsets_delete',
  72. action: () => {
  73. const data = this.list.selectedItems
  74. const requestData = {
  75. cluster: data[0].clusterID,
  76. }
  77. const namespace = data[0].namespace
  78. if (namespace) requestData.namespace = namespace
  79. this.createDialog('DeleteResDialog', {
  80. vm: this,
  81. data,
  82. columns: this.columns,
  83. title: this.$t('k8s.text_201'),
  84. name: this.$t('k8s.text_5'),
  85. onManager: this.onManager,
  86. requestData,
  87. })
  88. },
  89. meta: () => {
  90. let validate = true
  91. let tooltip = ''
  92. if (this.list.selectedItems.length > 0) {
  93. const namespaces = this.list.selectedItems.map(v => v.namespace)
  94. const unique = Array.from(new Set(namespaces))
  95. if (unique.length > 1) {
  96. validate = false
  97. tooltip = this.$t('k8s.text_203')
  98. }
  99. } else {
  100. validate = false
  101. tooltip = this.$t('k8s.text_204')
  102. }
  103. return {
  104. validate,
  105. tooltip,
  106. }
  107. },
  108. },
  109. ],
  110. }
  111. },
  112. created () {
  113. this.list.fetchData()
  114. },
  115. methods: {
  116. handleOpenSidepage (row) {
  117. this.sidePageTriggerHandle(this, 'K8SStatefulsetSidePage', {
  118. id: row.id,
  119. resource: 'statefulsets',
  120. getParams: () => {
  121. const params = R.clone(this.list.getParams)
  122. if (row.namespace) {
  123. params.namespace = row.namespace
  124. if (params.all_namespace) delete params.all_namespace
  125. }
  126. return params
  127. },
  128. apiVersion: 'v1',
  129. steadyStatus: {
  130. status: Object.values(expectStatus.k8s_resource).flat(),
  131. },
  132. }, {
  133. list: this.list,
  134. })
  135. },
  136. },
  137. }
  138. </script>