小程序安全设置-弹出框输入获取值

2022-04-29 09:54:16 浏览数 (2)

小程序安全设置

代码语言:javascript复制
Page({
  /**
   * 页面的初始数据
   */
  data: {
    anquan: '',
    detailanquan: '',
    hiddenmodalput: true,
    //可以通过hidden是否掩藏弹出框的属性,来指定那个弹出框
    idCard: '',
    password: '',
    phone: '',
    email: '',
    wxUnionid: '',
    // 修改密码
    psd: "",
    newpsd: '',
  },
  // 获取身份认证:
  idCard: function(e) {
    this.setData({
      idCard: e.detail.value,
    })
    console.log("获取身份认证:"   this.data.idCard);
  },
  // 获取登录密码:
  password: function(e) {
    this.setData({
      password: e.detail.value,
    })
    console.log("获取登录密码:"   this.data.password);
  },
  // 获取绑定手机:
  phone: function(e) {
    this.setData({
      phone: e.detail.value,
    })
    console.log("获取绑定手机:"   this.data.phone);
  },
  // 获取绑定邮箱:
  email: function(e) {
    this.setData({
      email: e.detail.value,
    })
    console.log("获取绑定邮箱:"   this.data.email);
  },
  // 获取微信绑定:
  wxUnionid: function(e) {
    this.setData({
      wxUnionid: e.detail.value,
    })
    console.log("获取微信绑定:"   this.data.wxUnionid);
  },

  // 修改按钮
  sfrz: function(e) {
    console.log("身份认证", this.data.idCard);
    wx.request({

      method: 'POST',
      header: {
        'Authorization': 'Bearer'   wx.getStorageSync('token'),
      },
      success(res) {
        console.log("保存成功", res.data);
        if (res == null || res.data == null) {
          console.error('网络请求失败');
          return;
        }
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 500
        })
      }
    })
  },
  // 修改登录密码
  dlmm: function(e) {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput
    })
  },
  cancelM: function(e) {
    this.setData({
      hiddenmodalput: true,
    })
  },

  confirmM: function(e) {
    console.log("原密码"   this.data.psd   "新密码"   this.data.newpsd);
    this.setData({
      hiddenmodalput: true,
    })
    wx.request({

      method: 'POST',
      header: {
        'Authorization': 'Bearer'   wx.getStorageSync('token'),
      },
      success(res) {
        console.log("保存成功", res.data);
        if (res.data.code == 0) {
          wx.showToast({
            title: '保存失败',
            icon: 'success',
            duration: 500
          })
        }
        if (res == null || res.data == null) {
          console.error('网络请求失败');
          return;
        }
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 500
        })
      }
    })
  },

  ipsd: function(e) {
    this.setData({
      psd: e.detail.value
    })
  },
  newipsd: function(e) {
    this.setData({
      newpsd: e.detail.value
    })
  },

  // 绑定手机
  bdsj: function(e) {
    console.log("绑定手机", this.data.phone);
    wx.request({

      method: 'POST',
      header: {
        'Authorization': 'Bearer'   wx.getStorageSync('token'),
      },
      success(res) {
        console.log("保存成功", res.data);
        if (res == null || res.data == null) {
          console.error('网络请求失败');
          return;
        }
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 500
        })
      }
    })
  },
  bdyx: function(e) {
    console.log("绑定邮箱", this.data.email);
    wx.request({

      method: 'POST',
      header: {
        'Authorization': 'Bearer'   wx.getStorageSync('token'),
      },
      success(res) {
        console.log("保存成功", res.data);
        if (res == null || res.data == null) {
          console.error('网络请求失败');
          return;
        }
        wx.showToast({
          title: '保存成功',
          icon: 'success',
          duration: 500
        })
      }
    })
  },
  wxbd: function(e) {
    console.log("微信绑定", this.data.wxUnionid);
    wx.showModal({
      title: '提示',
      content: '解除微信绑定,注销账号! 是否确定?',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.request({
 
            data: this.data.wxUnionid,
            method: 'POST',
            header: {
              'Authorization': 'Bearer'   wx.getStorageSync('token'),
            },
            success(res) {
              console.log("解绑成功", res.data);
              if (res == null || res.data == null) {
                console.error('网络请求失败');
                return;
              }
              wx.showToast({
                title: '保存成功',
                icon: 'success',
                duration: 500
              })
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    wx.request({

      method: 'GET',
      header: {
        'Authorization': 'Bearer'   wx.getStorageSync('token')
      },
      success(res) {
        console.log("安全设置", res.data.data);
        var pass = res.data.data.user.password
        if (pass != null) {
          let password = "**********";
          let passs = password;
          that.setData({
            idCard: res.data.data.userDetail.idCard,
            // password: res.data.data.user.password,
            password: passs,
            phone: res.data.data.user.phone,
            email: res.data.data.user.email,
            wxUnionid: res.data.data.user.wxUnionid,
          })
        } else {
          that.setData({
            idCard: res.data.data.userDetail.idCard,
            password: res.data.data.user.password,
            phone: res.data.data.user.phone,
            email: res.data.data.user.email,
            wxUnionid: res.data.data.user.wxUnionid,
          })
        }

        wx.showToast({
          title: '加载成功',
          icon: 'loading',
          duration: 500
        })
      }
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    var that = this;
    wx.request({

      method: 'GET',
      header: {
        'Authorization': 'Bearer'   wx.getStorageSync('token')
      },
      success(res) {
        console.log("安全设置", res.data.data);
        var pass = res.data.data.user.password
        if (pass != null) {
          let password = "**********";
          let passs = password;
          that.setData({
            idCard: res.data.data.userDetail.idCard,
            // password: res.data.data.user.password,
            password: passs,
            phone: res.data.data.user.phone,
            email: res.data.data.user.email,
            wxUnionid: res.data.data.user.wxUnionid,
          })
        } else {
          that.setData({
            idCard: res.data.data.userDetail.idCard,
            password: res.data.data.user.password,
            phone: res.data.data.user.phone,
            email: res.data.data.user.email,
            wxUnionid: res.data.data.user.wxUnionid,
          })
        }
        wx.showToast({
          title: '加载成功',
          icon: 'loading',
          duration: 500
        })
      },
      complete: function(res) {
        wx.stopPullDownRefresh();
      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})
代码语言:javascript复制
 <view class='item'>
    登录密码
    <view class='bk'>
      <!-- name="password" -->
      <input class="textarea" placeholder="{{password}}" value='{{password}}' bindinput="password" maxlength='100' auto-height disabled/>
    </view>

    <button class='btn' bindtap='dlmm'>修改</button>
    <modal hidden="{{hiddenmodalput}}" title="修改密码" confirm-text="提交" cancel-text="取消" bindcancel="cancelM" bindconfirm="confirmM">
      <input bindinput='ipsd' type='text' placeholder="请输入原密码..." auto-focus/>
      <input bindinput='newipsd' type='password' placeholder="请输入新密码..." />
    </modal>

  </view>

0 人点赞