forget.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <view style="position: relative;">
  3. <view class="bg"></view>
  4. <view class="bg1"></view>
  5. <view class="back" @click="$back">
  6. <u-icon name="arrow-left" size="50" color="#919191"></u-icon>
  7. </view>
  8. <view class="content">
  9. <view class="top">
  10. <view class="title">
  11. <text>忘记登录密码</text>
  12. <text>输入手机号进行找回密码</text>
  13. </view>
  14. </view>
  15. <view style="width: 76%;margin-top: 80rpx;">
  16. <u-form :model="form" ref="uForm" :rules="rules" :error-type="['message']">
  17. <u-form-item label="手机号" prop="phone" label-width="150">
  18. <u-input :border="false" placeholder="请输入手机号" v-model="form.phone" type="number"></u-input>
  19. </u-form-item>
  20. <u-form-item label="验证码" prop="code" label-width="150">
  21. <view class="flex" >
  22. <u-input style="width: 100%;" :border="false" placeholder="请输入验证码" v-model="form.code" type="text"></u-input>
  23. <u-button shape="circle" slot="right" :custom-style="customStyle" size="mini" @click="getCode">{{codeTips}}</u-button>
  24. </view>
  25. </u-form-item>
  26. <u-form-item label="密码" prop="password" label-width="150">
  27. <u-input :border="false" placeholder="请设置新的登录密码" v-model="form.password" type="number"></u-input>
  28. </u-form-item>
  29. </u-form>
  30. </view>
  31. <view style="width: 86%;margin-top: 80rpx;">
  32. <view @click="login" class="btn cu-btn round" style="width:100%;height: 90rpx;font-size: 34rpx;">
  33. 确认修改并登录
  34. </view>
  35. </view>
  36. </view>
  37. <u-verification-code seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
  38. </view>
  39. </template>
  40. <script>
  41. import md5Libs from "uview-ui/libs/function/md5";
  42. export default {
  43. data() {
  44. return {
  45. customStyle:{
  46. 'backgroundColor':'#d18c42',
  47. 'color':'#ffffff'
  48. },
  49. codeTips: '',
  50. form:{
  51. phone:'',
  52. code:'',
  53. password:'',
  54. },
  55. rules: {
  56. phone: [{
  57. required: true,
  58. message: '请输入手机号',
  59. trigger: ['change', 'blur'],
  60. },{
  61. message: '手机号码不正确',
  62. trigger: ['change', 'blur'],
  63. validator: (rule, value, callback) => {
  64. return this.$u.test.mobile(value);
  65. },
  66. }],
  67. code: [{
  68. required: true,
  69. message: '请输入验证码',
  70. trigger: ['change', 'blur'],
  71. }],
  72. password: [{
  73. required: true,
  74. message: '请输入登录密码',
  75. trigger: ['change', 'blur'],
  76. }],
  77. }
  78. }
  79. },
  80. onReady() {
  81. this.$refs.uForm.setRules(this.rules);
  82. },
  83. methods: {
  84. async forgetPaw(){
  85. let p={
  86. type:2,
  87. phone:this.form.phone,
  88. password:md5Libs.md5(this.form.password),
  89. code:this.form.code
  90. }
  91. let res=await this.$api.accout.forgetPaw(p)
  92. uni.navigateBack({
  93. delta:1
  94. })
  95. this.$u.toast('找回成功,请登录')
  96. },
  97. async login(){
  98. this.$refs.uForm.validate(valid => {
  99. if (valid) {
  100. this.forgetPaw()
  101. }
  102. });
  103. },
  104. codeChange(text) {
  105. this.codeTips = text;
  106. },
  107. // 获取验证码
  108. getCode() {
  109. if (this.$isEmpty(this.form.phone)) {
  110. this.$u.toast('请输入手机号')
  111. return
  112. }
  113. if (this.$refs.uCode.canGetCode) {
  114. // 模拟向后端请求验证码
  115. uni.showLoading({
  116. title: '正在获取验证码',
  117. mask: true
  118. })
  119. setTimeout(() => {
  120. let params={
  121. phone:this.form.phone
  122. }
  123. let p=this.$u.queryParams(params)
  124. this.$api.sms.send(p).then(res=>{
  125. if (res.data=="success") {
  126. this.$u.toast('验证码已发送');
  127. // 通知验证码组件内部开始倒计时
  128. }else{
  129. this.$u.toast(res.data);
  130. }
  131. this.$refs.uCode.start();
  132. })
  133. }, 2000);
  134. } else {
  135. this.$u.toast('倒计时结束后再发送');
  136. }
  137. },
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. $color:#d18c42;
  143. page{
  144. background-color: #FFFFFF;
  145. }
  146. .btn{
  147. background-color: $color;
  148. color:#FFFFFF;
  149. }
  150. .btn{
  151. background-color: $color;
  152. color:#FFFFFF;
  153. }
  154. .bg{
  155. z-index: 99;
  156. height: 400rpx;
  157. width: 400rpx;
  158. position: absolute;
  159. right: -240rpx;
  160. top: -240rpx;
  161. background-color: #d18c42;
  162. border-radius: 50%;
  163. box-shadow: 0rpx 0rpx 50rpx #c5803b;
  164. }
  165. .bg1{
  166. height: 460rpx;
  167. width: 460rpx;
  168. position: absolute;
  169. right: -240rpx;
  170. top: -240rpx;
  171. background-color: #d18c42;
  172. border-radius: 50%;
  173. box-shadow: #c6813b;
  174. }
  175. .back{
  176. position: absolute;
  177. top: var(--status-bar-height);
  178. left: 20rpx;
  179. padding-top: var(--status-bar-height);
  180. }
  181. .content{
  182. height: 90vh;
  183. display: flex;
  184. flex-direction: column;
  185. justify-content: center;
  186. align-items: center;
  187. .top{
  188. width: 76%;
  189. display: flex;
  190. .title{
  191. margin-right: 20rpx;
  192. display: flex;
  193. flex-direction: column;
  194. justify-content: center;
  195. align-items: flex-start;
  196. text-align: left;
  197. text:first-child{
  198. font-weight: 800;
  199. font-size: 60rpx;
  200. color: #000;
  201. margin-bottom: 20rpx;
  202. }
  203. text:last-child{
  204. font-size: 28rpx;
  205. color: #7f7f7f;
  206. }
  207. }
  208. }
  209. }
  210. </style>