小程序修改密码
This commit is contained in:
		@@ -24,6 +24,10 @@ Page({
 | 
			
		||||
        id: "myOrder",
 | 
			
		||||
        title: "我的订单",
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        id: "updpwd",
 | 
			
		||||
        title: "修改密码",
 | 
			
		||||
      },
 | 
			
		||||
      {
 | 
			
		||||
        id: "logout",
 | 
			
		||||
        color: 'red',
 | 
			
		||||
@@ -140,6 +144,12 @@ Page({
 | 
			
		||||
        })
 | 
			
		||||
        break
 | 
			
		||||
 | 
			
		||||
      // 修改密码
 | 
			
		||||
      case "updpwd":
 | 
			
		||||
        wx.navigateTo({
 | 
			
		||||
          url: '/pages/person/updpwd'
 | 
			
		||||
        })
 | 
			
		||||
        break
 | 
			
		||||
      // 退出登录
 | 
			
		||||
      case "logout":
 | 
			
		||||
        wx.clearStorageSync()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										105
									
								
								weixin-miniprogram/pages/person/updpwd.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								weixin-miniprogram/pages/person/updpwd.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
			
		||||
// pages/person/updpwd.js
 | 
			
		||||
// 获取应用实例
 | 
			
		||||
const app = getApp()
 | 
			
		||||
 | 
			
		||||
Page({
 | 
			
		||||
  data: {
 | 
			
		||||
    waiting: false,
 | 
			
		||||
 | 
			
		||||
    oldpwd: '', // 旧密码
 | 
			
		||||
    newpwd: '', // 新密码
 | 
			
		||||
    newpwd2: '' // 确认新密码
 | 
			
		||||
  },
 | 
			
		||||
  // 表单提交事件
 | 
			
		||||
  submitForm(e) {
 | 
			
		||||
    // 获取表单数据
 | 
			
		||||
    let { oldpwd, newpwd, newpwd2 } = e.detail.value
 | 
			
		||||
    // 验证表单数据
 | 
			
		||||
    if (!newpwd || !newpwd2) {
 | 
			
		||||
      // 新密码不能为空
 | 
			
		||||
      wx.showToast({
 | 
			
		||||
        title: '新密码不能为空',
 | 
			
		||||
        icon: 'none'
 | 
			
		||||
      })
 | 
			
		||||
    } else if (newpwd !== newpwd2) {
 | 
			
		||||
      // 两次密码不一致
 | 
			
		||||
      wx.showToast({
 | 
			
		||||
        title: '两次密码不一致',
 | 
			
		||||
        icon: 'none'
 | 
			
		||||
      })
 | 
			
		||||
    } else {
 | 
			
		||||
      let userInfo = wx.getStorageSync("userInfo")
 | 
			
		||||
      if (!userInfo || !userInfo.id) {
 | 
			
		||||
        console.log("userInfo", userInfo)
 | 
			
		||||
        wx.showModal({
 | 
			
		||||
          title: '登陆失效',
 | 
			
		||||
          content: '请重新登录',
 | 
			
		||||
          showCancel: false,
 | 
			
		||||
          complete: (res) => {
 | 
			
		||||
            wx.navigateBack()
 | 
			
		||||
          }
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      // 调用后台接口修改密码
 | 
			
		||||
      this.setData({
 | 
			
		||||
        waiting: true,
 | 
			
		||||
      })
 | 
			
		||||
      wx.showNavigationBarLoading()
 | 
			
		||||
      var that = this
 | 
			
		||||
      wx.request({
 | 
			
		||||
        url: app.globalData.baseUrl + '/user/updatePwd', // 后台接口地址
 | 
			
		||||
        method: 'POST',
 | 
			
		||||
        data: {
 | 
			
		||||
          userId: userInfo.id,
 | 
			
		||||
          oldpwd, // 旧密码
 | 
			
		||||
          newpwd // 新密码
 | 
			
		||||
        },
 | 
			
		||||
        header: {
 | 
			
		||||
          'content-type': 'application/x-www-form-urlencoded'
 | 
			
		||||
        },
 | 
			
		||||
        success(res) {
 | 
			
		||||
          wx.hideNavigationBarLoading()
 | 
			
		||||
          that.setData({
 | 
			
		||||
            waiting: false,
 | 
			
		||||
          })
 | 
			
		||||
          console.log("res.data.success", res.data.success)
 | 
			
		||||
          // 请求成功
 | 
			
		||||
          if (res.data.success) {
 | 
			
		||||
            // 修改成功
 | 
			
		||||
            wx.showModal({
 | 
			
		||||
              title: '修改成功',
 | 
			
		||||
              content: '密码修改成功',
 | 
			
		||||
              showCancel: false,
 | 
			
		||||
              complete: (res) => {
 | 
			
		||||
                // 返回上一页
 | 
			
		||||
                wx.navigateBack()
 | 
			
		||||
              }
 | 
			
		||||
            })
 | 
			
		||||
          } else {
 | 
			
		||||
            // 修改失败
 | 
			
		||||
            // wx.showToast({
 | 
			
		||||
            //   title: res.data.msg,
 | 
			
		||||
            //   icon: 'none'
 | 
			
		||||
            // })
 | 
			
		||||
            wx.showModal({
 | 
			
		||||
              title: '修改失败',
 | 
			
		||||
              content: res.data.msg,
 | 
			
		||||
              showCancel: false
 | 
			
		||||
            })
 | 
			
		||||
          }
 | 
			
		||||
        },
 | 
			
		||||
        fail(err) {
 | 
			
		||||
          wx.hideNavigationBarLoading()
 | 
			
		||||
          that.setData({
 | 
			
		||||
            waiting: false,
 | 
			
		||||
          })
 | 
			
		||||
          // 请求失败
 | 
			
		||||
          wx.showToast({
 | 
			
		||||
            title: '网络异常,请稍后重试',
 | 
			
		||||
            icon: 'none'
 | 
			
		||||
          })
 | 
			
		||||
        },
 | 
			
		||||
      })
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										4
									
								
								weixin-miniprogram/pages/person/updpwd.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								weixin-miniprogram/pages/person/updpwd.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
{
 | 
			
		||||
  "usingComponents": {},
 | 
			
		||||
  "navigationBarTitleText": "修改密码"
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								weixin-miniprogram/pages/person/updpwd.wxml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								weixin-miniprogram/pages/person/updpwd.wxml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
<!-- pages/person/updpwd.wxml -->
 | 
			
		||||
<view class="container">
 | 
			
		||||
  <view class="title">修改密码</view>
 | 
			
		||||
  <view style="text-align: center; margin-bottom: 12px;">
 | 
			
		||||
    * 微信快捷登录的初始密码为空
 | 
			
		||||
  </view>
 | 
			
		||||
  <form bindsubmit="submitForm" report-submit="true">
 | 
			
		||||
    <view class="input-group">
 | 
			
		||||
      <input type="password" name="oldpwd" placeholder="请输入旧密码" required />
 | 
			
		||||
    </view>
 | 
			
		||||
    <view class="input-group">
 | 
			
		||||
      <input type="password" name="newpwd" placeholder="请输入新密码" required />
 | 
			
		||||
    </view>
 | 
			
		||||
    <view class="input-group">
 | 
			
		||||
      <input type="password" name="newpwd2" placeholder="请确认新密码" required />
 | 
			
		||||
    </view>
 | 
			
		||||
    <button disabled="{{ waiting }}" type="primary" form-type="submit">提交</button>
 | 
			
		||||
  </form>
 | 
			
		||||
</view>
 | 
			
		||||
							
								
								
									
										31
									
								
								weixin-miniprogram/pages/person/updpwd.wxss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								weixin-miniprogram/pages/person/updpwd.wxss
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
/* pages/person/updpwd.wxss */
 | 
			
		||||
.container {
 | 
			
		||||
  padding: 20rpx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.title {
 | 
			
		||||
  font-size: 36rpx;
 | 
			
		||||
  font-weight: bold;
 | 
			
		||||
  text-align: center;
 | 
			
		||||
  margin-bottom: 40rpx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.input-group {
 | 
			
		||||
  margin-bottom: 20rpx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
input {
 | 
			
		||||
  width: 100%;
 | 
			
		||||
  height: 80rpx;
 | 
			
		||||
  border: 1rpx solid #ccc;
 | 
			
		||||
  border-radius: 10rpx;
 | 
			
		||||
  padding: 0 20rpx;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
button {
 | 
			
		||||
  width: 100%;
 | 
			
		||||
  height: 80rpx;
 | 
			
		||||
  background-color: #1aad19;
 | 
			
		||||
  color: white;
 | 
			
		||||
  border-radius: 10rpx;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user