ContainerRegistry.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions" />
  7. </template>
  8. <script>
  9. import { uuid } from '@/utils/utils'
  10. export default {
  11. name: 'ContainerRegistry',
  12. props: {
  13. id: String,
  14. resId: String,
  15. getParams: {
  16. type: Object,
  17. default: () => ({}),
  18. },
  19. },
  20. data () {
  21. return {
  22. list: this.$list.createList(this, {
  23. id: 'containerRegistryListId',
  24. resource: () => this.fetchData(),
  25. getParams: this.getParams,
  26. filterOptions: {
  27. repository_name: {
  28. label: this.$t('k8s.repo.image.name'),
  29. },
  30. },
  31. }),
  32. columns: [
  33. {
  34. field: 'name',
  35. title: this.$t('k8s.repo.image.name'),
  36. width: 240,
  37. slots: {
  38. default: ({ row }, h) => {
  39. return row.name
  40. },
  41. },
  42. },
  43. {
  44. field: 'version',
  45. title: this.$t('k8s.repo.image.tag'),
  46. minWidth: 220,
  47. slots: {
  48. default: ({ row }) => {
  49. if (this.isPreLoad && !row.tags) return [<data-loading />]
  50. const len = (row.tags && row.tags.length) || 0
  51. if (len === 0) return this.$t('k8s.repo.image.tag_empty')
  52. const list = row.tags.map(v => <a-tag class='mr-1'>{ v }</a-tag>)
  53. return [<list-body-cell-popover text={this.$t('compute.text_619', [len])} max-width="400px">
  54. <div style="display: inline-flex; flex-wrap: wrap; max-width: 40vw;">
  55. {...list}
  56. </div>
  57. </list-body-cell-popover>]
  58. },
  59. },
  60. },
  61. ],
  62. groupActions: [],
  63. }
  64. },
  65. created () {
  66. this.list.fetchData()
  67. },
  68. methods: {
  69. async fetchTagByName (name) {
  70. try {
  71. const result = await new this.$Manager('container_registries')
  72. .getSpecific({
  73. id: this.resId,
  74. spec: 'image-tags',
  75. params: {
  76. $t: uuid(),
  77. repository: name,
  78. },
  79. })
  80. return Promise.resolve(result.data)
  81. } catch (error) {
  82. return Promise.reject(error)
  83. }
  84. },
  85. async fetchData () {
  86. const response = { data: {} }
  87. try {
  88. const result = await new this.$Manager('container_registries')
  89. .getSpecific({
  90. id: this.resId,
  91. spec: 'images',
  92. params: {
  93. ...this.list.params,
  94. },
  95. })
  96. const repositories = result?.data?.repositories || []
  97. const repos = repositories.map((item, key) => {
  98. return {
  99. id: key,
  100. name: item,
  101. tags: [],
  102. }
  103. })
  104. const allPromise = repos.map(item => {
  105. return this.fetchTagByName(item.name)
  106. })
  107. const tagMap = await Promise.allSettled(allPromise).then((values) => {
  108. const tagMap = new Map()
  109. values.forEach(({ status, value }) => {
  110. if (status === 'fulfilled') {
  111. tagMap.set(value.name, value.tags)
  112. }
  113. })
  114. return Promise.resolve(tagMap)
  115. })
  116. response.data.data = repos.map(item => {
  117. return {
  118. ...item,
  119. tags: tagMap.get(item.name),
  120. }
  121. })
  122. } catch (error) {
  123. throw error
  124. }
  125. return response
  126. },
  127. },
  128. }
  129. </script>