index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <div class="d-flex">
  3. <div>
  4. <span>{{$t('k8s.text_28')}}</span>
  5. <cluster-select
  6. :value="cluster"
  7. @input="clusterChange"
  8. style="width: 140px;" />
  9. </div>
  10. <div class="ml-2" v-if="!ignoreNamespace">
  11. <span>{{$t('k8s.text_29')}}</span>
  12. <namespace-select
  13. :value="namespace"
  14. @input="setNamespace"
  15. :cluster="cluster"
  16. :support-all-namespace="true"
  17. :namespaceMap="namespaceMap"
  18. size="small"
  19. style="width: 140px;" />
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. import * as R from 'ramda'
  25. import { mapState, mapMutations } from 'vuex'
  26. import ClusterSelect from '@K8S/sections/ClusterSelect'
  27. import NamespaceSelect from '@K8S/sections/NamespaceSelect'
  28. export default {
  29. name: 'K8SClusterNamespace',
  30. components: {
  31. ClusterSelect,
  32. NamespaceSelect,
  33. },
  34. props: {
  35. getParams: {
  36. type: Object,
  37. default: () => ({}),
  38. },
  39. ignoreNamespace: {
  40. type: Boolean,
  41. default: false,
  42. },
  43. namespaceMap: {
  44. type: Object,
  45. },
  46. },
  47. computed: {
  48. ...mapState('common', {
  49. cluster: state => state.k8s.cluster,
  50. namespace: state => state.k8s.namespace,
  51. }),
  52. },
  53. watch: {
  54. cluster () {
  55. this.paramsChange()
  56. },
  57. namespace () {
  58. this.paramsChange()
  59. },
  60. },
  61. mounted () {
  62. this.paramsChange()
  63. },
  64. methods: {
  65. ...mapMutations('common', {
  66. setCluster: 'SET_K8S_CLUSTER',
  67. setNamespace: 'SET_K8S_NAMESPACE',
  68. }),
  69. clusterChange (val) {
  70. if (this.namespace !== 'all_namespace' && !this.ignoreNamespace) {
  71. this.setNamespace('all_namespace')
  72. }
  73. this.setCluster(val)
  74. },
  75. paramsChange () {
  76. const listParams = R.clone(R.is(Function, this.getParams) ? this.getParams() : this.getParams)
  77. delete listParams.cluster
  78. delete listParams.namespace
  79. const params = {
  80. ...listParams,
  81. details: true,
  82. cluster: this.cluster,
  83. }
  84. if (this.namespace) {
  85. if (this.namespace === 'all_namespace') {
  86. delete params.namespace
  87. } else {
  88. params.namespace = this.namespace
  89. delete params.all_namespace
  90. }
  91. }
  92. this.$emit('update:getParams', params)
  93. this.$emit('refresh')
  94. },
  95. },
  96. }
  97. </script>