UpdatePassword.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{$t('compute.text_276')}}</div>
  4. <div slot="body">
  5. <dialog-selected-tips :name="$t('dictionary.user')" :count="params.data.length" :action="params.title" />
  6. <dialog-table :data="params.data" :columns="params.columns.slice(0, 3)" />
  7. <a-form
  8. :form="form.fc"
  9. v-bind="formItemLayout">
  10. <a-form-item :label="$t('system.text_221')">
  11. <a-input-password :placeholder="$t('system.text_239')" v-decorator="decorators.password" />
  12. </a-form-item>
  13. </a-form>
  14. </div>
  15. <div slot="footer">
  16. <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
  17. <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
  18. </div>
  19. </base-dialog>
  20. </template>
  21. <script>
  22. import DialogMixin from '@/mixins/dialog'
  23. import WindowsMixin from '@/mixins/windows'
  24. export default {
  25. name: 'UserUpdatePasswordDialog',
  26. mixins: [DialogMixin, WindowsMixin],
  27. data () {
  28. // const validatePassword = async (rule, value, callback) => {
  29. // if (this.minPasswordLen) {
  30. // if (value.length < this.minPasswordLen) return callback(new Error(this.$t('system.text_485', [this.minPasswordLen])))
  31. // return callback()
  32. // }
  33. // const manager = new this.$Manager('services', 'v1')
  34. // try {
  35. // const response = await manager.list({
  36. // params: {
  37. // type: 'identity',
  38. // },
  39. // })
  40. // const id = response.data.data && response.data.data[0] && response.data.data[0].id
  41. // if (id) {
  42. // const configRes = await manager.getSpecific({
  43. // id,
  44. // spec: 'config',
  45. // })
  46. // const len = configRes.data.config && configRes.data.config.default && configRes.data.config.default.password_minimal_length
  47. // if (len) {
  48. // this.minPasswordLen = len
  49. // if (value.length < len) return callback(new Error(this.$t('system.text_485', [len])))
  50. // }
  51. // }
  52. // return callback()
  53. // } catch (error) {
  54. // callback()
  55. // throw error
  56. // }
  57. // }
  58. return {
  59. loading: false,
  60. minPasswordLen: null,
  61. form: {
  62. fc: this.$form.createForm(this),
  63. },
  64. decorators: {
  65. password: [
  66. 'password',
  67. {
  68. validateFirst: true,
  69. rules: [
  70. { required: true, message: this.$t('system.text_486'), trigger: 'blur' },
  71. // { validator: validatePassword, trigger: 'blur' },
  72. ],
  73. },
  74. ],
  75. },
  76. formItemLayout: {
  77. wrapperCol: {
  78. span: 20,
  79. },
  80. labelCol: {
  81. span: 4,
  82. },
  83. },
  84. }
  85. },
  86. methods: {
  87. async handleConfirm () {
  88. this.loading = true
  89. const { data, onManager } = this.params
  90. try {
  91. const values = await this.form.fc.validateFields()
  92. onManager('patch', {
  93. id: data[0].id,
  94. managerArgs: {
  95. data: {
  96. ...values,
  97. skip_password_complexity_check: true,
  98. },
  99. },
  100. })
  101. this.$message.success(this.$t('common.success'))
  102. this.cancelDialog()
  103. } catch (error) {
  104. this.loading = false
  105. throw error
  106. }
  107. },
  108. },
  109. }
  110. </script>