UnpackDialog.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. <div slot="message">
  7. {{ $t('compute.unpack_alert') }}
  8. </div>
  9. </a-alert>
  10. <dialog-selected-tips :name="$t('compute.instance_backup')" :count="params.data.length" :action="action" />
  11. <dialog-table :data="params.data" :columns="columns" />
  12. <a-form :form="form.fc" hideRequiredMark v-bind="formItemLayout">
  13. <a-form-item :label="$t('compute.unpack_name')">
  14. <a-input
  15. v-decorator="decorators.name"
  16. :placeholder="$t('common.tips.input', [$t('compute.unpack_name')])" />
  17. </a-form-item>
  18. </a-form>
  19. </div>
  20. <div slot="footer">
  21. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  22. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  23. </div>
  24. </base-dialog>
  25. </template>
  26. <script>
  27. import DialogMixin from '@/mixins/dialog'
  28. import WindowsMixin from '@/mixins/windows'
  29. export default {
  30. name: 'UnpackDialog',
  31. mixins: [DialogMixin, WindowsMixin],
  32. data () {
  33. return {
  34. loading: false,
  35. action: this.$t('compute.unpack'),
  36. form: {
  37. fc: this.$form.createForm(this),
  38. },
  39. decorators: {
  40. name: [
  41. 'name',
  42. {
  43. rules: [
  44. { required: true, message: this.$t('common.tips.input', [this.$t('compute.unpack_name')]) },
  45. ],
  46. },
  47. ],
  48. },
  49. formItemLayout: {
  50. wrapperCol: {
  51. span: 21,
  52. },
  53. labelCol: {
  54. span: 3,
  55. },
  56. },
  57. }
  58. },
  59. computed: {
  60. columns () {
  61. const showFields = ['name', 'brand', 'guest']
  62. return this.params.columns.filter((item) => { return showFields.includes(item.field) })
  63. },
  64. },
  65. methods: {
  66. doUnpackSubmit (values) {
  67. const params = {
  68. package_name: values.name,
  69. }
  70. const ids = this.params.data.map(item => item.id)
  71. return this.params.onManager('performAction', {
  72. id: ids[0],
  73. steadyStatus: ['ready'],
  74. managerArgs: {
  75. action: 'pack',
  76. data: params,
  77. },
  78. })
  79. },
  80. async handleConfirm () {
  81. this.loading = true
  82. try {
  83. const values = await this.form.fc.validateFields()
  84. await this.doUnpackSubmit(values)
  85. this.params.refresh && this.params.refresh()
  86. this.cancelDialog()
  87. } catch (error) {
  88. throw error
  89. } finally {
  90. this.loading = false
  91. }
  92. },
  93. },
  94. }
  95. </script>