index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <component
  3. ref="usage"
  4. :is="type"
  5. :type="type"
  6. :visible.sync="visible"
  7. :formItemLayout="formItemLayout"
  8. :options="options"
  9. @update="update"
  10. :params="params"
  11. :dataRangeParams="dataRangeParams">
  12. <a-row class="mb-4">
  13. <a-col :span="formItemLayout.labelCol.span" class="ant-form-item-label">
  14. <label>{{$t('dashboard.text_24')}}</label>
  15. </a-col>
  16. <a-col :span="formItemLayout.wrapperCol.span">
  17. <a-radio-group v-model="type">
  18. <a-radio-button v-for="item in typeOpts" :key="item.key" :value="item.key">{{ item.label }}</a-radio-button>
  19. </a-radio-group>
  20. </a-col>
  21. </a-row>
  22. <template v-slot:actions="{ handleEdit }"><slot name="actions" :handleEdit="handleEdit" /></template>
  23. </component>
  24. </template>
  25. <script>
  26. import { hasSetupKey } from '@/utils/auth'
  27. import Server from './components/Server'
  28. import K8s from './components/K8s'
  29. export default {
  30. name: 'Ring',
  31. components: {
  32. Server,
  33. K8s,
  34. },
  35. props: {
  36. options: {
  37. type: Object,
  38. required: true,
  39. },
  40. params: Object,
  41. dataRangeParams: {
  42. type: Object,
  43. },
  44. },
  45. data () {
  46. const typeOps = []
  47. if (hasSetupKey(['onestack', 'openstack', 'dstack', 'zstack', 'public', 'vmware', 'bill'])) {
  48. typeOps.push({ key: 'server', label: this.$t('dashboard.text_25') })
  49. }
  50. if (hasSetupKey(['k8s'])) {
  51. typeOps.push({ key: 'k8s', label: this.$t('dashboard.text_26') })
  52. }
  53. return {
  54. type: (this.params && this.params.type) || 'server',
  55. typeOpts: typeOps,
  56. formItemLayout: {
  57. wrapperCol: {
  58. span: 18,
  59. },
  60. labelCol: {
  61. span: 6,
  62. },
  63. },
  64. visible: false,
  65. }
  66. },
  67. watch: {
  68. visible (v) {
  69. if (!v) { // 当关闭抽屉的时候重置type
  70. this.type = (this.params && this.params.type) || 'server'
  71. }
  72. },
  73. },
  74. methods: {
  75. refresh () {
  76. return this.$refs.usage.refresh()
  77. },
  78. update (...ret) {
  79. this.$emit('update', ...ret)
  80. },
  81. },
  82. }
  83. </script>