index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <base-side-page
  3. @cancel="cancelSidePage"
  4. :title="$t('helm.text_77')"
  5. icon="res-vm-release"
  6. :res-name="detailData.name"
  7. :actions="params.actions"
  8. :current-tab="params.windowData.currentTab"
  9. :tabs="detailTabs"
  10. :loaded="loaded"
  11. @tab-change="handleTabChange">
  12. <template v-slot:actions>
  13. <actions :options="singleActions" :row="detailData" button-type="link" button-size="small" />
  14. </template>
  15. <component
  16. :is="params.windowData.currentTab"
  17. :res-id="data.id"
  18. :data="detailData"
  19. :onManager="onManager"
  20. resource="releases"
  21. :getParams="getParams"
  22. :fetchData="fetchData"
  23. :responseData="responseData"
  24. :showSearchbox="false"
  25. :showGroupActions="false"
  26. :getResponseData="fetchData" />
  27. </base-side-page>
  28. </template>
  29. <script>
  30. import * as R from 'ramda'
  31. import K8s_ansibleplaybook from '@Helm/views/k8s-ansibleplaybook/components/List'
  32. import SidePageMixin from '@/mixins/sidePage'
  33. import WindowsMixin from '@/mixins/windows'
  34. import Actions from '@/components/PageList/Actions'
  35. import ColumnsMixin from '../mixins/columns'
  36. import SingleActionsMixin from '../mixins/singleActions'
  37. import Virtualmachine from './Virtualmachine'
  38. import Detail from './Detail'
  39. export default {
  40. name: 'VmReleaseSidePage',
  41. components: {
  42. Actions,
  43. Detail,
  44. Virtualmachine,
  45. K8s_ansibleplaybook,
  46. },
  47. mixins: [SidePageMixin, WindowsMixin, ColumnsMixin, SingleActionsMixin],
  48. data () {
  49. return {
  50. timer: null,
  51. }
  52. },
  53. computed: {
  54. detailTabs () {
  55. const detailTabs = [{ label: this.$t('helm.text_78'), key: 'detail' }]
  56. if (!this.detailData.resources) return detailTabs
  57. const allResourceArr = [
  58. { label: this.$t('dictionary.server'), key: 'virtualmachine' },
  59. { label: this.$t('dictionary.ansibleplaybook'), key: 'k8s_ansibleplaybook' },
  60. ]
  61. allResourceArr.forEach(item => {
  62. const resource = item.key
  63. if (R.is(Array, this.detailData.resources[resource])) {
  64. detailTabs.push(item)
  65. }
  66. })
  67. detailTabs.push({ label: this.$t('dictionary.actions'), key: 'event-drawer' })
  68. return detailTabs
  69. },
  70. responseData () {
  71. const data = {
  72. data: [],
  73. }
  74. if (this.detailData.resources && this.params.windowData.currentTab) {
  75. data.data = this.detailData.resources[this.params.windowData.currentTab]
  76. }
  77. return data
  78. },
  79. getParams () {
  80. return {
  81. namespace: this.detailData.namespace,
  82. cluster: this.detailData.clusterID,
  83. }
  84. },
  85. },
  86. watch: {
  87. detailTabs (val) {
  88. if (!val.find(v => v.key === this.params.windowData.currentTab)) {
  89. this.params.windowData.currentTab = this.detailTabs.length ? this.detailTabs[0].key : ''
  90. }
  91. },
  92. },
  93. destroyed () {
  94. clearTimeout(this.timer)
  95. this.timer = null
  96. },
  97. methods: {
  98. fetchDataCallback () {
  99. if (R.is(Object, this.detailData.resources)) {
  100. clearTimeout(this.timer)
  101. this.timer = null
  102. const stableStatusMap = {
  103. virtualmachine: 'Running',
  104. k8s_ansibleplaybook: 'Finished',
  105. }
  106. const virtualmachineList = this.detailData.resources.virtualmachine || []
  107. const ansibleplaybookList = this.detailData.resources.k8s_ansibleplaybook || []
  108. const isStable1 = virtualmachineList.every(val => val.status === stableStatusMap.virtualmachine)
  109. const isStable2 = ansibleplaybookList.every(val => val.status === stableStatusMap.k8s_ansibleplaybook)
  110. if (!isStable1 || !isStable2) {
  111. this.timer = setTimeout(() => {
  112. this.fetchData()
  113. }, 10000)
  114. }
  115. }
  116. },
  117. },
  118. }
  119. </script>