Browse Source

修改用户密码

xiaohaizhao 2 years ago
parent
commit
15442954ce

+ 103 - 0
pages/index/userCenter/changePassword/index.js

@@ -0,0 +1,103 @@
+const md5 = require("../../../../utils/md5");
+const _Http = getApp().globalData.http;
+import Toast from '@vant/weapp/toast/toast';
+Page({
+    /**
+     * 页面的初始数据
+     */
+    data: {
+        from: {
+            password: "", //原密码
+            newPassword: "", //新密码
+            verifyNewPassword: "" //确认密码
+        },
+        disabled: true,
+        loading: false,
+        confirmPassword: "",
+    },
+
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad(options) {
+
+    },
+    /* 修改密码 */
+    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.basic({
+            "classname": "common.usercenter.usercenter",
+            "method": "changePassWord",
+            "content": {
+                "password": md5.hexMD5(from.password),
+                "newpassword": md5.hexMD5(from.newPassword)
+            }
+        }).then(res => {
+            console.log(res)
+            this.setData({
+                loading: false
+            })
+            if (res.msg != '成功') return wx.showToast({
+                title: res.msg,
+                icon: "none"
+            })
+            /* Toast({
+                           message: res.msg,
+                           position: 'bottom'
+                       }); */
+            this.setData({
+                disabled: true
+            })
+            wx.showToast({
+                title: '修改成功!',
+            })
+            setTimeout(() => {
+                wx.navigateBack({
+                    delta: 0
+                })
+            }, 300)
+        })
+    },
+    /* 表单输入 */
+    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: ""
+        })
+    },
+})

+ 4 - 0
pages/index/userCenter/changePassword/index.json

@@ -0,0 +1,4 @@
+{
+    "navigationBarTitleText": "修改密码",
+    "usingComponents": {}
+}

+ 64 - 0
pages/index/userCenter/changePassword/index.scss

@@ -0,0 +1,64 @@
+.input-field {
+    width: 690rpx;
+    background-color: #fff;
+    box-sizing: border-box;
+    border-radius: 16rpx;
+    display: flex;
+    position: relative;
+    padding: 26rpx 20rpx 24rpx 30rpx;
+    margin: 20rpx auto;
+
+    .icon-box {
+        width: 40rpx;
+        height: 40rpx;
+        margin-right: 50rpx;
+
+        .iconfont {
+            font-size: 40rpx;
+            color: var(--assist);
+        }
+    }
+
+    .input {
+        flex: 1;
+        font-size: 28rpx;
+        font-family: PingFang SC-Regular, PingFang SC;
+        color: #333333;
+        margin-top: -5rpx;
+    }
+
+    .auth-code {
+        width: 180rpx;
+        height: 40rpx;
+        line-height: 40rpx;
+        text-align: center;
+        flex-shrink: 0;
+        font-size: 28rpx;
+        font-family: PingFang SC-Regular, PingFang SC;
+        color: #3874F6;
+        border-left: 1rpx solid #EEE;
+    }
+
+    .errmsg {
+        font-size: 24rpx;
+        font-family: PingFang SC-Regular, PingFang SC;
+        color: #FF3B30;
+
+        .iconfont {
+            padding-left: 10rpx;
+            color: #BBBBBB;
+        }
+    }
+}
+
+.but-style {
+    width: 500rpx;
+    height: 90rpx;
+    background: #3874F6 !important;
+    border-radius: 45rpx !important;
+    opacity: 0.85;
+    font-size: 28rpx;
+    font-family: PingFang SC-Bold, PingFang SC;
+    font-weight: bold;
+    color: #FFFFFF !important;
+}

+ 26 - 0
pages/index/userCenter/changePassword/index.wxml

@@ -0,0 +1,26 @@
+<view class='input-field'>
+    <view class="icon-box">
+        <text class="iconfont icon-a-wodemima" />
+    </view>
+    <input class="input" bindinput="inputNumber" password bindinput="formInput" data-name="password" placeholder='请填写原密码' />
+</view>
+<view 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位新密码' />
+</view>
+<view class='input-field'>
+    <view class="icon-box">
+        <text class="iconfont icon-a-wodemima" />
+    </view>
+    <input class="input" password bindinput="formInput" value="{{from.verifyNewPassword}}" bindblur='passwordBlur' data-name="verifyNewPassword" placeholder='请确认新密码' />
+    <view wx:if="{{confirmPassword===false}}" class="errmsg">两次密码不一致
+        <van-icon class="iconfont" name="clear" bind:click="clearNewPassword" />
+    </view>
+</view>
+<view style="width: 100%; text-align: center;margin-top: 100rpx;">
+    <van-button disabled='{{disabled}}' loading='{{loading}}' bindtap="changePassword" loading-text="修改中..." custom-class='but-style'>确定修改</van-button>
+</view>
+
+<van-toast id="van-toast" />