clusterNamespace.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import * as R from 'ramda'
  2. import ClusterNamespace from '@K8S/sections/ClusterNamespace'
  3. export default {
  4. components: {
  5. ClusterNamespace,
  6. },
  7. inject: {
  8. // 是否处于SidePage中
  9. inBaseSidePage: {
  10. default: false,
  11. },
  12. },
  13. computed: {
  14. noDataText () {
  15. const { cluster, namespace } = this.list.getParams
  16. if (!cluster && !namespace) return this.$t('common_461')
  17. return this.$t('common.notData')
  18. },
  19. },
  20. data () {
  21. return {
  22. namespaceMap: {},
  23. }
  24. },
  25. methods: {
  26. async fetchAllNamespaceData () {
  27. if (this.inBaseSidePage) return
  28. const params = R.clone(this.list.getParams)
  29. params.scope = this.$store.getters.scope
  30. params.limit = 0
  31. delete params.namespace
  32. this.namespaceMap = {}
  33. try {
  34. const { data: { data = [] } } = await this.list.manager.list({
  35. params,
  36. ctx: this.list.ctx,
  37. })
  38. const map = {}
  39. data.forEach(val => {
  40. if (!map[val.namespace_id]) {
  41. map[val.namespace_id] = []
  42. }
  43. map[val.namespace_id].push(val)
  44. })
  45. this.namespaceMap = map
  46. } catch (error) {
  47. throw error
  48. }
  49. },
  50. async fetchData () {
  51. if (this.list.getParams.cluster) {
  52. await this.list.fetchData()
  53. if (R.isEmpty(this.namespaceMap)) this.fetchAllNamespaceData()
  54. }
  55. },
  56. },
  57. }