List.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 WindowsMixin from '@/mixins/windows'
  20. import ListMixin from '@/mixins/list'
  21. import { getNameFilter } from '@/utils/common/tableFilter'
  22. import expectStatus from '@/constants/expectStatus'
  23. export default {
  24. name: 'K8SIngressList',
  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: 'ingresses',
  41. apiVersion: 'v1',
  42. getParams: this.getParams,
  43. filterOptions: {
  44. name: getNameFilter(),
  45. },
  46. steadyStatus: {
  47. status: Object.values(expectStatus.k8s_resource).flat(),
  48. },
  49. }),
  50. groupActions: [
  51. {
  52. label: this.$t('k8s.create'),
  53. permission: 'k8s_ingresses_create',
  54. action: () => {
  55. this.$router.push({ path: '/k8s-ingress/create' })
  56. },
  57. meta: () => ({
  58. buttonType: 'primary',
  59. }),
  60. },
  61. {
  62. label: this.$t('k8s.text_201'),
  63. permission: 'k8s_ingresses_delete',
  64. action: () => {
  65. const data = this.list.selectedItems
  66. const requestData = {
  67. cluster: data[0].clusterID,
  68. }
  69. const namespace = data[0].namespace
  70. if (namespace) requestData.namespace = namespace
  71. this.createDialog('DeleteResDialog', {
  72. vm: this,
  73. data,
  74. columns: this.columns,
  75. title: this.$t('k8s.text_201'),
  76. name: this.$t('k8s.text_8'),
  77. onManager: this.onManager,
  78. requestData,
  79. })
  80. },
  81. meta: () => {
  82. let validate = true
  83. let tooltip = ''
  84. if (this.list.selectedItems.length > 0) {
  85. const namespaces = this.list.selectedItems.map(v => v.namespace)
  86. const unique = Array.from(new Set(namespaces))
  87. if (unique.length > 1) {
  88. validate = false
  89. tooltip = this.$t('k8s.text_203')
  90. }
  91. } else {
  92. validate = false
  93. tooltip = this.$t('k8s.text_204')
  94. }
  95. return {
  96. validate,
  97. tooltip,
  98. }
  99. },
  100. },
  101. ],
  102. }
  103. },
  104. methods: {
  105. handleOpenSidepage (row) {
  106. this.sidePageTriggerHandle(this, 'K8SIngressSidePage', {
  107. id: row.id,
  108. resource: 'ingresses',
  109. getParams: () => {
  110. const params = R.clone(this.list.getParams)
  111. if (row.namespace) {
  112. params.namespace = row.namespace
  113. if (params.all_namespace) delete params.all_namespace
  114. }
  115. return params
  116. },
  117. apiVersion: 'v1',
  118. }, {
  119. list: this.list,
  120. })
  121. },
  122. },
  123. }
  124. </script>