SetupSSH.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <steps class="my-3" v-model="step" />
  6. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="action" v-show="showSetup" />
  7. <detect-ssh-table ref="endpointsTable" @onDetecting="handleDetectStatusChange" :params="params" :key="step.currentStep" :ansibleTasks="ansibleTasks" :remote="!showSetup" />
  8. <setup-ssh-form ref="stepForm" :servers="servers" @tasks="handleSetupSSHTasks" v-show="showSetup" />
  9. </div>
  10. <div slot="footer">
  11. <a-button type="primary" @click="handleConfirm" :loading="loading" v-show="showSetup">{{ $t('dialog.ok') }}</a-button>
  12. <a-button type="primary" @click="() => { step.currentStep = 0 }" :loading="detecting" v-show="step.currentStep === 1">{{ $t('scope.text_107') }}</a-button>
  13. <a-button @click="cancelDialog">{{ cancelButtonText }}</a-button>
  14. </div>
  15. </base-dialog>
  16. </template>
  17. <script>
  18. import SetupSshForm from '../create/form/SetupSSHForm'
  19. import { DetectSshTable } from './DetectSSH'
  20. import DialogMixin from '@/mixins/dialog'
  21. import WindowsMixin from '@/mixins/windows'
  22. export default {
  23. name: 'SetupSSHDialog',
  24. components: {
  25. DetectSshTable,
  26. SetupSshForm,
  27. },
  28. mixins: [DialogMixin, WindowsMixin],
  29. data () {
  30. return {
  31. loading: false,
  32. detecting: false,
  33. action: this.$t('compute.vminstance.actions.setup_ssh_authentication'),
  34. ansibleTasks: {},
  35. step: {
  36. steps: [
  37. { title: this.$t('compute.vminstance.actions.setup_ssh_authentication'), key: 'setup-ssh-form' },
  38. { title: this.$t('compute.vminstance.setup_ssh_authentication.step2'), key: 'add-user' },
  39. ],
  40. currentStep: 0,
  41. },
  42. }
  43. },
  44. computed: {
  45. showSetup () {
  46. return this.step.currentStep === 0
  47. },
  48. stepComponent () {
  49. return this.step.steps[this.step.currentStep].key
  50. },
  51. servers () {
  52. return this.params.data.map((i) => { return i.id })
  53. },
  54. cancelButtonText () {
  55. return this.step.currentStep === 0 ? this.$t('dialog.cancel') : this.$t('scope.text_252')
  56. },
  57. },
  58. methods: {
  59. handleSetupSSHTasks (tasks) {
  60. this.ansibleTasks = tasks
  61. },
  62. handleDetectStatusChange (e) {
  63. this.detecting = e
  64. },
  65. async handleConfirm () {
  66. this.loading = true
  67. try {
  68. await this.$refs.stepForm.submit()
  69. this.loading = false
  70. this.step.currentStep = 1
  71. } catch (error) {
  72. this.loading = false
  73. }
  74. },
  75. },
  76. }
  77. </script>