ResetPassword.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <div class="container">
  3. <div role="form">
  4. <div class="form-group" :class="{'has-error has-feedback': (newPasswordCheckResult.length > 0)}">
  5. <label for="newPassword" class="control-label">{{ $t("lang.ResetPassword.newPassword") }}</label>
  6. <input
  7. id="newPassword" v-model="newPassword" type="password" class="form-control" autocomplete="off" :placeholder="$t('lang.ResetPassword.enterNewPassword')"
  8. @input="handlerPasswordStrength1"
  9. />
  10. <span v-if="newPasswordCheckResult.length > 0" class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true" />
  11. <span v-if="newPasswordCheckResult.length > 0" class="control-label" for="newPassword">{{ newPasswordCheckResult }}</span>
  12. </div>
  13. <div class="form-group" :class="{'has-error has-feedback': (newPassword2CheckResult.length > 0)}">
  14. <label for="newPassword2" class="control-label">{{ $t("lang.ResetPassword.confirmPassword") }}</label>
  15. <input
  16. id="newPassword2" v-model="newPassword2" autocomplete="off" class="form-control" type="password"
  17. :placeholder="$t('lang.ResetPassword.enterConfirmPassword')"
  18. @input="handlerPasswordStrength2"
  19. />
  20. <span v-if="newPassword2CheckResult.length > 0" class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true" />
  21. <span v-if="newPassword2CheckResult.length > 0" class="control-label" for="newPassword">{{ newPassword2CheckResult }}</span>
  22. </div>
  23. <div class="form-group">
  24. <div class="col-sm-offset-4 col-sm-4">
  25. <button type="primary" class="btn btn-default" @click="resetPassword">{{ $t("lang.ResetPassword.resetPassword") }}</button>
  26. </div>
  27. </div>
  28. </div>
  29. <Loading v-if="loading" />
  30. </div>
  31. </template>
  32. <script>
  33. import Common from '../common/Common.js';
  34. import { Notify } from 'pc-component-v3';
  35. import PasswordService from '../common/PasswordService.js';
  36. export default {
  37. components: {},
  38. props: {},
  39. emits: ['finishTask'],
  40. data: function () {
  41. return {
  42. newPassword: null,
  43. newPasswordCheckResult: '',
  44. newPassword2: null,
  45. newPassword2CheckResult: '',
  46. loading: false,
  47. };
  48. },
  49. watch: {
  50. },
  51. mounted: function () {
  52. },
  53. methods: {
  54. resetPassword: function () {
  55. let _self = this;
  56. let newPassword = _self.newPassword;
  57. let newPassword2 = _self.newPassword2;
  58. if (newPassword == null && newPassword2 == null) {
  59. Notify.error(_self.$t('lang.Notify.prompt'), _self.$t('lang.ResetPassword.describe1'), false);
  60. return;
  61. }
  62. if (newPassword.indexOf(' ') > -1) {
  63. Notify.error(_self.$t('lang.Notify.prompt'), _self.$t('lang.ResetPassword.describe2'), false);
  64. return;
  65. }
  66. if (newPassword != newPassword2) {
  67. Notify.error(
  68. _self.$t('lang.Notify.prompt'),
  69. _self.$t('lang.ResetPassword.describe3'),
  70. false,
  71. );
  72. return;
  73. }
  74. let message = PasswordService.handlerPasswordStrength(this.$i18n.locale,newPassword);
  75. if(message != null && message.length > 0){
  76. Notify.error(_self.$t('lang.Notify.warning'), message, false);
  77. return;
  78. }
  79. this.loading = true;
  80. $.ajax({
  81. url: Common.getApiURL('userResource/resetPassword'),
  82. async: false,
  83. type: 'post',
  84. dataType: 'json',
  85. data: {
  86. newPassword: newPassword,
  87. newPassword2: newPassword2,
  88. },
  89. beforeSend: function (request) {
  90. Common.addTokenToRequest(request);
  91. },
  92. success: function (data) {
  93. console.log(data);
  94. _self.loading = false;
  95. if (data.errorCode == 0) {
  96. Notify.success(_self.$t('lang.ResetPassword.resetPassword'), data.errorMessage, 1500);
  97. _self.$emit('finishTask');
  98. }else{
  99. Notify.error(_self.$t('lang.ResetPassword.resetPassword'), data.errorMessage, false);
  100. }
  101. },
  102. error: function (XMLHttpRequest, textStatus, errorThrown) {
  103. _self.loading = true;
  104. Common.processException(
  105. XMLHttpRequest,
  106. textStatus,
  107. errorThrown,
  108. );
  109. },
  110. });
  111. },
  112. handlerPasswordStrength1: function(){
  113. if(this.newPassword == null || this.newPassword.length == 0){
  114. this.newPasswordCheckResult = '';
  115. return;
  116. }
  117. let message = PasswordService.handlerPasswordStrength(this.$i18n.locale,this.newPassword);
  118. if(message != null && message.length > 0){
  119. this.newPasswordCheckResult = message;
  120. }else{
  121. this.newPasswordCheckResult = '';
  122. }
  123. },
  124. handlerPasswordStrength2: function(){
  125. if(this.newPassword2 == null || this.newPassword2.length2 == 0){
  126. this.newPassword2CheckResult = '';
  127. return;
  128. }
  129. if(this.newPassword != this.newPassword2){
  130. this.newPassword2CheckResult = this.$t('lang.ResetPassword.describe4');
  131. }else{
  132. this.newPassword2CheckResult = '';
  133. }
  134. },
  135. },
  136. };
  137. </script>
  138. <style scoped>
  139. .grid-container {
  140. display: grid;
  141. grid-template-columns: 100%;
  142. grid-template-rows: 10% 90%;
  143. /*视口被均分为 100 单位的 vh 占据整个窗口,扣掉顶部 topNav 的距离后,计算得到 responseOrganizationSelect 的高度*/
  144. height: calc(100vh - 85px);
  145. width: 100%;
  146. }
  147. .grid-item-1 {
  148. grid-column: 1 / 2;
  149. grid-row: 1 / 2;
  150. }
  151. </style>