HostAttachBackupStorageDialog.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{this.params.title}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.blockstorage')" :count="params.data.length" :action="this.params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('storage.text_50')">
  9. <a-select :loading="hostsLoading" allowClear showSearch :filterOption="filterOption" mode="multiple" v-decorator="decorators.host" :placeholder="$t('storage.text_51')">
  10. <a-select-option v-for="item in hosts" :key="item.id" :value="item.id">{{item.name}}</a-select-option>
  11. </a-select>
  12. </a-form-item>
  13. </a-form>
  14. </div>
  15. <div slot="footer">
  16. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t("dialog.ok") }}</a-button>
  17. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  18. </div>
  19. </base-dialog>
  20. </template>
  21. <script>
  22. import DialogMixin from '@/mixins/dialog'
  23. import WindowsMixin from '@/mixins/windows'
  24. export default {
  25. name: 'HostAttachBackupStorageDialog',
  26. mixins: [DialogMixin, WindowsMixin],
  27. data () {
  28. return {
  29. loading: false,
  30. hostsLoading: false,
  31. hosts: [],
  32. form: {
  33. fc: this.$form.createForm(this),
  34. },
  35. formItemLayout: {
  36. labelCol: { span: 4 },
  37. wrapperCol: { span: 20 },
  38. },
  39. }
  40. },
  41. computed: {
  42. decorators () {
  43. return {
  44. host: [
  45. 'host',
  46. {
  47. rules: [
  48. { required: true, message: this.$t('storage.text_54') },
  49. ],
  50. },
  51. ],
  52. }
  53. },
  54. },
  55. created () {
  56. this.queryHostList()
  57. },
  58. methods: {
  59. filterOption (input, option) {
  60. return (
  61. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  62. )
  63. },
  64. async queryHostList () {
  65. const params = { hypervisor: 'kvm', storage_not_attached: true, backupstorage: this.params.data[0].id }
  66. const manager = new this.$Manager('hosts', 'v2')
  67. this.hostsLoading = true
  68. try {
  69. const { data = {} } = await manager.list({ params })
  70. this.hosts = data.data || []
  71. } catch (err) {
  72. throw err
  73. } finally {
  74. this.hostsLoading = false
  75. }
  76. },
  77. async handleConfirm () {
  78. this.loading = true
  79. try {
  80. const values = await this.form.fc.validateFields()
  81. const manager = new this.$Manager('hosts', 'v2')
  82. await manager.batchPerformAction({
  83. ids: values.host,
  84. action: '',
  85. data: values,
  86. ctx: [['backupstorages', this.params.data[0].id]],
  87. })
  88. this.cancelDialog()
  89. this.params.refresh()
  90. this.loading = false
  91. } catch (error) {
  92. this.loading = false
  93. throw error
  94. }
  95. },
  96. },
  97. }
  98. </script>