index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div>
  3. <a-form-item class="mb-0">
  4. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorator.backupEnable" @change="change" :disabled="switchDisabled" />
  5. </a-form-item>
  6. <a-form-item class="mt-2" v-if="backupEnable && !isProjectMode">
  7. <base-select
  8. v-decorator="decorator.backup"
  9. :options="hostList"
  10. :select-props="{ placeholder: $t('compute.text_117') }"
  11. :disabled-items="disabledItems" />
  12. </a-form-item>
  13. </div>
  14. </template>
  15. <script>
  16. import { mapGetters } from 'vuex'
  17. import * as R from 'ramda'
  18. export default {
  19. name: 'Backup',
  20. props: {
  21. decorator: {
  22. type: Object,
  23. required: true,
  24. validator: val => R.is(Array, val.backupEnable) && R.is(Array, val.backup),
  25. },
  26. disabledItems: {
  27. type: Array,
  28. default: () => [],
  29. },
  30. diskType: { // 系统盘磁盘类型
  31. type: String,
  32. },
  33. domain: Object,
  34. availableHostCount: Number, // 可用的宿主机数量
  35. hostParams: {
  36. type: Object,
  37. },
  38. },
  39. data () {
  40. return {
  41. hostList: [],
  42. backupEnable: this.decorator.backupEnable[1].initialValue,
  43. }
  44. },
  45. computed: {
  46. ...mapGetters(['isProjectMode']),
  47. switchDisabled () {
  48. if (this.diskType === 'gpfs') return true
  49. if (this.availableHostCount < 2) return true
  50. return false
  51. },
  52. },
  53. watch: {
  54. backupEnable: {
  55. handler (val) {
  56. if (val) this.fetchBackupHosts()
  57. },
  58. immediate: true,
  59. },
  60. },
  61. methods: {
  62. change (val) {
  63. this.backupEnable = val
  64. },
  65. async fetchBackupHosts () {
  66. if (!R.is(Object, this.hostParams) || this.isProjectMode) return
  67. try {
  68. const { data: { data = [] } } = await new this.$Manager('hosts', 'v2').list({ params: this.hostParams })
  69. this.hostList = data
  70. } catch (error) {
  71. throw error
  72. }
  73. },
  74. },
  75. }
  76. </script>