CreateUser.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <a-form :form="form.fc" v-bind="formItemLayout">
  3. <a-form-item :label="$t('system.text_101')">
  4. <a-input :placeholder="$t('system.text_168')" v-decorator="decorators.name" />
  5. </a-form-item>
  6. <a-form-item :label="$t('common.description')">
  7. <a-textarea :auto-size="{ minRows: 1, maxRows: 3 }" v-decorator="decorators.description" :placeholder="$t('common_367')" />
  8. </a-form-item>
  9. <a-form-item :label="$t('system.text_221')">
  10. <a-input-password :placeholder="$t('system.text_239')" v-decorator="decorators.password" />
  11. </a-form-item>
  12. <a-form-item :label="$t('dictionary.domain')" v-if="isAdminMode">
  13. <base-select
  14. resource="domains"
  15. v-decorator="decorators.domain"
  16. :params="domainParams"
  17. filterable
  18. remote
  19. version="v1"
  20. :showSync="true"
  21. :select-props="{placeholder: $t('system.text_443', [$t('dictionary.domain')]), labelInValue: true }" />
  22. <div slot="extra">{{$t('system.text_439')}}<help-link :href="domainCreateLink">{{$t('system.text_128')}}</help-link>
  23. </div>
  24. </a-form-item>
  25. <a-form-item :label="$t('scope.text_245')">
  26. <a-input :placeholder="$t('system.displayname_tip')" v-decorator="decorators.displayname" />
  27. </a-form-item>
  28. <a-form-item :label="$t('system.text_475')">
  29. <a-switch :checkedChildren="$t('system.text_134')" :unCheckedChildren="$t('system.text_135')" v-decorator="decorators['allow_web_console']" />
  30. <div slot="extra">{{$t('system.text_481')}}</div>
  31. </a-form-item>
  32. <a-form-item :label="$t('system.text_483')">
  33. <a-switch :checkedChildren="$t('system.text_134')" :unCheckedChildren="$t('system.text_135')" v-decorator="decorators['enable_mfa']" />
  34. <div slot="extra">{{$t('system.text_484')}}</div>
  35. </a-form-item>
  36. </a-form>
  37. </template>
  38. <script>
  39. import { mapGetters } from 'vuex'
  40. export default {
  41. name: 'CreateUser',
  42. data () {
  43. // const validatePassword = async (rule, value, callback) => {
  44. // if (this.minPasswordLen) {
  45. // if (value.length < this.minPasswordLen) return callback(new Error(this.$t('system.text_485', [this.minPasswordLen])))
  46. // return callback()
  47. // }
  48. // const manager = new this.$Manager('services', 'v1')
  49. // try {
  50. // const response = await manager.list({
  51. // params: {
  52. // type: 'identity',
  53. // },
  54. // })
  55. // const id = response.data.data && response.data.data[0] && response.data.data[0].id
  56. // if (id) {
  57. // const configRes = await manager.getSpecific({
  58. // id,
  59. // spec: 'config',
  60. // })
  61. // const len = configRes.data.config && configRes.data.config.default && configRes.data.config.default.password_minimal_length
  62. // if (len) {
  63. // this.minPasswordLen = len
  64. // if (value.length < len) return callback(new Error(this.$t('system.text_485', [len])))
  65. // }
  66. // }
  67. // return callback()
  68. // } catch (error) {
  69. // callback()
  70. // throw error
  71. // }
  72. // }
  73. return {
  74. minPasswordLen: null,
  75. form: {
  76. fc: this.$form.createForm(this),
  77. },
  78. formItemLayout: {
  79. wrapperCol: {
  80. span: 21,
  81. xxl: {
  82. span: 22,
  83. },
  84. },
  85. labelCol: {
  86. span: 3,
  87. xxl: {
  88. span: 2,
  89. },
  90. },
  91. },
  92. decorators: {
  93. name: [
  94. 'name',
  95. {
  96. rules: [
  97. { required: true, message: this.$t('system.text_168') },
  98. ],
  99. },
  100. ],
  101. description: ['description'],
  102. displayname: [
  103. 'displayname',
  104. {
  105. initialValue: '',
  106. rules: [{ required: false }],
  107. },
  108. ],
  109. password: [
  110. 'password',
  111. {
  112. validateFirst: true,
  113. rules: [
  114. { required: true, message: this.$t('system.text_486'), trigger: 'blur' },
  115. // { validator: validatePassword, trigger: 'blur' },
  116. ],
  117. },
  118. ],
  119. domain: [
  120. 'domain',
  121. {
  122. // initialValue: { key: this.$store.getters.userInfo.projectDomainId, label: this.$store.getters.userInfo.projectDomain },
  123. // validateTrigger: 'blur',
  124. rules: [
  125. { required: true, message: this.$t('rules.domain') },
  126. ],
  127. },
  128. ],
  129. allow_web_console: [
  130. 'allow_web_console',
  131. {
  132. initialValue: true,
  133. valuePropName: 'checked',
  134. },
  135. ],
  136. enable_mfa: [
  137. 'enable_mfa',
  138. {
  139. initialValue: false,
  140. valuePropName: 'checked',
  141. },
  142. ],
  143. },
  144. domainParams: {
  145. scope: this.$store.getters.scope,
  146. limit: 20,
  147. enabled: true,
  148. },
  149. }
  150. },
  151. computed: {
  152. ...mapGetters(['isAdminMode']),
  153. domainCreateLink () {
  154. return this.$router.resolve('/domain/create').href
  155. },
  156. },
  157. methods: {
  158. validateForm () {
  159. return this.form.fc.validateFields()
  160. },
  161. },
  162. }
  163. </script>