ResCommon.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="res-container d-flex justify-content-center align-items-center" :class="{'is-exist': isExist, 'res-container-host': showSchedTag, 'res-last': isLast}">
  3. <span class="line" :class="{'full': multiple}" />
  4. <div :class="{'common-left-line': showLeftLine}" />
  5. <div class="res d-flex" :class="{'res-host': showSchedTag, 'res-running': type === 'vminstance' && ((resSource.status || resSource.status) === 'running')}">
  6. <a-tooltip placement="top" :get-popup-container="getPopupContainer">
  7. <template slot="title">
  8. <p class="title">{{ $t('network.topology.res_type.' + getType(resSource)) }}</p>
  9. <p>{{ $t('common.name') }}:{{ getName(resSource) }}</p>
  10. <p v-if="type !== 'gpu'">{{ $t('common.status') }}:{{ getStatus(resSource) }}</p>
  11. <template v-if="type === 'vminstance'">
  12. <p>{{ $t('network.waf.rule_ip') }}:{{ resSource.ip_addr }}</p>
  13. </template>
  14. <template v-else-if="type === 'lb'">
  15. <p>{{ $t('network.text_248') }}:{{ resSource.ip_addr }}</p>
  16. </template>
  17. <template v-else-if="type === 'host'">
  18. <p v-for="(obj, idx) in resSource.networks" :key="idx">{{ $t('network.waf.rule_ip') }}:{{ obj.ip_addr }}</p>
  19. <div v-for="(obj, idx) in resSource.storages" :key="idx">
  20. <p>{{ `${$t('network.text_708')}${$t('common.name')}`}}:{{obj.name}}</p>
  21. <p>{{$t('storage.text_38')}}:{{getStorageType(obj.storage_type)}}</p>
  22. <p>{{$t('storage.text_155')}}:{{getStorageSize(obj.capacity_mb)}}</p>
  23. </div>
  24. </template>
  25. <template v-else-if="type === 'baremetal'">
  26. <p v-for="(obj, idx) in resSource.networks" :key="idx">{{ $t('network.waf.rule_ip') }}:{{ obj.ip_addr }}</p>
  27. </template>
  28. <template v-if="showSchedTag && resSchedTags.length">
  29. <p>{{ $t('dictionary.schedtag') }}:</p>
  30. <div class="tag-list d-flex align-items-center flex-wrap">
  31. <template v-for="(item,index) in resSchedTags">
  32. <div class="tag" :key="index" :style="{background: item.background}">{{item.name}}</div>
  33. </template>
  34. </div>
  35. </template>
  36. <p v-for="(obj, idx) in extraShowList" :key="idx">{{ obj.label }}:{{ obj.value }}</p>
  37. </template>
  38. <div class="d-flex">
  39. <icon v-if="!showSchedTag && !showStorage" :type="iconType" />
  40. <div v-else class="res-box;">
  41. <icon :type="iconType" class="mt-2 mb-1" style="border:none;font-size:40px;" />
  42. <div class="tag-list tag-list-limit d-flex align-items-center flex-wrap justify-content-center">
  43. <template v-if="showStorageTag">
  44. <div v-for="(item,index) in resStorages" class="tag storage-tag" :key="index" :style="{background: item.background}">{{item.name}}</div>
  45. </template>
  46. <template v-for="(item,index) in resSchedTags">
  47. <div class="tag" :key="index" :style="{background: item.background}" v-if="index<2">{{item.name}}</div>
  48. </template>
  49. </div>
  50. </div>
  51. <div class="d-flex align-items-center">
  52. <span class="name text-truncate ml-1 pt-2">{{ getName(resSource) }}</span>
  53. </div>
  54. </div>
  55. </a-tooltip>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import ResMixin from '@Network/sections/Topology/ResMixin'
  61. import { sizestr } from '@/utils/utils'
  62. import { STORAGE_TYPES } from '@Storage/constants/index.js'
  63. import { STATUS_MAP, COLORS } from './constants'
  64. export default {
  65. name: 'ResCommon',
  66. mixins: [ResMixin],
  67. props: {
  68. dataSource: Object,
  69. multiple: Boolean,
  70. type: String,
  71. isExist: Boolean,
  72. schedTagColorsMap: Object,
  73. showStorageTag: {
  74. type: Boolean,
  75. default: false,
  76. },
  77. isLast: {
  78. type: Boolean,
  79. default: false,
  80. },
  81. extraShowList: {
  82. type: Array,
  83. default: () => [],
  84. },
  85. showLeftLine: {
  86. type: Boolean,
  87. default: false,
  88. },
  89. },
  90. data () {
  91. return {}
  92. },
  93. computed: {
  94. showSchedTag () {
  95. return this.type === 'host' || this.type === 'baremetal'
  96. },
  97. showStorage () {
  98. return this.type === 'host'
  99. },
  100. iconType () {
  101. return `res-${this.type}`
  102. },
  103. resSource () {
  104. return this.dataSource || {}
  105. },
  106. resSchedTags () {
  107. const tags = []
  108. const { schedtags = [] } = this.resSource
  109. schedtags.map((item, index) => {
  110. const tag = {
  111. name: item.name,
  112. background: '#ccc',
  113. }
  114. if (this.schedTagColorsMap && this.schedTagColorsMap[item.name]) {
  115. tag.background = this.schedTagColorsMap[item.name]
  116. }
  117. tags.push(tag)
  118. })
  119. tags.sort((a, b) => {
  120. return a.name.length - b.name.length
  121. })
  122. return tags
  123. },
  124. resStorages () {
  125. const { storages = [] } = this.resSource
  126. const localStorage = []
  127. storages.forEach((item, idx) => {
  128. if (item.storage_type === 'local') {
  129. localStorage.push({
  130. name: item.name,
  131. background: COLORS[idx % 8],
  132. })
  133. }
  134. })
  135. return localStorage
  136. },
  137. },
  138. methods: {
  139. getStatus ({ status, owner_status }) {
  140. if (!status && !owner_status) return this.$t('common.text00001')
  141. return this.$t(`status.${STATUS_MAP[this.type] || this.type}.${status || owner_status}`)
  142. },
  143. getName ({ owner, name }) {
  144. return owner || name
  145. },
  146. getType ({ owner_type, host_type }) {
  147. return owner_type || host_type
  148. },
  149. getStorageType (type) {
  150. return STORAGE_TYPES[type] || type
  151. },
  152. getStorageSize (size) {
  153. return sizestr(size, 'M', 1024)
  154. },
  155. },
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. // @import "@Network/sections/Topology/index.scss";
  160. </style>