Browse Source

忘记密码

zhaoxiaohai 3 years ago
parent
commit
fd3f8ccbf5

+ 198 - 0
pages/login/retrievePassword.js

@@ -0,0 +1,198 @@
+const _Http = getApp().globalData.http;
+import Toast from '@vant/weapp/toast/toast';
+const md5 = require('../../utils/md5');
+let passwordDowm = null;
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        from: {
+            accountno: "", //账户名
+            password: "", //验证码
+            newPassword: "", //新密码
+            verifyNewPassword: "", //确认密码
+        },
+        disabled: true, //修改按钮禁用
+        loading: false,
+        confirmPassword: "", //两次密码是否一致
+        countDown: "", //倒计时
+    },
+
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad(options) {
+
+    },
+    /* 获取验证码 */
+    getPassword() {
+        let accountno = this.data.from.accountno;
+        if (!accountno) return Toast({
+            message: '您还未填写账户名称',
+            position: 'bottom'
+        });
+        if (this.data.countDown != '') return Toast({
+            message: '您已发送验证码,请勿重复获取',
+            position: 'bottom'
+        });
+        _Http.base({
+            "classname": "common.usercenter.usercenter",
+            "method": "forgetPassword_getPassWord",
+            "content": {
+                accountno
+            }
+        }, false).then(res => {
+            if (res.code != 1) return Toast({
+                message: res.data,
+                position: 'bottom'
+            });
+            this.setData({
+                countDown: 30
+            })
+            passwordDowm = setInterval(() => {
+                let countDown = (this.data.countDown == 0) ? '' : this.data.countDown - 1;
+                this.setData({
+                    countDown
+                })
+                if (countDown == '') clearInterval(passwordDowm)
+            }, 1000);
+            Toast({
+                message: res.msg,
+                position: 'bottom'
+            });
+        })
+    },
+    /* 表单输入 */
+    formInput(e) {
+        let v = e.detail.value.trim(),
+            name = e.currentTarget.dataset.name;
+        this.setData({
+            [`from.${name}`]: v
+        });
+        let disabled = false,
+            from = this.data.from;
+        for (let i in from) {
+            if (from[i] == '') disabled = true;
+        }
+        this.setData({
+            disabled
+        })
+    },
+    /* 验证确认密码 */
+    passwordBlur() {
+        let {
+            from
+        } = this.data,
+            confirmPassword = from.newPassword == from.verifyNewPassword;
+        if (from.newPassword == '' || from.verifyNewPassword == '') confirmPassword = ""
+        this.setData({
+            confirmPassword
+        })
+    },
+    /* 清除确认密码 */
+    clearNewPassword() {
+        this.setData({
+            ['from.verifyNewPassword']: '',
+            confirmPassword: ""
+        })
+    },
+    /* 修改密码 */
+    changePassword() {
+        if (this.data.disabled || this.data.loading) return;
+        if (this.data.confirmPassword != true) return Toast({
+            message: '请检查新密码与确认密码',
+            position: 'bottom'
+        });
+        let from = this.data.from;
+        this.setData({
+            loading: true
+        })
+        _Http.base({
+            "classname": "common.usercenter.usercenter",
+            "method": "forgetPassword_changePassWord",
+            "content": {
+                "password": md5.hexMD5(from.password),
+                "accountno": from.accountno,
+                "newpassword": md5.hexMD5(from.newPassword)
+            }
+        }).then(res => {
+            this.setData({
+                loading: false
+            })
+            if (res.msg != '成功') return Toast({
+                message: res.msg,
+                position: 'bottom'
+            });
+            this.setData({
+                disabled: true
+            })
+            wx.showToast({
+                title: '修改成功!',
+            })
+            let pages = getCurrentPages(),
+                prevPage = pages[pages.length - 2];
+            prevPage.setData({
+                password: "" // 需要传递的值
+            })
+            wx.setStorageSync('loginMsg', {
+                "accountno": this.data.from.accountno,
+                "password": this.data.from.newPassword
+            })
+            setTimeout(() => {
+                wx.navigateBack({
+                    delta: 0
+                })
+            }, 300)
+        })
+    },
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady() {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow() {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide() {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload() {
+
+    },
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh() {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom() {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage() {
+
+    }
+})

+ 4 - 0
pages/login/retrievePassword.json

@@ -0,0 +1,4 @@
+{
+    "navigationBarTitleText": "找回密码",
+    "usingComponents": {}
+}

+ 1 - 0
pages/login/retrievePassword.scss

@@ -0,0 +1 @@
+@import "../../pages/tabbar/mine/changePassword/index.scss";

+ 32 - 0
pages/login/retrievePassword.wxml

@@ -0,0 +1,32 @@
+<My_card custom-class='input-field'>
+    <view class="icon-box">
+        <text class="iconfont icon-a-biaoqianlanwodexuanzhong" />
+    </view>
+    <input class="input" type="text" bindinput="formInput" data-name="accountno" placeholder='请填写账户名' />
+</My_card>
+<My_card custom-class='input-field'>
+    <view class="icon-box">
+        <text class="iconfont icon-hujiao" />
+    </view>
+    <input class="input" type="number" bindinput="formInput" data-name="password" placeholder='请填写验证码' />
+    <view class="auth-code" bindtap="getPassword">{{countDown?countDown+'s':'获取验证码'}}</view>
+</My_card>
+<My_card custom-class='input-field'>
+    <view class="icon-box">
+        <text class="iconfont icon-a-wodemima" />
+    </view>
+    <input class="input" password bindinput="formInput" bindblur='passwordBlur' data-name="newPassword" placeholder='请设置6-20位新密码' />
+</My_card>
+<My_card custom-class='input-field'>
+    <view class="icon-box">
+        <text class="iconfont icon-a-wodemima" />
+    </view>
+    <input class="input" password value="{{from.verifyNewPassword}}" bindinput="formInput" bindblur='passwordBlur' data-name="verifyNewPassword" placeholder='请确认新密码' />
+    <view wx:if="{{confirmPassword===false}}" class="errmsg">两次密码不一致
+        <van-icon class="iconfont" name="clear" bind:click="clearNewPassword" />
+    </view>
+</My_card>
+<view style="width: 100%; text-align: center;margin-top: 100rpx;">
+    <van-button disabled='{{disabled}}' bindtap="changePassword" loading='{{loading}}' loading-text="修改中..." type="primary" custom-class='but-style'>确定修改</van-button>
+</view>
+<van-toast id="van-toast" />