List.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div>
  3. <div class="mb-2">
  4. <span>{{$t('k8s.text_28')}}</span>
  5. <cluster-select
  6. :value="cluster"
  7. @input="setCluster"
  8. style="width: 140px;" />
  9. </div>
  10. <page-card-list
  11. v-if="responseData.length"
  12. :list="list"
  13. :showPageer="false"
  14. :isRefreshed="false"
  15. :card-fields="cardFields"
  16. :group-actions="groupActions"
  17. :single-actions="singleActions" />
  18. <a-alert v-else :message="$t('k8s.text_265')" banner />
  19. </div>
  20. </template>
  21. <script>
  22. import ClusterSelect from '@K8S/sections/ClusterSelect'
  23. import k8sCreateMixin from '@K8S/mixins/create'
  24. import WindowsMixin from '@/mixins/windows'
  25. export default {
  26. name: 'KubeComponentList',
  27. components: {
  28. ClusterSelect,
  29. },
  30. mixins: [WindowsMixin, k8sCreateMixin],
  31. props: {
  32. id: {
  33. type: String,
  34. },
  35. },
  36. data () {
  37. return {
  38. list: this.$list.createList(this, {
  39. id: this.id,
  40. idKey: 'name',
  41. }),
  42. cardFields: {
  43. url: {
  44. formatter: (data) => {
  45. return require(`../assets/images/${data.name.toLowerCase()}${data.name.toLowerCase() === 'cephcsi' ? '.svg' : '.png'}`)
  46. },
  47. },
  48. title: 'name',
  49. content: [{
  50. title: this.$t('k8s.text_266'),
  51. field: 'enabled',
  52. slots: (data) => {
  53. return (<div class='status'>
  54. <status status={ data.enabled } statusModule='enabled' />
  55. </div>)
  56. },
  57. },
  58. {
  59. title: this.$t('k8s.text_35'),
  60. field: 'status',
  61. slots: (data) => {
  62. if (!data.status) {
  63. return (<span>-</span>)
  64. }
  65. return (<div class='status'>
  66. <status status={ data.status } statusModule='kubecomponent' />
  67. </div>)
  68. },
  69. }],
  70. },
  71. groupActions: [],
  72. singleActions: [
  73. {
  74. label: this.$t('k8s.create'),
  75. action: obj => {
  76. this.$router.push({
  77. path: '/k8s-kubecomponent/create',
  78. query: {
  79. kubeComponent: obj.name,
  80. cluster: this.cluster,
  81. },
  82. })
  83. },
  84. meta: (obj) => ({
  85. buttonType: 'primary',
  86. validate: !obj.created,
  87. }),
  88. },
  89. {
  90. label: this.$t('k8s.text_95'),
  91. action: obj => {
  92. this.$router.push({
  93. path: '/k8s-kubecomponent/update',
  94. query: {
  95. kubeComponent: obj.name,
  96. cluster: this.cluster,
  97. },
  98. })
  99. },
  100. meta: (obj) => ({
  101. validate: obj.created,
  102. }),
  103. },
  104. {
  105. label: this.$t('k8s.text_267'),
  106. action: obj => {
  107. return new this.$Manager('kubeclusters', 'v1').performAction({
  108. id: this.cluster,
  109. action: 'disable-component',
  110. data: {
  111. type: obj.name,
  112. },
  113. }).then(() => {
  114. this.fetchData()
  115. }).catch(error => {
  116. throw error
  117. })
  118. },
  119. meta: (obj) => ({
  120. validate: obj.enabled && obj.created,
  121. }),
  122. },
  123. {
  124. label: this.$t('k8s.text_268'),
  125. action: obj => {
  126. return new this.$Manager('kubeclusters', 'v1').performAction({
  127. id: this.cluster,
  128. action: 'enable-component',
  129. data: {
  130. type: obj.name,
  131. },
  132. }).then(() => {
  133. this.fetchData()
  134. }).catch(error => {
  135. throw error
  136. })
  137. },
  138. meta: (obj) => ({
  139. validate: !obj.enabled && obj.created,
  140. }),
  141. },
  142. {
  143. label: this.$t('k8s.text_201'),
  144. action: obj => {
  145. this.createDialog('DeleteResDialog', {
  146. vm: this,
  147. data: [obj],
  148. title: this.$t('k8s.text_201'),
  149. name: obj.name,
  150. ok: (ids, data) => {
  151. return new this.$Manager('kubeclusters', 'v1').performAction({
  152. id: this.cluster,
  153. action: 'delete-component',
  154. data: {
  155. type: obj.name,
  156. },
  157. }).then(() => {
  158. this.fetchData()
  159. return true
  160. }).catch(error => {
  161. throw error
  162. })
  163. },
  164. })
  165. },
  166. meta: obj => ({
  167. validate: obj.created,
  168. }),
  169. },
  170. ],
  171. responseData: [],
  172. timer: null,
  173. }
  174. },
  175. watch: {
  176. cluster () {
  177. this.fetchData()
  178. },
  179. },
  180. created () {
  181. this.manager = new this.$Manager('kubeclusters', 'v1')
  182. this.fetchData()
  183. },
  184. methods: {
  185. async fetchData () {
  186. if (this.cluster) {
  187. const { data } = await this.manager.getSpecific({
  188. id: this.cluster,
  189. spec: 'components-status',
  190. })
  191. this.list.responseData = {
  192. data: [],
  193. }
  194. for (const key in data) {
  195. data[key].name = key
  196. // if (key === 'cephCSI') this.list.responseData.data.push(data[key])
  197. this.list.responseData.data.push(data[key])
  198. this.responseData = this.list.responseData.data
  199. }
  200. this.list.fetchData()
  201. this.getStableStatus(data)
  202. }
  203. },
  204. getStableStatus (data) {
  205. const kubeComponentStatus = ['deployed', 'deploy_fail', 'update_fail', 'delete_fail', 'init']
  206. const statusArr = Object.values(data).map(val => val.status).filter(v => v)
  207. const flatStableStatus = Object.values(kubeComponentStatus)
  208. const notStable = statusArr.some(val => !flatStableStatus.includes(val))
  209. if (notStable) {
  210. this.timer = setTimeout(() => {
  211. this.fetchData()
  212. }, 5000)
  213. } else {
  214. this.timer = null
  215. }
  216. },
  217. },
  218. }
  219. </script>
  220. <style lang="less" scoped>
  221. .status {
  222. display: inline-block;
  223. vertical-align: bottom;
  224. overflow: hidden;
  225. text-overflow: ellipsis;
  226. white-space: nowrap;
  227. }
  228. </style>