List.vue 3.9 KB

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