Create.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_1054')}}</div>
  4. <div slot="body">
  5. <a-form
  6. v-bind="formItemLayout"
  7. :form="form.fc">
  8. <a-form-item :label="$t('compute.text_1051')" :extra="$t('compute.text_1055')">
  9. <a-input-number :min="1" v-decorator="decorators.cpu_core_count" /> {{$t('compute.text_167')}}</a-form-item>
  10. <a-form-item :label="$t('compute.text_1052')" :extra="$t('compute.text_1056')">
  11. <a-input-number :min="0.5" v-decorator="decorators.memory_size_mb" /> GB
  12. </a-form-item>
  13. <a-form-item :label="$t('compute.system_disk_max')">
  14. <a-input-number :min="0" v-decorator="decorators.sys_disk_max_size_gb" /> GB
  15. </a-form-item>
  16. <a-form-item :label="$t('common.description')">
  17. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  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 DialogMixin from '@/mixins/dialog'
  29. import WindowsMixin from '@/mixins/windows'
  30. export default {
  31. name: 'CreateSkuDialog',
  32. mixins: [DialogMixin, WindowsMixin],
  33. data () {
  34. return {
  35. loading: false,
  36. form: {
  37. fc: this.$form.createForm(this),
  38. },
  39. decorators: {
  40. cpu_core_count: [
  41. 'cpu_core_count',
  42. {
  43. initialValue: 4,
  44. },
  45. ],
  46. memory_size_mb: [
  47. 'memory_size_mb',
  48. {
  49. initialValue: 16,
  50. },
  51. ],
  52. sys_disk_max_size_gb: [
  53. 'sys_disk_max_size_gb',
  54. {
  55. initialValue: 2048,
  56. },
  57. ],
  58. description: ['description'],
  59. },
  60. formItemLayout: {
  61. wrapperCol: {
  62. span: 18,
  63. },
  64. labelCol: {
  65. span: 4,
  66. },
  67. },
  68. }
  69. },
  70. methods: {
  71. validateForm () {
  72. return new Promise((resolve, reject) => {
  73. this.form.fc.validateFields((err, values) => {
  74. if (!err) {
  75. resolve(values)
  76. } else {
  77. reject(err)
  78. }
  79. })
  80. })
  81. },
  82. doCreate (data) {
  83. return this.params.onManager('create', {
  84. managerArgs: {
  85. data,
  86. },
  87. })
  88. },
  89. async handleConfirm () {
  90. this.loading = true
  91. try {
  92. const values = await this.validateForm()
  93. this.loading = true
  94. values.memory_size_mb = values.memory_size_mb * 1024
  95. await this.doCreate(values)
  96. this.loading = false
  97. this.cancelDialog()
  98. } catch (error) {
  99. this.loading = false
  100. }
  101. },
  102. },
  103. }
  104. </script>