Create.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('system.text_130', [$t('dictionary.group')])}}</div>
  4. <div slot="body">
  5. <a-form
  6. :form="form.fc"
  7. v-bind="formItemLayout">
  8. <a-form-item :label="$t('system.text_101')">
  9. <a-input v-decorator="decorators.name" />
  10. </a-form-item>
  11. <a-form-item :label="$t('common.description')">
  12. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  13. </a-form-item>
  14. <a-form-item :label="$t('dictionary.domain')" v-if="isAdminMode">
  15. <base-select
  16. v-decorator="decorators.domain_id"
  17. resource="domains"
  18. version="v1"
  19. remote
  20. :params="{ enabled: true }"
  21. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  22. :select-props="{ mode: 'default' }" />
  23. </a-form-item>
  24. </a-form>
  25. </div>
  26. <div slot="footer">
  27. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  28. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  29. </div>
  30. </base-dialog>
  31. </template>
  32. <script>
  33. import { mapGetters } from 'vuex'
  34. import DialogMixin from '@/mixins/dialog'
  35. import WindowsMixin from '@/mixins/windows'
  36. export default {
  37. name: 'GroupCreateDialog',
  38. mixins: [DialogMixin, WindowsMixin],
  39. data () {
  40. return {
  41. loading: false,
  42. form: {
  43. fc: this.$form.createForm(this),
  44. },
  45. decorators: {
  46. name: [
  47. 'name',
  48. {
  49. rules: [
  50. {
  51. required: true,
  52. message: this.$t('system.text_194'),
  53. whitespace: true,
  54. },
  55. ],
  56. },
  57. ],
  58. domain_id: [
  59. 'domain_id',
  60. {
  61. rules: [
  62. {
  63. required: true,
  64. message: this.$t('rules.domain'),
  65. },
  66. ],
  67. },
  68. ],
  69. description: [
  70. 'description',
  71. ],
  72. },
  73. formItemLayout: {
  74. wrapperCol: {
  75. span: 21,
  76. },
  77. labelCol: {
  78. span: 3,
  79. },
  80. },
  81. }
  82. },
  83. computed: mapGetters(['isAdminMode']),
  84. destroyed () {
  85. this.manager = null
  86. },
  87. created () {
  88. this.manager = new this.$Manager('groups', 'v1')
  89. },
  90. methods: {
  91. async handleConfirm () {
  92. this.loading = true
  93. try {
  94. const values = await this.form.fc.validateFields()
  95. await this.manager.create({
  96. data: values,
  97. })
  98. this.loading = false
  99. this.params.success()
  100. this.cancelDialog()
  101. } catch (error) {
  102. this.loading = false
  103. throw error
  104. }
  105. },
  106. },
  107. }
  108. </script>