CreateRole.vue 2.4 KB

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