Create.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ $t('common.create') }}</div>
  4. <div slot="body">
  5. <a-form :form="form.fc" v-bind="formItemLayout" hideRequiredMark>
  6. <a-form-item :label="$t('common.name')">
  7. <a-input
  8. v-decorator="decorators.name"
  9. :placeholder="$t('validator.resourceName')" />
  10. </a-form-item>
  11. <a-form-item :label="$t('k8s.text_34')">
  12. <a-radio-group v-decorator="decorators.type" buttonStyle="solid">
  13. <a-radio-button value="common">{{ $t('k8s.repo.type.common') }}</a-radio-button>
  14. <a-radio-button value="custom">{{ $t('k8s.repo.type.custom') }}</a-radio-button>
  15. </a-radio-group>
  16. </a-form-item>
  17. <a-form-item :label="$t('k8s.repo.url')" :extra="isCustomType ? $t('k8s.repo.url.extra.custom') : $t('k8s.repo.url.extra')">
  18. <a-input
  19. v-decorator="decorators.url"
  20. :placeholder="$t('common.tips.input', [$t('k8s.repo.url')])" />
  21. </a-form-item>
  22. <a-form-item :label="$t('k8s.text_54')">
  23. <a-input
  24. v-decorator="decorators.username"
  25. :placeholder="$t('common.tips.input', [$t('k8s.text_54')])" />
  26. </a-form-item>
  27. <a-form-item :label="$t('k8s.text_56')">
  28. <a-input-password
  29. v-decorator="decorators.password"
  30. :placeholder="$t('common.tips.input', [$t('k8s.text_56')])" />
  31. </a-form-item>
  32. </a-form>
  33. </div>
  34. <div slot="footer">
  35. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  36. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  37. </div>
  38. </base-dialog>
  39. </template>
  40. <script>
  41. import DialogMixin from '@/mixins/dialog'
  42. import WindowsMixin from '@/mixins/windows'
  43. export default {
  44. name: 'ReposCreateDialog',
  45. mixins: [DialogMixin, WindowsMixin],
  46. data () {
  47. return {
  48. loading: false,
  49. decorators: {
  50. name: [
  51. 'name',
  52. {
  53. validateFirst: true,
  54. rules: [
  55. { required: true, message: `${this.$t('common.placeholder')}${this.$t('common.name')}` },
  56. { validator: this.$validate('resourceName') },
  57. ],
  58. },
  59. ],
  60. type: [
  61. 'type',
  62. {
  63. initialValue: 'common',
  64. rules: [
  65. { required: true, message: this.$t('common.tips.select', [this.$t('k8s.text_34')]) },
  66. ],
  67. },
  68. ],
  69. url: [
  70. 'url',
  71. {
  72. rules: [
  73. { required: true, message: this.$t('common.tips.input', [this.$t('k8s.repo.url')]) },
  74. ],
  75. },
  76. ],
  77. username: [
  78. 'username',
  79. {
  80. rules: [
  81. { required: false, message: this.$t('common.tips.input', [this.$t('k8s.text_54')]) },
  82. ],
  83. },
  84. ],
  85. password: [
  86. 'password',
  87. {
  88. rules: [
  89. { required: false, message: this.$t('common.tips.input', [this.$t('k8s.text_56')]) },
  90. ],
  91. },
  92. ],
  93. },
  94. form: {
  95. fc: this.$form.createForm(this, {
  96. onValuesChange: (props, values) => {
  97. Object.keys(values).forEach((key) => {
  98. this.$set(this.form.fd, key, values[key])
  99. })
  100. },
  101. }),
  102. fd: {},
  103. },
  104. formItemLayout: {
  105. wrapperCol: {
  106. span: 20,
  107. },
  108. labelCol: {
  109. span: 4,
  110. },
  111. },
  112. }
  113. },
  114. computed: {
  115. isCustomType () {
  116. return this.form.fd.type === 'custom'
  117. },
  118. },
  119. methods: {
  120. async handleConfirm () {
  121. this.loading = true
  122. try {
  123. const { username, password, type, ...rest } = await this.form.fc.validateFields()
  124. const manager = new this.$Manager('container_registries', 'v1')
  125. const data = {
  126. ...rest,
  127. type,
  128. }
  129. if (username && password) {
  130. const configKey = type || 'common'
  131. data.config = {
  132. [configKey]: {
  133. username,
  134. password,
  135. },
  136. }
  137. }
  138. await manager.create({ data })
  139. this.params.refresh && this.params.refresh()
  140. this.cancelDialog()
  141. } catch (error) {
  142. throw error
  143. } finally {
  144. this.loading = false
  145. }
  146. },
  147. },
  148. }
  149. </script>