zhpassword.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view>
  4. <cu-custom bgImage="/static/bg.png" :isBack="true">
  5. <template v-slot:content>
  6. <text class="text-black">重置密码</text>
  7. </template>
  8. </cu-custom>
  9. <view class="padding">
  10. <uni-forms ref="pwdFormX" :model="pwdForm" :label-width="130" :rules="rules">
  11. <uni-forms-item class="text-bold text-black" label="用户名" name="username">
  12. <uni-easyinput type="username" v-model="pwdForm.username"/>
  13. </uni-forms-item>
  14. <uni-forms-item class="text-bold text-black" label="新密码" name="password">
  15. <uni-easyinput type="password" v-model="pwdForm.password"/>
  16. </uni-forms-item>
  17. <uni-forms-item class="text-bold text-black" label="确认密码" name="confirmPassword">
  18. <uni-easyinput type="password" v-model="pwdForm.confirmPassword"/>
  19. </uni-forms-item>
  20. <uni-forms-item class="text-bold text-black" label="验证码" name="code">
  21. <uni-easyinput type="text" v-model="pwdForm.code" placeholder="请输入验证码" :clearable="false"/>
  22. <view class="yzmbt" @click="getEmailcodeSele">
  23. <text>{{huoquyzm}}</text>
  24. </view>
  25. <view class="contentInRowL" style="margin-top: 20rpx;">
  26. <text class="text-grey">验证码将发至注册时填写的邮箱</text>
  27. </view>
  28. </uni-forms-item>
  29. <view class="margin-top text-center">
  30. <button class="cu-btn bg-zblue border lg margin-top" style="width: 100%;" @tap="submit">保存</button>
  31. </view>
  32. </uni-forms>
  33. </view>
  34. </view>
  35. </template>
  36. <script setup lang="ts">
  37. import CuCustom from '@/colorui/components/cu-custom.vue'
  38. import {ref} from "vue";
  39. import UniForms from "@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
  40. import UniFormsItem from "@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue";
  41. import UniEasyinput from "@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue";
  42. import Auth from "@/api/Auth";
  43. import {resetPassword,getcodeByUsername} from "@/api/Login";
  44. import MessageUtils from "@/utils/MessageUtils";
  45. const fontValue=ref(Auth.getfontSize());
  46. const pwdFormX = ref();
  47. const huoquyzm=ref('获取验证码');
  48. const timeCall=ref(0);
  49. const timer=ref();
  50. const pwdForm = ref({
  51. username: '',
  52. password: '',
  53. confirmPassword: '',
  54. code:''
  55. })
  56. const equalToPassword = (rule:any, value:any,data:any, callback:(err?:string)=>{}) => {
  57. if (pwdForm.value.password !== value) {
  58. callback('两次输入的密码不一致')
  59. } else {
  60. return true
  61. }
  62. }
  63. const rules = {
  64. username: {
  65. rules: [
  66. { required: true, errorMessage: '用户名不能为空', trigger: 'blur' }
  67. ]
  68. },
  69. password: {
  70. rules: [
  71. { required: true, errorMessage: '新密码不能为空', trigger: 'blur' },
  72. {
  73. minLength: 5,
  74. maxLength: 10,
  75. errorMessage: '长度在 {minLength} 到 {maxLength} 个字符',
  76. }
  77. ]
  78. },
  79. confirmPassword: {
  80. rules: [
  81. { required: true, errorMessage: '确认密码不能为空', trigger: 'blur' },
  82. { required: true, validateFunction: equalToPassword, trigger: 'blur' }
  83. ]
  84. }
  85. }
  86. //邮箱验证码
  87. const getEmailcodeSele = () =>{
  88. if(timeCall.value==0){
  89. getEmailcodeact();
  90. }
  91. else{
  92. return;
  93. }
  94. }
  95. const getEmailcodeact = () =>{
  96. console.log('getEmailcode',pwdForm.value.username);
  97. getcodeByUsername(pwdForm.value.username).then((res : any) => {
  98. console.log('getEmailcode',res);
  99. if(res.code==200){
  100. MessageUtils.success(res.msg);
  101. timeCall.value=60;
  102. timer.value = setInterval(() => {
  103. timeCall.value=timeCall.value-1;
  104. if(timeCall.value==0){
  105. clearInterval(timer.value);
  106. huoquyzm.value='获取验证码';
  107. }
  108. else{
  109. huoquyzm.value='重新获取'+'('+timeCall.value+')';
  110. }
  111. }, 1000);
  112. }
  113. else{
  114. MessageUtils.success(res.msg);
  115. }
  116. });
  117. }
  118. /** 提交按钮 */
  119. function submit() {
  120. pwdFormX.value.validate().then(() => {
  121. resetPassword(pwdForm.value)
  122. .then(() => {
  123. MessageUtils.success('重置成功');
  124. Auth.logout();
  125. // uni.reLaunch({
  126. // url: "/pages/login/login"
  127. // })
  128. })
  129. .catch((err) => {
  130. MessageUtils.error(err.msg);
  131. })
  132. })
  133. }
  134. </script>
  135. <style scoped>
  136. .yzmbt{
  137. margin-top: 16rpx;
  138. color: white;
  139. font-size: 26upx;
  140. width: 170rpx;
  141. height: 60rpx;
  142. line-height: 60rpx;
  143. text-align: center;
  144. margin-left: auto;
  145. margin-right: 10rpx;
  146. border-radius: 2rpx;
  147. background-color:#60BA63;
  148. }
  149. </style>