index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div>
  3. <page-header :title="$t('system.text_167', [$t('dictionary.domain')])" />
  4. <page-body needMarginBottom>
  5. <a-form :form="form.fc" v-bind="formItemLayout">
  6. <a-form-item :label="$t('system.text_101')">
  7. <a-input v-decorator="decorators.name" :placeholder="$t('system.text_168')" />
  8. </a-form-item>
  9. <a-form-item :label="$t('common.description')">
  10. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  11. </a-form-item>
  12. </a-form>
  13. </page-body>
  14. <page-footer>
  15. <div slot="right">
  16. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('common.create') }}</a-button>
  17. <a-button class="ml-3" @click="handleCancel">{{ $t('dialog.cancel') }}</a-button>
  18. </div>
  19. </page-footer>
  20. </div>
  21. </template>
  22. <script>
  23. import { mapGetters } from 'vuex'
  24. import { escapeHTML } from '@/utils/utils'
  25. export default {
  26. name: 'DomainCreateIndex',
  27. data () {
  28. return {
  29. loading: false,
  30. submiting: false,
  31. form: {
  32. fc: this.$form.createForm(this),
  33. },
  34. decorators: {
  35. name: [
  36. 'name',
  37. {
  38. validateFirst: true,
  39. rules: [
  40. {
  41. required: true, message: this.$t('system.text_170'),
  42. },
  43. ],
  44. },
  45. ],
  46. description: ['description'],
  47. },
  48. formItemLayout: {
  49. wrapperCol: {
  50. span: 21,
  51. xxl: {
  52. span: 22,
  53. },
  54. },
  55. labelCol: {
  56. span: 3,
  57. xxl: {
  58. span: 2,
  59. },
  60. },
  61. },
  62. }
  63. },
  64. computed: {
  65. ...mapGetters(['l3PermissionEnable']),
  66. domain () {
  67. return this.$route.query.domain
  68. },
  69. isClone () {
  70. return !!this.domain
  71. },
  72. },
  73. methods: {
  74. async handleConfirm () {
  75. this.loading = true
  76. try {
  77. await this.form.fc.validateFields()
  78. await this.fetchCreate()
  79. this.$router.push('/domain')
  80. } catch (err) {
  81. throw err
  82. } finally {
  83. this.loading = false
  84. }
  85. },
  86. async fetchCreate () {
  87. const manager = new this.$Manager('domains', 'v1')
  88. try {
  89. const { data } = await manager.create({
  90. data: {
  91. name: escapeHTML(this.form.fc.getFieldValue('name')),
  92. description: this.form.fc.getFieldValue('description'),
  93. },
  94. })
  95. return data
  96. } catch (err) {
  97. throw err
  98. }
  99. },
  100. handleCancel () {
  101. this.$router.push('/domain')
  102. },
  103. },
  104. }
  105. </script>