AddBastion.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.add_to_bastion')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.add_to_bastion')" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <bastion-host :decorator="decorators.bastion_host" :form="form" inDialog />
  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 DialogMixin from '@/mixins/dialog'
  19. import WindowsMixin from '@/mixins/windows'
  20. import { getInitialValue } from '@/utils/common/ant'
  21. import { Decorator } from '@Compute/utils/createServer'
  22. import { SERVER_TYPE } from '@Compute/constants'
  23. import BastionHost from '../create/components/BastionHost'
  24. export default {
  25. name: 'VmAddToBastionDialog',
  26. components: {
  27. BastionHost,
  28. },
  29. mixins: [DialogMixin, WindowsMixin],
  30. data () {
  31. const decorators = new Decorator(SERVER_TYPE.idc).createDecorators()
  32. const initFd = getInitialValue(decorators)
  33. return {
  34. loading: false,
  35. form: {
  36. fc: this.$form.createForm(this),
  37. fd: {
  38. ...initFd,
  39. },
  40. },
  41. formItemLayout: {
  42. wrapperCol: {
  43. span: 18,
  44. },
  45. labelCol: {
  46. span: 6,
  47. },
  48. },
  49. decorators,
  50. }
  51. },
  52. computed: {
  53. },
  54. methods: {
  55. async handleConfirm () {
  56. this.loading = true
  57. try {
  58. const values = await this.form.fc.validateFields()
  59. values.accounts = [values.privileged_accounts].concat(values.accounts)
  60. delete values.privileged_accounts
  61. for (const item of this.params.data) {
  62. await new this.$Manager('bastion_servers').create({
  63. data: {
  64. ...values,
  65. server_id: item.id,
  66. generate_name: item.name,
  67. },
  68. })
  69. }
  70. this.params.refresh()
  71. this.cancelDialog()
  72. } finally {
  73. this.loading = false
  74. }
  75. },
  76. },
  77. }
  78. </script>