ModifyPasswordDlg.vue 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <FormDlg title="修改密码" @hide="onHide" @show="onShow" @submit="onSubmit" ref="dlg" :disabled="errors.any()">
  3. <div :class="{'form-group':true, 'has-feedback':true,'has-error': errors.has('oldPassword')}">
  4. <label for="old-password" class="col-sm-4 control-label">原密码
  5. <span class="text-red">*</span>
  6. </label>
  7. <div class="col-sm-7">
  8. <input type="password" class="form-control" id="old-password" name="oldPassword" v-model.trim="form.oldPassword" autocomplete="new-password" data-vv-as="原密码" v-validate="'required'" @keydown.enter="$el.querySelector('#new-password').focus()">
  9. </div>
  10. </div>
  11. <div :class="{'form-group':true, 'has-feedback':true,'has-error': errors.has('newPassword')}">
  12. <label for="new-password" class="col-sm-4 control-label">新密码
  13. <span class="text-red">*</span>
  14. </label>
  15. <div class="col-sm-7">
  16. <input type="password" class="form-control" id="new-password" name="newPassword" v-model.trim="form.newPassword" autocomplete="new-password" data-vv-as="新密码" v-validate="'required'" @keydown.enter="$el.querySelector('#new-password2').focus()">
  17. </div>
  18. </div>
  19. <div :class="{'form-group':true, 'has-feedback':true,'has-error': errors.has('newPassword2')}">
  20. <label for="new-password2" class="col-sm-4 control-label">确认密码
  21. <span class="text-red">*</span>
  22. </label>
  23. <div class="col-sm-7">
  24. <input type="password" class="form-control" id="new-password2" name="newPassword2" v-model.trim="form.newPassword2" autocomplete="new-password" data-vv-as="确认密码" v-validate="'required|confirmed:newPassword'" @keydown.enter="onSubmit">
  25. </div>
  26. </div>
  27. </FormDlg>
  28. </template>
  29. <script>
  30. import FormDlg from 'components/FormDlg.vue'
  31. import $ from 'jquery'
  32. import crypto from 'crypto'
  33. export default {
  34. data() {
  35. return {
  36. form: this.defForm()
  37. }
  38. },
  39. components: {
  40. FormDlg
  41. },
  42. methods: {
  43. defForm() {
  44. return {
  45. oldPassword: '',
  46. newPassword: '',
  47. newPassword2: ''
  48. }
  49. },
  50. onHide() {
  51. this.form = this.defForm();
  52. },
  53. onShow() {
  54. this.errors.clear();
  55. // this.$el.querySelector('#old-password').focus();
  56. },
  57. async onSubmit() {
  58. var ok = await this.$validator.validateAll();
  59. if(!ok) {
  60. var e = this.errors.items[0];
  61. this.$message({
  62. type: 'error',
  63. message: e.msg
  64. })
  65. $(`[name=${e.field}]`).focus();
  66. return;
  67. }
  68. $.get('/api/v1/modifypassword', {
  69. oldpassword: this.md5(this.form.oldPassword),
  70. newpassword: this.md5(this.form.newPassword)
  71. }).then(data => {
  72. this.$refs['dlg'].hide();
  73. this.$alert("密码修改成功,即将重新登录!", "提示").then(() => {
  74. this.$router.replace("/logout");
  75. }).catch(() => {
  76. this.$router.replace("/logout");
  77. })
  78. })
  79. },
  80. show(data) {
  81. this.errors.clear();
  82. if(data) {
  83. Object.assign(this.form, data);
  84. }
  85. this.$refs['dlg'].show();
  86. },
  87. md5(text) {
  88. return crypto.createHash('md5').update(text, "utf8").digest('hex');
  89. }
  90. }
  91. }
  92. </script>