index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div>
  3. <a-form-item :label="$t('dashboard.text_96')" v-if="decorators.all_usage_key">
  4. <usage-select
  5. class="w-100"
  6. v-decorator="decorators.all_usage_key"
  7. :usages="allUsages"
  8. @change="allUsageChange" />
  9. <div slot="extra" v-if="showDocsLink()">
  10. <i18n path="metricConfig.create_form.all_usage_extra">
  11. <template #link>
  12. <help-link :href="metricDoc">{{$t('metricConfig.create_form.all_usage_link')}}</help-link>
  13. </template>
  14. </i18n>
  15. </div>
  16. </a-form-item>
  17. <a-form-item :label="usageLabel || $t('dashboard.text_97')" v-if="decorators.usage_key">
  18. <usage-select
  19. class="w-100"
  20. v-decorator="decorators.usage_key"
  21. :usages="usages"
  22. @change="usageChange" />
  23. <div slot="extra">
  24. <i18n :path="usageLabel?'metricConfig.create_form.metric_extra':'metricConfig.create_form.usage_extra'">
  25. <template #link>
  26. <help-link :href="metricDoc">{{$t('metricConfig.create_form.usage_link')}}</help-link>
  27. </template>
  28. </i18n>
  29. </div>
  30. </a-form-item>
  31. <a-form-item :label="$t('dashboard.usage_metric_name')" class="mb-0" v-if="decorators.usage_label">
  32. <a-form-item :wrapperCol="{ span: 24 }">
  33. <a-input class="w-100" v-decorator="decorators.usage_label" />
  34. </a-form-item>
  35. </a-form-item>
  36. <a-form-item :label="$t('dashboard.remaining_usage_metric_name')" class="mb-0" v-if="decorators.un_usage_label">
  37. <a-form-item :wrapperCol="{ span: 24 }">
  38. <a-input class="w-100" v-decorator="decorators.un_usage_label" />
  39. </a-form-item>
  40. </a-form-item>
  41. </div>
  42. </template>
  43. <script>
  44. import { mapGetters } from 'vuex'
  45. import { K8S_USAGE_CONFIG, getMetricDocs } from '@Dashboard/constants'
  46. import UsageSelect from '@Dashboard/sections/QuotaConfig/UsageSelect'
  47. import { showDocsLink } from '@/constants/docs'
  48. export default {
  49. name: 'K8sConfig',
  50. components: {
  51. UsageSelect,
  52. },
  53. props: {
  54. decorators: {
  55. type: Object,
  56. required: true,
  57. },
  58. fc: {
  59. type: Object,
  60. required: true,
  61. },
  62. fd: {
  63. type: Object,
  64. required: false,
  65. },
  66. usageLabel: String,
  67. },
  68. data () {
  69. return {
  70. showDocsLink,
  71. translateUsage: this.$t('k8s_usage'),
  72. metricDoc: getMetricDocs(this.$store.getters.scope),
  73. }
  74. },
  75. computed: {
  76. ...mapGetters(['scope']),
  77. allUsages () {
  78. const ret = []
  79. for (const key in K8S_USAGE_CONFIG) {
  80. if (K8S_USAGE_CONFIG[key].isOnlyAllPartKey && K8S_USAGE_CONFIG[key].scope === this.scope) {
  81. ret.push({
  82. key,
  83. scope: K8S_USAGE_CONFIG[key].scope,
  84. label: this.translateUsage[key] ? this.translateUsage[key] : key,
  85. })
  86. }
  87. }
  88. return ret
  89. },
  90. usages () {
  91. const ret = []
  92. const allUsageKey = this.fd?.all_usage_key || ''
  93. for (const key in K8S_USAGE_CONFIG) {
  94. const { isOnlyAllPartKey, belongAllPartKeys } = K8S_USAGE_CONFIG[key]
  95. if (!isOnlyAllPartKey && belongAllPartKeys && belongAllPartKeys.includes(allUsageKey) && K8S_USAGE_CONFIG[key].scope === this.scope) {
  96. ret.push({
  97. key,
  98. scope: K8S_USAGE_CONFIG[key].scope,
  99. label: this.translateUsage[key] ? this.translateUsage[key] : key,
  100. belongAllPartKeys: K8S_USAGE_CONFIG[key].belongAllPartKeys,
  101. })
  102. }
  103. }
  104. if (!ret.length && this.decorators.usage_key && !this.decorators.all_usage_key) {
  105. return this.allUsages
  106. }
  107. return ret
  108. },
  109. },
  110. methods: {
  111. allUsageChange (allUsage) {
  112. this.$emit('update:all_usage_key', allUsage)
  113. },
  114. usageChange (usage) {
  115. this.$emit('update:usage_key', usage)
  116. },
  117. },
  118. }
  119. </script>