index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. :edit="edit">
  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: 'NumberCard',
  31. components: {
  32. Server,
  33. K8s,
  34. },
  35. props: {
  36. options: {
  37. type: Object,
  38. required: true,
  39. },
  40. params: Object,
  41. edit: Boolean,
  42. },
  43. data () {
  44. const typeOps = []
  45. if (hasSetupKey(['onestack', 'openstack', 'dstack', 'zstack', 'public', 'vmware', 'bill'])) {
  46. typeOps.push({ key: 'server', label: this.$t('dashboard.text_25') })
  47. }
  48. if (hasSetupKey(['k8s'])) {
  49. typeOps.push({ key: 'k8s', label: this.$t('dashboard.text_26') })
  50. }
  51. return {
  52. type: (this.params && this.params.type) || 'server',
  53. typeOpts: typeOps,
  54. visible: false,
  55. formItemLayout: {
  56. wrapperCol: {
  57. span: 18,
  58. },
  59. labelCol: {
  60. span: 6,
  61. },
  62. },
  63. }
  64. },
  65. watch: {
  66. visible (v) {
  67. if (!v) { // 当关闭抽屉的时候重置type
  68. this.type = (this.params && this.params.type) || 'server'
  69. }
  70. },
  71. },
  72. methods: {
  73. update (...ret) {
  74. this.$emit('update', ...ret)
  75. },
  76. refresh () {
  77. return this.$refs.usage.refresh()
  78. },
  79. },
  80. }
  81. </script>