UnbindKeypair.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_364')}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" v-if="isOpenStack" :message="$t('compute.text_1267')" type="warning" />
  6. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_364')" />
  7. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  8. <a-form :form="form.fc" hideRequiredMark>
  9. <a-form-item :label="$t('compute.text_494')" v-bind="formItemLayout" :extra="$t('compute.text_1268')">
  10. <a-switch :checkedChildren="$t('compute.text_115')" :unCheckedChildren="$t('compute.text_116')" v-decorator="decorators.auto_start" :disabled="form.fi.disableAutoStart" />
  11. </a-form-item>
  12. </a-form>
  13. </div>
  14. <div slot="footer">
  15. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  16. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  17. </div>
  18. </base-dialog>
  19. </template>
  20. <script>
  21. import DialogMixin from '@/mixins/dialog'
  22. import WindowsMixin from '@/mixins/windows'
  23. import { typeClouds } from '@/utils/common/hypervisor'
  24. const hypervisorMap = typeClouds.hypervisorMap
  25. export default {
  26. name: 'VmUnbindKeypairDialog',
  27. mixins: [DialogMixin, WindowsMixin],
  28. data () {
  29. let autoStartInitialValue = true
  30. let disableAutoStart = false
  31. const firstData = this.params.data && this.params.data[0]
  32. if (firstData && (firstData.status === 'running' || firstData.hypervisor === hypervisorMap.azure.key)) {
  33. autoStartInitialValue = false
  34. disableAutoStart = true
  35. }
  36. return {
  37. loading: false,
  38. form: {
  39. fc: this.$form.createForm(this),
  40. fi: {
  41. disableAutoStart,
  42. },
  43. },
  44. decorators: {
  45. auto_start: [
  46. 'auto_start',
  47. {
  48. initialValue: autoStartInitialValue,
  49. valuePropName: 'checked',
  50. },
  51. ],
  52. },
  53. formItemLayout: {
  54. wrapperCol: {
  55. span: 21,
  56. },
  57. labelCol: {
  58. span: 3,
  59. },
  60. },
  61. }
  62. },
  63. computed: {
  64. isOpenStack () {
  65. return this.params.data[0].hypervisor === hypervisorMap.openstack.key
  66. },
  67. },
  68. methods: {
  69. async handleConfirm () {
  70. this.loading = true
  71. try {
  72. const values = await this.form.fc.validateFields()
  73. const ids = this.params.data.map(item => item.id)
  74. values.__delete_keypair__ = true
  75. await this.params.onManager('batchPerformAction', {
  76. id: ids,
  77. steadyStatus: ['running', 'ready'],
  78. managerArgs: {
  79. action: 'deploy',
  80. data: values,
  81. },
  82. })
  83. this.$bus.$emit('VMInstanceListSingleUpdate', [this.params.data[0].id])
  84. this.cancelDialog()
  85. } finally {
  86. this.loading = false
  87. }
  88. },
  89. },
  90. }
  91. </script>