MountUpdateDialog.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.disk_perform_attach')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :count="params.data.length" :action="$t('compute.disk_perform_attach')" :name="$t('dictionary.disk')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc">
  9. <a-form-item :label="$t('dictionary.server')" v-bind="formItemLayout">
  10. <!-- <a-select v-decorator="decorators.server">
  11. <a-select-option v-for="item in serversOpts" :key="item.id">
  12. {{item.name}}
  13. </a-select-option>
  14. </a-select> -->
  15. <base-select
  16. class="w-100"
  17. remote
  18. filterable
  19. v-decorator="decorators.server"
  20. resource="servers"
  21. search-key="search"
  22. :remote-fn="q => ({ search: q })"
  23. :params="serverParams" />
  24. </a-form-item>
  25. </a-form>
  26. </div>
  27. <div slot="footer">
  28. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  29. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  30. </div>
  31. </base-dialog>
  32. </template>
  33. <script>
  34. import { mapGetters } from 'vuex'
  35. import DialogMixin from '@/mixins/dialog'
  36. import WindowsMixin from '@/mixins/windows'
  37. export default {
  38. name: 'DiskMountUpdateDialog',
  39. mixins: [DialogMixin, WindowsMixin],
  40. data () {
  41. return {
  42. loading: false,
  43. form: {
  44. fc: this.$form.createForm(this),
  45. },
  46. decorators: {
  47. server: [
  48. 'server',
  49. {
  50. rules: [
  51. { required: true, message: this.$t('compute.text_425') },
  52. ],
  53. },
  54. ],
  55. },
  56. formItemLayout: {
  57. wrapperCol: {
  58. span: 21,
  59. },
  60. labelCol: {
  61. span: 3,
  62. },
  63. },
  64. }
  65. },
  66. computed: {
  67. ...mapGetters(['isAdminMode', 'isDomainMode', 'scope']),
  68. serverParams () {
  69. const itemData = this.params.data[0]
  70. const params = {
  71. details: true,
  72. attachable_servers_for_disk: itemData.id,
  73. scope: this.scope,
  74. brand: itemData.brand,
  75. filter: 'status.in(ready, running)',
  76. limit: 20,
  77. }
  78. if (itemData.cloud_env === 'public' || itemData.cloud_env === 'private') {
  79. params.manager = itemData.manager_id
  80. params.zone = itemData.zone_id
  81. }
  82. if (this.isAdminMode || this.isDomainMode) params.project_id = itemData.project_id
  83. return params
  84. },
  85. },
  86. methods: {
  87. validateForm () {
  88. return new Promise((resolve, reject) => {
  89. this.form.fc.validateFields((err, values) => {
  90. if (!err) {
  91. resolve(values)
  92. } else {
  93. reject(err)
  94. }
  95. })
  96. })
  97. },
  98. doUpdate (data) {
  99. return new this.$Manager('servers').batchPerformAction({
  100. action: 'attachdisk',
  101. ids: data.server,
  102. data: {
  103. disk_id: this.params.data[0].id,
  104. },
  105. })
  106. },
  107. async handleConfirm () {
  108. this.loading = true
  109. try {
  110. const values = await this.validateForm()
  111. this.loading = true
  112. await this.doUpdate(values)
  113. this.loading = false
  114. this.params.refresh()
  115. this.cancelDialog()
  116. } catch (error) {
  117. this.loading = false
  118. }
  119. },
  120. },
  121. }
  122. </script>