AddTemplate.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1166')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.server')" :count="params.data.length" :action="$t('compute.text_1166')" />
  6. <dialog-table :data="params.data" :columns="columns" />
  7. <a-form :form="form.fc" v-bind="formItemLayout">
  8. <a-form-item :label="$t('common.name')">
  9. <a-input v-decorator="decorators.name" :placeholder="$t('compute.text_210')" />
  10. <name-repeated
  11. v-slot:extra
  12. res="servertemplates"
  13. :name="form.fc.getFieldValue('generate_name')" />
  14. </a-form-item>
  15. </a-form>
  16. </div>
  17. <div slot="footer">
  18. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  19. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  20. </div>
  21. </base-dialog>
  22. </template>
  23. <script>
  24. import DialogMixin from '@/mixins/dialog'
  25. import WindowsMixin from '@/mixins/windows'
  26. import NameRepeated from '@/sections/NameRepeated'
  27. export default {
  28. name: 'VmAddTemplateDialog',
  29. components: {
  30. NameRepeated,
  31. },
  32. mixins: [DialogMixin, WindowsMixin],
  33. data () {
  34. return {
  35. loading: false,
  36. form: {
  37. fc: this.$form.createForm(this),
  38. },
  39. decorators: {
  40. name: [
  41. 'generate_name',
  42. {
  43. rules: [
  44. { required: true, message: this.$t('compute.text_210') },
  45. ],
  46. },
  47. ],
  48. },
  49. formItemLayout: {
  50. wrapperCol: {
  51. span: 20,
  52. },
  53. labelCol: {
  54. span: 4,
  55. },
  56. },
  57. }
  58. },
  59. computed: {
  60. columns () {
  61. const fields = ['name', 'instance_type', 'brand']
  62. return this.params.columns.filter(item => {
  63. const { field } = item
  64. return fields.indexOf(field) > -1
  65. })
  66. },
  67. },
  68. methods: {
  69. async handleConfirm () {
  70. this.loading = true
  71. try {
  72. const values = await this.form.fc.validateFields()
  73. await this.params.onManager('performAction', {
  74. id: this.params.data[0].id,
  75. steadyStatus: ['running', 'ready'],
  76. managerArgs: {
  77. action: 'save-template',
  78. data: values,
  79. },
  80. })
  81. this.cancelDialog()
  82. } finally {
  83. this.loading = false
  84. }
  85. },
  86. },
  87. }
  88. </script>