Restart.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{action}}</div>
  4. <div slot="body">
  5. <a-alert class="mb-2" type="warning">
  6. <template v-slot:message>
  7. <div>{{$t('compute.text_1234')}}</div>
  8. </template>
  9. </a-alert>
  10. <dialog-selected-tips :name="$t('compute.vminstance-container')" :count="params.data.length" :action="action" />
  11. <vxe-grid class="mb-2" :data="params.data" :columns="columns" />
  12. <a-form :form="form.fc" hideRequiredMark>
  13. <a-form-item :label="$t('compute.text_1041')" v-bind="formItemLayout" v-if="isOpenWorkflow">
  14. <a-input v-decorator="decorators.reason" :placeholder="$t('compute.text_1105')" />
  15. </a-form-item>
  16. <a-form-item :label="$t('compute.text_1235')" v-bind="formItemLayout">
  17. <a-switch v-decorator="decorators.autoStart" />
  18. </a-form-item>
  19. </a-form>
  20. </div>
  21. <div slot="footer">
  22. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  23. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  24. </div>
  25. </base-dialog>
  26. </template>
  27. <script>
  28. import { mapGetters } from 'vuex'
  29. import DialogMixin from '@/mixins/dialog'
  30. import WindowsMixin from '@/mixins/windows'
  31. import WorkflowMixin from '@/mixins/workflow'
  32. import { BATCH_OPERATE_SERVERS_MAX } from '@/constants/workflow'
  33. export default {
  34. name: 'VmContainerRestartDialog',
  35. mixins: [DialogMixin, WindowsMixin, WorkflowMixin],
  36. data () {
  37. return {
  38. loading: false,
  39. action: this.$t('compute.text_274'),
  40. form: {
  41. fc: this.$form.createForm(this),
  42. },
  43. decorators: {
  44. reason: [
  45. 'reason',
  46. {
  47. initialValue: '',
  48. },
  49. ],
  50. autoStart: [
  51. 'autoStart',
  52. {
  53. initialValue: false,
  54. valuePropName: 'checked',
  55. },
  56. ],
  57. },
  58. formItemLayout: {
  59. wrapperCol: {
  60. span: 21,
  61. },
  62. labelCol: {
  63. span: 3,
  64. },
  65. },
  66. }
  67. },
  68. computed: {
  69. ...mapGetters(['userInfo']),
  70. columns () {
  71. const showFields = ['name', 'ip', 'instance_type']
  72. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  73. },
  74. isOpenWorkflow () {
  75. return this.checkWorkflowEnabled(this.WORKFLOW_TYPES.APPLY_SERVER_RESTART)
  76. },
  77. },
  78. methods: {
  79. async doRestartSubmit (values) {
  80. const ids = this.params.data.map(item => item.id)
  81. return this.params.onManager('batchPerformAction', {
  82. id: ids,
  83. steadyStatus: 'ready',
  84. managerArgs: {
  85. action: 'restart',
  86. data: {
  87. is_force: values.autoStart,
  88. },
  89. },
  90. })
  91. },
  92. async handleConfirm () {
  93. this.loading = true
  94. try {
  95. const values = await this.form.fc.validateFields()
  96. if (this.isOpenWorkflow) {
  97. if (this.params.data.length > BATCH_OPERATE_SERVERS_MAX) {
  98. this.$message.error(this.$t('compute.workflow.operate_servers_check.message', [this.$t('compute.text_274'), BATCH_OPERATE_SERVERS_MAX]))
  99. this.loading = false
  100. return
  101. }
  102. const projects = new Set(this.params.data.map(item => item.tenant_id))
  103. if (projects.size > 1) {
  104. this.$message.error(this.$t('compute.text_1348'))
  105. this.loading = false
  106. return
  107. }
  108. await this.handleRestartByWorkflowSubmit(values)
  109. } else {
  110. await this.doRestartSubmit(values)
  111. }
  112. this.loading = false
  113. this.cancelDialog()
  114. } catch (error) {
  115. this.loading = false
  116. }
  117. },
  118. async handleRestartByWorkflowSubmit (values) {
  119. const ids = this.params.data.map(item => item.id)
  120. const params = {
  121. is_force: values.autoStart,
  122. }
  123. const variables = {
  124. project: this.params.data[0].tenant_id,
  125. project_domain: this.params.data[0].domain_id,
  126. process_definition_key: this.WORKFLOW_TYPES.APPLY_SERVER_RESTART,
  127. initiator: this.userInfo.id,
  128. ids: ids.join(','),
  129. description: values.reason,
  130. paramter: JSON.stringify(params),
  131. }
  132. await this.createWorkflow(variables)
  133. this.$message.success(this.$t('common.worflow_tip', [this.$t('compute.text_274')]))
  134. this.$router.push('/workflow')
  135. },
  136. },
  137. }
  138. </script>