Create.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{ params.formType === 'update' ? $t('helm.text_104') : $t('helm.text_103')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips v-if="params.data" :count="params.data.length" :name="$t('helm.text_6')" :action="$t('helm.text_90')" />
  6. <dialog-table v-if="params.columns" :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. v-bind="formItemLayout"
  9. :form="form.fc">
  10. <a-form-item :label="$t('helm.text_16')">
  11. <a-input v-decorator="decorators.name" :placeholder="$t('helm.text_28')" />
  12. </a-form-item>
  13. <a-form-item :label="$t('compute.text_297', [$t('dictionary.domain')])" v-if="$store.getters.isAdminMode">
  14. <domain-select v-decorator="decorators.project_domain" />
  15. </a-form-item>
  16. <a-form-item label="URL">
  17. <a-input v-decorator="decorators.url" :placeholder="$t('helm.text_91')" />
  18. </a-form-item>
  19. <a-form-item :label="$t('helm.text_92')">
  20. <a-radio-group v-decorator="decorators.type">
  21. <a-radio-button
  22. v-for="item in typeOpts"
  23. :value="item.key"
  24. :key="item.key">{{ item.label }}</a-radio-button>
  25. </a-radio-group>
  26. </a-form-item>
  27. </a-form>
  28. </div>
  29. <div slot="footer">
  30. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  31. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  32. </div>
  33. </base-dialog>
  34. </template>
  35. <script>
  36. import DialogMixin from '@/mixins/dialog'
  37. import WindowsMixin from '@/mixins/windows'
  38. import DomainSelect from '@/sections/DomainSelect'
  39. export default {
  40. name: 'ChartCreateDialog',
  41. components: {
  42. DomainSelect,
  43. },
  44. mixins: [DialogMixin, WindowsMixin],
  45. data () {
  46. const initialValue = {}
  47. if (this.params.data && this.params.data[0]) {
  48. initialValue.name = this.params.data[0].name
  49. initialValue.url = this.params.data[0].url
  50. }
  51. return {
  52. loading: false,
  53. form: {
  54. fc: this.$form.createForm(this),
  55. fd: {},
  56. },
  57. typeOpts: [
  58. { key: 'internal', label: this.$t('helm.text_14') },
  59. { key: 'external', label: this.$t('helm.text_15') },
  60. ],
  61. decorators: {
  62. name: [
  63. 'name',
  64. {
  65. initialValue: initialValue.name,
  66. validateFirst: true,
  67. rules: [
  68. { required: true, message: this.$t('helm.text_28') },
  69. { validator: this.$validate('k8sName') },
  70. ],
  71. },
  72. ],
  73. project_domain: [
  74. 'project_domain',
  75. {
  76. initialValue: this.$store.getters.userInfo.projectDomainId,
  77. },
  78. ],
  79. type: [
  80. 'type',
  81. {
  82. initialValue: 'internal',
  83. },
  84. ],
  85. url: [
  86. 'url',
  87. {
  88. initialValue: initialValue.url,
  89. validateFirst: true,
  90. rules: [
  91. { required: true, message: this.$t('helm.text_94'), trigger: 'blur' },
  92. { validator: this.$validate('url') },
  93. ],
  94. },
  95. ],
  96. },
  97. formItemLayout: {
  98. wrapperCol: {
  99. span: 21,
  100. },
  101. labelCol: {
  102. span: 3,
  103. },
  104. },
  105. }
  106. },
  107. methods: {
  108. async doCreate (data) {
  109. try {
  110. if (this.params.formType === 'update') {
  111. return await this.params.onManager('update', {
  112. id: this.params.data[0].id,
  113. managerArgs: {
  114. data,
  115. },
  116. })
  117. } else {
  118. return this.params.onManager('create', {
  119. managerArgs: {
  120. data,
  121. },
  122. })
  123. }
  124. } catch (error) {
  125. throw error
  126. }
  127. },
  128. async handleConfirm () {
  129. this.loading = true
  130. try {
  131. const values = await this.form.fc.validateFields()
  132. await this.doCreate(values)
  133. if (this.params.refresh) this.params.refresh()
  134. this.loading = false
  135. this.cancelDialog()
  136. } catch (error) {
  137. this.loading = false
  138. throw error
  139. }
  140. },
  141. },
  142. }
  143. </script>