List.vue 4.0 KB

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