VmAddBastionHostDialog.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('compute.bastionHost.add_bastion_host') }}</div>
  4. <div slot="body">
  5. <a-form :form="form.fc" hideRequiredMark v-bind="formItemLayout">
  6. <bastion-host
  7. :decorator="decorator.bastion_host"
  8. :inDialog="true" />
  9. </a-form>
  10. </div>
  11. <div slot="footer">
  12. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  13. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  14. </div>
  15. </base-dialog>
  16. </template>
  17. <script>
  18. import BastionHost from '@Compute/views/vminstance/create/components/BastionHost'
  19. import DialogMixin from '@/mixins/dialog'
  20. import WindowsMixin from '@/mixins/windows'
  21. import { uuid } from '@/utils/utils'
  22. export default {
  23. name: 'VmAddBastionHostDialog',
  24. components: {
  25. BastionHost,
  26. },
  27. mixins: [DialogMixin, WindowsMixin],
  28. data () {
  29. return {
  30. form: {
  31. fc: this.$form.createForm(this),
  32. },
  33. formItemLayout: {
  34. wrapperCol: {
  35. span: 20,
  36. },
  37. labelCol: {
  38. span: 4,
  39. },
  40. },
  41. decorator: {
  42. bastion_host: {
  43. bastion_host_enable: [
  44. 'bastion_host_enable',
  45. {
  46. valuePropName: 'checked',
  47. initialValue: false,
  48. },
  49. ],
  50. bastion_host_id: [
  51. 'bastion_host_id',
  52. {
  53. rules: [
  54. { required: true, message: this.$t('compute.bastionHost.bastion_host.placeholder') },
  55. ],
  56. },
  57. ],
  58. bastion_org_id: [
  59. 'bastion_org_id',
  60. {
  61. rules: [
  62. { required: true, message: this.$t('compute.bastionHost.bastion_org.placeholder') },
  63. ],
  64. },
  65. ],
  66. nodes: [
  67. 'nodes',
  68. {
  69. rules: [
  70. { required: true, message: this.$t('compute.bastionHost.node.placeholder') },
  71. ],
  72. },
  73. ],
  74. port: [
  75. 'port',
  76. {
  77. initialValue: 22,
  78. rules: [
  79. { type: 'number', min: 0, max: 65535, message: this.$t('compute.bastionHost.port.placeholder'), trigger: 'blur', transform: (v) => parseInt(v) },
  80. ],
  81. },
  82. ],
  83. privileged_accounts: [
  84. 'privileged_accounts',
  85. {
  86. rules: [
  87. { required: true, message: this.$t('compute.bastionHost.privileged_account.placeholder') },
  88. ],
  89. },
  90. ],
  91. accounts: [
  92. 'accounts',
  93. {
  94. rules: [
  95. { required: true, message: this.$t('compute.bastionHost.account.placeholder') },
  96. ],
  97. },
  98. ],
  99. bastion_domain_id: [
  100. 'bastion_domain_id',
  101. ],
  102. },
  103. },
  104. }
  105. },
  106. methods: {
  107. async handleConfirm () {
  108. try {
  109. const curItem = this.params.data[0]
  110. const bsManager = new this.$Manager('bastion_servers')
  111. const values = await this.form.fc.validateFields()
  112. this.loading = true
  113. const data = {
  114. bastion_host_id: values.bastion_host_id,
  115. bastion_org_id: values.bastion_org_id,
  116. nodes: values.nodes,
  117. port: values.port,
  118. accounts: [values.privileged_accounts].concat(values.accounts),
  119. server_id: curItem.id,
  120. name: curItem.name,
  121. os_type: curItem.os_type,
  122. bastion_domain_id: values.bastion_domain_id,
  123. }
  124. bsManager.create({ data, params: { $t: uuid() } })
  125. this.$message.success(this.$t('common.success'))
  126. this.cancelDialog()
  127. } catch (error) {
  128. throw error
  129. } finally {
  130. this.loading = false
  131. }
  132. },
  133. },
  134. }
  135. </script>