forgetpwd.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="">
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="登录"></fa-navbar>
  5. <view class="login">
  6. <view class="u-text-center"><u-avatar :size="150"></u-avatar></view>
  7. <view class="u-m-t-50">
  8. <u-form :model="form" ref="uForm">
  9. <u-form-item :label-position="labelPosition" label="类 型:" label-width="120">
  10. <u-radio-group v-model="form.type" @change="radioGroupChange" :width="radioCheckWidth" :wrap="radioCheckWrap">
  11. <u-radio shape="circle" :active-color="theme.bgColor" name="email">邮箱</u-radio>
  12. <u-radio shape="circle" :active-color="theme.bgColor" name="mobile">手机</u-radio>
  13. </u-radio-group>
  14. </u-form-item>
  15. <u-form-item :label-position="labelPosition" :label="form.type == 'email' ? '邮 箱:' : '手机号:'" prop="account" label-width="120">
  16. <u-input :border="border" :placeholder="form.type == 'email' ? '请填写邮箱' : '请填写手机号码'" v-model="form.account" />
  17. </u-form-item>
  18. <u-form-item :label-position="labelPosition" label="验证码:" prop="captcha" label-width="120">
  19. <u-input :border="border" placeholder="请输入验证码" v-model="form.captcha" type="text"></u-input>
  20. <u-button
  21. type="primary"
  22. hover-class="none"
  23. slot="right"
  24. :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }"
  25. size="mini"
  26. @click="getCode"
  27. >
  28. {{ codeTips }}
  29. </u-button>
  30. </u-form-item>
  31. <u-form-item :label-position="labelPosition" label="新密码:" prop="newpassword" label-width="120">
  32. <u-input :password-icon="true" :border="border" type="password" v-model="form.newpassword" placeholder="请输入密码"></u-input>
  33. </u-form-item>
  34. </u-form>
  35. </view>
  36. <view class="u-m-t-80">
  37. <u-button type="primary" hover-class="none" :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }" shape="circle" @click="submit">提交</u-button>
  38. </view>
  39. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { loginfunc } from '@/common/fa.mixin.js';
  45. export default {
  46. mixins: [loginfunc],
  47. onReady() {
  48. this.$refs.uForm.setRules(this.rules);
  49. },
  50. data() {
  51. return {
  52. labelPosition: 'left',
  53. border: false,
  54. radioCheckWidth: 'auto',
  55. radioCheckWrap: false,
  56. form: {
  57. account: '',
  58. newpassword: '',
  59. type: 'email',
  60. captcha: ''
  61. },
  62. rules: {
  63. account: [
  64. {
  65. validator: (rule, value, callback) => {
  66. rule.message = `请填写${this.form.type == 'email' ? '邮箱' : '手机号码'}`;
  67. return !!value;
  68. },
  69. message: '',
  70. trigger: 'blur'
  71. }
  72. ],
  73. newpassword: [
  74. {
  75. required: true,
  76. message: '请输入新密码',
  77. trigger: 'blur'
  78. }
  79. ],
  80. captcha: [
  81. {
  82. required: true,
  83. message: '请输入验证码',
  84. trigger: 'blur'
  85. }
  86. ]
  87. },
  88. codeTips: '',
  89. errorType: ['message']
  90. };
  91. },
  92. methods: {
  93. codeChange(text) {
  94. this.codeTips = text;
  95. },
  96. radioGroupChange(e) {
  97. this.form.type = e;
  98. },
  99. // 获取验证码
  100. getCode: async function(type) {
  101. if (this.$refs.uCode.canGetCode) {
  102. let res = {};
  103. if (this.form.type == 'email') {
  104. if (!this.$u.test.email(this.form.account)) {
  105. this.$u.toast('邮箱格式不正确!');
  106. return;
  107. }
  108. res = await this.$api.getEmsSend({
  109. email: this.form.account,
  110. event: 'resetpwd'
  111. });
  112. } else {
  113. if (!this.$u.test.mobile(this.form.account)) {
  114. this.$u.toast('手机号码格式不正确!');
  115. return;
  116. }
  117. res = await this.$api.getSmsSend({
  118. mobile: this.form.account,
  119. event: 'resetpwd'
  120. });
  121. }
  122. this.$u.toast(res.msg || '发送失败');
  123. if (res.code) {
  124. this.$refs.uCode.start();
  125. }
  126. } else {
  127. this.$u.toast('倒计时结束后再发送');
  128. }
  129. },
  130. submit() {
  131. this.$refs.uForm.validate(async valid => {
  132. if (valid) {
  133. let res = await this.$api.goResetpwd({
  134. type: this.form.type,
  135. mobile: this.form.account,
  136. email: this.form.account,
  137. newpassword: this.form.newpassword,
  138. captcha: this.form.captcha
  139. });
  140. if (!res.code) {
  141. this.$u.toast(res.msg);
  142. return;
  143. }
  144. setTimeout(() => {
  145. this.$Router.replace('/pages/login/login');
  146. }, 800);
  147. } else {
  148. this.$u.toast('验证失败');
  149. }
  150. });
  151. }
  152. }
  153. };
  154. </script>
  155. <style>
  156. page {
  157. background-color: #ffffff;
  158. }
  159. .login {
  160. padding: 20% 15%;
  161. }
  162. </style>