ResourcesStatistics.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <detail
  3. :data="data"
  4. :base-info="baseInfo"
  5. :on-manager="onManager"
  6. :extra-info="extraInfo"
  7. :hiddenKeys="['id', 'name', 'status', 'project_domain', 'tenant', 'created_at', 'updated_at']"
  8. :showDesc="false" />
  9. </template>
  10. <script>
  11. import { RESOURCES_MAP } from '../../policy/constants'
  12. import { transformLabel } from '../../policy/utils'
  13. const RESOURCES_BASE = {
  14. servers: {},
  15. disks: {},
  16. images: {},
  17. snapshots: {},
  18. snapshotpolicies: {},
  19. secgroups: {},
  20. networks: {},
  21. eips: {},
  22. route_tables: {},
  23. dnsrecords: {},
  24. externalprojects: {},
  25. }
  26. const RESOURCES_LOAD = {
  27. loadbalancers: {},
  28. loadbalancerlisteners: {},
  29. loadbalancerlistenerrules: {},
  30. hosts: {},
  31. loadbalancerbackendgroups: {},
  32. loadbalanceracls: {},
  33. loadbalancercertificates: {},
  34. }
  35. export default {
  36. name: 'ProjectResourcesStatistics',
  37. props: {
  38. data: {
  39. type: Object,
  40. required: true,
  41. },
  42. onManager: {
  43. type: Function,
  44. required: true,
  45. },
  46. },
  47. data () {
  48. return {}
  49. },
  50. computed: {
  51. extResources () {
  52. return this.data.ext_resource ? this.data.ext_resource : {}
  53. },
  54. baseInfo () {
  55. const arr = []
  56. Object.keys(RESOURCES_BASE).map((key) => {
  57. arr.push({
  58. field: key,
  59. title: transformLabel(RESOURCES_MAP[key]) || key,
  60. formatter: () => {
  61. return this.extResources[key] ? this.$t('system.text_459', [this.extResources[key]]) : this.$t('system.text_460')
  62. },
  63. })
  64. })
  65. return arr
  66. },
  67. extraInfo () {
  68. if (!this.extResources) {
  69. return null
  70. }
  71. const otherRes = {
  72. title: this.$t('system.text_461'),
  73. items: (() => {
  74. const itmes = []
  75. Object.keys(this.extResources).forEach((key) => {
  76. if (!RESOURCES_BASE[key] && !RESOURCES_LOAD[key]) {
  77. itmes.push({
  78. field: key,
  79. title: transformLabel(RESOURCES_MAP[key]) || key,
  80. formatter: () => {
  81. return this.extResources[key] ? this.$t('system.text_459', [this.extResources[key]]) : this.$t('system.text_460')
  82. },
  83. })
  84. }
  85. })
  86. return itmes
  87. })(),
  88. }
  89. const resItems = [
  90. {
  91. title: this.$t('system.text_462'),
  92. items: Object.keys(RESOURCES_LOAD).map((key) => {
  93. return {
  94. field: key,
  95. title: transformLabel(RESOURCES_MAP[key]) || key,
  96. formatter: () => {
  97. return this.extResources[key] ? this.$t('system.text_459', [this.extResources[key]]) : this.$t('system.text_460')
  98. },
  99. }
  100. }),
  101. },
  102. ]
  103. if (otherRes.children && otherRes.children.length > 0) {
  104. resItems.push(otherRes)
  105. }
  106. return resItems
  107. },
  108. },
  109. }
  110. </script>