ll
liukangdong
2024-08-27 2c08a98f7e85ec7c9376f27a7933e75e44d672f7
wechat_staff/pages/login/index.js
@@ -3,7 +3,8 @@
  getDictData,
  getWxMiniPhone,
  loginByPhone,
  bindingOpenid
  bindingOpenid,
  wxLoginCustomer
} from '../../api/index'
Page({
@@ -16,6 +17,7 @@
    status: '0', // 标识
    countDown: 0,
    phone: '',
    openid:'',
    code: '',
    showModal: false,
    activeHtml: '',
@@ -54,24 +56,53 @@
      }, 1000)
    })
  },
  onShow(){
    wx.hideHomeButton()
  },
  handleJudge(e) {
    const flag = e.currentTarget.dataset.flag
    console.log(e);
    this.setData({ agreementFalg: flag, showModal: false })
  },
  loginPhone() {
    const {
      code,
      phone
      phone,
      openid
    } = this.data
    if (!this.data.agreementFalg) {
      return wx.showToast({
        title: '请先阅读并同意相关协议',
        icon: 'none'
      })
    }
    if (phone.length != 11) {
      return wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
    }
    if (!code) {
      return wx.showToast({
        title: '请输入验证码',
        icon: 'none'
      })
    }
    loginByPhone({
      code,
      openid,
      phone
    }).then(res => {
      if (res.data && res.data.token) {
        wx.login({
          timeout: 5000,
          success: (loginRes) =>  {
            if (loginRes.code) {
              this.bindingOpenid(loginRes.code, res.data.token)
            }
          }
        })
        // wx.login({
        //   timeout: 5000,
        //   success: (loginRes) =>  {
        //     if (loginRes.code) {
        //       this.bindingOpenid(loginRes.code, res.data.token)
        //     }
        //   }
        // })
        if(res.data.phone){
          res.data.users.phone = res.data.phone || res.data.users.phone
        }
@@ -88,17 +119,12 @@
      }else{
        wx.showToast({
          title: '你还不是该系统用户,请联系相关管理员注册',
          icon: 'none'
        })
      }
    })
  },
  changeStatus() {
    if (!this.data.agreementFalg) {
      return wx.showToast({
        title: '请先阅读并同意相关协议',
        icon: 'none'
      })
    }
    this.setData({
      status: '1'
    })
@@ -111,9 +137,48 @@
  onLoad(options) {
    var app = getApp().globalData
    this.setData({
      primary: app.primary
      primary: app.primary,
      bottomLift: app.bottomLift
    })
    this.autoLogin()
    this.initData()
  },
  autoLogin(){
    var that =this
    wx.login({
      timeout: 5000,
      success(res) {
        if (res.code) {
          //发起网络请求
          wxLoginCustomer({
            code: res.code
          }).then(res => {
            console.log(res)
            wx.setStorageSync('sessionKey', res.data.sessionKey)
            that.setData({openid:res.data.openid})
            if (res && res.data !=null && res.data.token!=null) {
              console.log(res)
              wx.hideLoading()
              wx.setStorageSync('member', res.data.users || '')
              wx.setStorageSync('token', res.data.token || '')
              wx.switchTab({
                url: '/pages/index/index',
              })
            }
          })
        } else {
          wx.reLaunch({
            url: '/pages/login/index',
          })
          wx.hideLoading()
          console.log('登录失败!' + res)
        }
      },
      fail(err) {
        wx.hideLoading()
        console.log(err)
      }
    })
  },
  getPhoneNumber(e) {
    const data = {
@@ -122,17 +187,10 @@
    getWxMiniPhone({
      encryptedData: data.encryptedData,
      iv: data.iv,
      openid:this.data.openid,
      sessionKey: wx.getStorageSync('sessionKey'),
    }).then(res => {
      if (res.data && res.data.token) {
        wx.login({
          timeout: 5000,
          success: (loginRes) =>  {
            if (loginRes.code) {
              this.bindingOpenid(loginRes.code, res.data.token)
            }
          }
        })
      if (res.data && res.data.token) {
        if(res.data.phone){
          res.data.users.phone = res.data.phone || res.data.users.phone
        }
@@ -144,6 +202,7 @@
      }else{
        wx.showToast({
          title: '你还不是该系统用户,请联系相关管理员注册',
          icon: 'none'
        })
      }
@@ -204,13 +263,6 @@
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },