RetrievePasswordStep1.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <a-form
  3. :model="userDto"
  4. name="basic"
  5. :label-col="{span: 6}"
  6. :wrapper-col="{ span: 14 }"
  7. @finish="onFinish"
  8. @finish-failed="onFinishFailed"
  9. >
  10. <a-form-item
  11. :label="$t('lang.RetrievePasswordStep1.yourEmail')"
  12. name="email"
  13. :rules="[{ required: true, message: $t('lang.RetrievePasswordStep1.pleaseEnterYourEmail') }]"
  14. >
  15. <a-input
  16. v-model:value="userDto.email"
  17. size="default"
  18. type="email"
  19. @input="inputName"
  20. />
  21. </a-form-item>
  22. <a-form-item
  23. :label="$t('lang.RetrievePasswordStep1.yourAccount')"
  24. name="loginName"
  25. :rules="[{ required: true, message: $t('lang.RetrievePasswordStep1.pleaseEnterYourAccount') }]"
  26. >
  27. <a-input
  28. v-model:value="userDto.loginName"
  29. size="default"
  30. />
  31. </a-form-item>
  32. <a-form-item :wrapper-col="{ offset: 6, span: 14 }">
  33. <a-button
  34. v-if="disabledBtn == false"
  35. type="primary"
  36. size="default"
  37. @click="sendUserVerificationCode"
  38. >
  39. {{ btntxt }}
  40. </a-button>
  41. <a-button
  42. v-else
  43. type="primary"
  44. size="default"
  45. >
  46. {{ btntxt }}
  47. </a-button>
  48. </a-form-item>
  49. <a-form-item
  50. v-if="isVerificationCode == true "
  51. :label="$t('lang.RetrievePasswordStep1.verificationCode')"
  52. name="verificationCode"
  53. :rules="[{ required: true, message: $t('lang.RetrievePasswordStep1.pleaseEnterVerificationVode') }]"
  54. >
  55. <a-input
  56. v-model:value="userDto.verificationCode"
  57. size="default"
  58. />
  59. </a-form-item>
  60. <div style="text-align: center;">
  61. <a-button
  62. type="primary"
  63. html-type="submit"
  64. >
  65. {{ $t('lang.RetrievePasswordStep1.nextStep') }}
  66. </a-button>
  67. </div>
  68. </a-form>
  69. </template>
  70. <script>
  71. import Common from '../common/Common.js';
  72. import UserVerificationCodeResource from '../api/base/UserVerificationCodeResource.js';
  73. import UserResource from '../api/base/UserResource.js';
  74. import { message } from 'ant-design-vue';
  75. export default {
  76. props: {
  77. userDtoProp: {
  78. type: Object,
  79. default() {
  80. return {};
  81. },
  82. },
  83. },
  84. emits: ['updateUserDto', 'next'],
  85. // 定义抛出的事件名称
  86. data: function () {
  87. return {
  88. userDto: {},
  89. errorText: '',
  90. disabledBtn: false,
  91. time: 60,
  92. btntxt: this.$t('lang.RetrievePasswordStep1.getVerificationCode'),
  93. isVerificationCode: false,
  94. };
  95. },
  96. watch: {
  97. userDtoProp: {
  98. handler(newVal, oldVal) {
  99. if (newVal != null) {
  100. this.userDto = JSON.parse(JSON.stringify(newVal));
  101. console.log(this.userDto);
  102. }
  103. },
  104. immediate: true,
  105. },
  106. },
  107. methods: {
  108. inputName: function () {
  109. this.userDto.loginName = this.userDto.email;
  110. },
  111. onFinish: function (values) {
  112. let _self = this;
  113. console.log('Success: %o', values);
  114. let data = {
  115. currentStep: 1,
  116. showPage: 1,
  117. };
  118. UserVerificationCodeResource.forgetPasswordVerifyIdentity(
  119. _self.userDto.loginName, _self.userDto.email, _self.userDto.verificationCode,
  120. ).then(
  121. baseObjectResponse => {
  122. if (baseObjectResponse.errorCode === 0) {
  123. console.log(baseObjectResponse);
  124. this.$emit('next', data);
  125. this.$emit('updateUserDto', _self.userDto);
  126. } else {
  127. message.error(baseObjectResponse.data);
  128. }
  129. },
  130. errorData => {
  131. Common.processException(errorData);
  132. },
  133. );
  134. },
  135. onFinishFailed: function (errorInfo) {
  136. console.log('Failed: %o', errorInfo);
  137. },
  138. /**
  139. * 发送验证码
  140. */
  141. sendUserVerificationCode: function (event) {
  142. var _self = this;
  143. if (_self.userDto.loginName == null) {
  144. message.error(_self.$t('lang.RetrievePasswordStep1.accountNumberCannotBeBlank'));
  145. return;
  146. }
  147. if (_self.userDto.email == null) {
  148. message.error(_self.$t('lang.RetrievePasswordStep1.mailboxCannotBeEmpty'));
  149. return;
  150. }
  151. UserVerificationCodeResource.retrievePasswordUserVerificationCode(
  152. _self.userDto.loginName, _self.userDto.email, '忘记密码',_self.$i18n.locale,
  153. ).then(
  154. baseObjectResponse => {
  155. if (baseObjectResponse.errorCode === 0) {
  156. message.success(baseObjectResponse.data);
  157. console.log(baseObjectResponse);
  158. _self.isVerificationCode = true;
  159. _self.timerStr();
  160. } else {
  161. message.error(baseObjectResponse.data);
  162. }
  163. },
  164. errorData => {
  165. Common.processException(errorData);
  166. },
  167. );
  168. },
  169. timerStr: function () {
  170. if (this.time > 0) {
  171. this.disabledBtn = true;
  172. this.time--;
  173. this.btntxt = this.time + '秒';
  174. setTimeout(this.timerStr, 1000);
  175. } else {
  176. this.time = 60;
  177. this.btntxt = this.$t('lang.RetrievePasswordStep1.getVerificationCode');
  178. this.disabledBtn = false;
  179. }
  180. },
  181. emailValidator: function (rule, val, callback) {
  182. const idcardReg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
  183. if (!idcardReg.test(val)) {
  184. callback(this.$t('lang.RetrievePasswordStep1.illegalFormat'));
  185. }
  186. callback();
  187. },
  188. },
  189. };
  190. </script>
  191. <style scoped>
  192. </style>