List.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :noDataText="noDataText"
  6. :group-actions="groupActions"
  7. :single-actions="singleActions">
  8. <template v-slot:group-actions-append>
  9. <cluster-namespace :getParams.sync="list.getParams" :namespaceMap="namespaceMap" @refresh="fetchData" class="ml-3" />
  10. </template>
  11. </page-list>
  12. </template>
  13. <script>
  14. import * as R from 'ramda'
  15. import ColumnsMixin from '../mixins/columns'
  16. import SingleActionsMixin from '../mixins/singleActions'
  17. import ClusterNamespace from '@K8S/sections/ClusterNamespace'
  18. import clusterNamespaceMixin from '@K8S/mixins/clusterNamespace'
  19. import expectStatus from '@/constants/expectStatus'
  20. import WindowsMixin from '@/mixins/windows'
  21. import ListMixin from '@/mixins/list'
  22. import { getNameFilter } from '@/utils/common/tableFilter'
  23. export default {
  24. name: 'K8SPersistentvolumeclaimList',
  25. components: {
  26. ClusterNamespace,
  27. },
  28. mixins: [WindowsMixin, ListMixin, ColumnsMixin, SingleActionsMixin, clusterNamespaceMixin],
  29. props: {
  30. id: String,
  31. getParams: {
  32. type: Object,
  33. default: () => ({}),
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. id: this.id,
  40. resource: 'persistentvolumeclaims',
  41. apiVersion: 'v1',
  42. getParams: this.getParams,
  43. filterOptions: {
  44. name: getNameFilter(),
  45. unused: {
  46. label: this.$t('k8s.text_301'),
  47. dropdown: true,
  48. items: [
  49. { label: this.$t('k8s.text_302'), key: false },
  50. { label: this.$t('k8s.text_303'), key: true },
  51. ],
  52. },
  53. },
  54. steadyStatus: {
  55. status: Object.values(expectStatus.k8s_resource).flat(),
  56. },
  57. itemGetParams: {
  58. cluster: '',
  59. namespace: '',
  60. },
  61. }),
  62. groupActions: [
  63. {
  64. label: this.$t('k8s.create'),
  65. permission: 'k8s_persistentvolumeclaims_create',
  66. action: () => {
  67. this.$router.push({ path: '/k8s-persistentvolumeclaim/create' })
  68. },
  69. meta: () => ({
  70. buttonType: 'primary',
  71. }),
  72. },
  73. {
  74. label: this.$t('k8s.text_201'),
  75. permission: 'k8s_persistentvolumeclaims_delete',
  76. action: () => {
  77. const data = this.list.selectedItems
  78. const requestData = {
  79. cluster: data[0].clusterID,
  80. }
  81. const namespace = data[0].namespace
  82. if (namespace) requestData.namespace = namespace
  83. this.createDialog('DeleteResDialog', {
  84. vm: this,
  85. data,
  86. columns: this.columns,
  87. title: this.$t('k8s.text_201'),
  88. name: this.$t('k8s.text_10'),
  89. onManager: this.onManager,
  90. requestData,
  91. })
  92. },
  93. meta: () => {
  94. let validate = true
  95. let tooltip = ''
  96. if (this.list.selectedItems.length > 0) {
  97. const namespaces = this.list.selectedItems.map(v => v.namespace)
  98. const unique = Array.from(new Set(namespaces))
  99. if (unique.length > 1) {
  100. validate = false
  101. tooltip = this.$t('k8s.text_203')
  102. }
  103. if (this.list.selectedItems.some(item => item.mountedBy && item.mountedBy.length !== 0)) {
  104. validate = false
  105. tooltip = this.$t('k8s.text_304')
  106. }
  107. } else {
  108. validate = false
  109. tooltip = this.$t('k8s.text_204')
  110. }
  111. return {
  112. validate,
  113. tooltip,
  114. }
  115. },
  116. },
  117. ],
  118. }
  119. },
  120. methods: {
  121. handleOpenSidepage (row) {
  122. this.sidePageTriggerHandle(this, 'K8SPersistentvolumeclaimSidePage', {
  123. id: row.id,
  124. resource: 'persistentvolumeclaims',
  125. getParams: () => {
  126. const params = R.clone(this.list.getParams)
  127. if (row.namespace) {
  128. params.namespace = row.namespace
  129. if (params.all_namespace) delete params.all_namespace
  130. }
  131. return params
  132. },
  133. apiVersion: 'v1',
  134. steadyStatus: {
  135. status: Object.values(expectStatus.k8s_resource).flat(),
  136. },
  137. }, {
  138. list: this.list,
  139. })
  140. },
  141. },
  142. }
  143. </script>