index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="d-flex res-topology vpc-topology">
  3. <div class="c-left">
  4. <res-wire :dataSource="dataSource" :physical="physical" />
  5. </div>
  6. <div class="c-right" :class="{'res-topology-wire': physical ? !isEmpty(hosts) : !isEmpty(networks)}">
  7. <ul class="list" v-if="physical">
  8. <li class="item d-flex">
  9. <div v-for="(obj, nidx) in hosts" :key="nidx">
  10. <res-common
  11. :type="RES_ICON_MAP[obj.host_type] || obj.host_type"
  12. :dataSource="obj"
  13. :schedTagColorsMap="schedTagColorsMap" />
  14. </div>
  15. </li>
  16. </ul>
  17. <ul class="list" v-else>
  18. <li class="item d-flex" v-for="(network, nidx) in networks" :key="nidx">
  19. <res-ipsubnet :dataSource="network" />
  20. <div v-for="(obj, idx) in getAddress(network)" :key="idx">
  21. <res-common
  22. :type="RES_ICON_MAP[obj.owner_type] || obj.owner_type"
  23. :dataSource="obj"
  24. :isExist="isAddrExist(networks, nidx, obj)" />
  25. </div>
  26. </li>
  27. </ul>
  28. </div>
  29. </div>
  30. </template>
  31. <script>
  32. import ResCommon from '@Network/sections/Topology/ResCommon'
  33. import { RES_ICON_MAP } from '@Network/sections/Topology/constants'
  34. import ResMixin from '@Network/sections/Topology/ResMixin'
  35. import ResWire from '../ResWire'
  36. import ResIpsubnet from '../ResIpsubnet'
  37. const COLORS = ['#E45826', '#874356', '#0E3EDA', '#139487', '#464E2E', '#A1B57D', '#6E3CBC', '#6FB2D2', '#C5D8A4', '#F473B9', '#D18CE0', '#203239']
  38. export default {
  39. name: 'VpcTopology',
  40. components: {
  41. ResWire,
  42. ResCommon,
  43. ResIpsubnet,
  44. },
  45. mixins: [ResMixin],
  46. props: {
  47. physical: Boolean,
  48. dataSource: Object,
  49. },
  50. data () {
  51. return {
  52. RES_ICON_MAP,
  53. }
  54. },
  55. computed: {
  56. networks () {
  57. return this.dataSource?.networks || []
  58. },
  59. hosts () {
  60. return this.dataSource?.hosts || []
  61. },
  62. schedTagColorsMap () {
  63. const ret = {}
  64. let index = 0
  65. const { wires = [], hosts = [] } = this.dataSource
  66. const originWires = wires.length ? wires : [{ hosts }]
  67. originWires.map(wire => {
  68. const { hosts = [] } = wire
  69. hosts.map(host => {
  70. const { schedtags = [] } = host
  71. schedtags.map(schedtag => {
  72. if (schedtag.name && !ret[schedtag.name]) {
  73. ret[schedtag.name] = COLORS[index % COLORS.length]
  74. index++
  75. }
  76. })
  77. })
  78. })
  79. return ret
  80. },
  81. },
  82. methods: {
  83. getMultiple (nidx, resArr, curObj) {
  84. if (this.physical) {
  85. if (resArr[nidx + 1]) {
  86. return resArr[nidx + 1].hosts.some((v, i) => {
  87. if (v.id === undefined || curObj.id === undefined) return false
  88. if (v.id === curObj.id) {
  89. resArr[nidx + 1].hosts[i].hidden = true
  90. }
  91. return v.id === curObj.id
  92. })
  93. }
  94. } else {
  95. if (resArr[nidx + 1]) {
  96. return resArr[nidx + 1].address.some((v, i) => {
  97. if (v.owner_id === undefined || curObj.owner_id === undefined) return false
  98. if (v.owner_id === curObj.owner_id) {
  99. resArr[nidx + 1].address[i].hidden = true
  100. }
  101. return v.owner_id === curObj.owner_id
  102. })
  103. }
  104. }
  105. return false
  106. },
  107. getHost (wire) {
  108. const resTypes = ['hypervisor', 'hosts', 'baremetal', 'esxi']
  109. return wire.hosts?.filter(v => resTypes.includes(v.host_type))
  110. },
  111. getAddress (network) {
  112. const resTypes = ['servers', 'loadbalancers', 'dbinstances']
  113. return network.address?.filter(v => resTypes.includes(v.owner_type))
  114. },
  115. isAddrExist (networks, nidx, addr) {
  116. let isExist = false
  117. // 跨 networks 查找
  118. for (let i = nidx - 1; i >= 0; i--) {
  119. const network = networks[i]
  120. if (network.address && network.address.length > 0) {
  121. const addressArr = this.getAddress(network)
  122. isExist = addressArr.some(v => v.owner_id === addr.owner_id)
  123. }
  124. }
  125. return isExist
  126. },
  127. },
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. // @import "@Network/sections/Topology/index.scss";
  132. </style>