liukangdong
2024-07-18 5b219a9694c8d69db42e746a654c779cc6a61bf6
wechat_staff/pages/login/index.js
@@ -1,4 +1,4 @@
// pages/auth/auth.js
import { sendSms,loginByPhone, getDictData } from '../../api/index'
Page({
  /**
@@ -9,12 +9,29 @@
    primary: '',
    status: '0', // 标识
    countDown: 0,
    phone: '',
    password: '',
    phone: '13663966099',
    code: '',
    showModal: false,
    activeHtml: '',
  },
  getCode() {
    let countDown = this.data.countDown
    if(countDown > 0) return
    const { phone } = this.data
    if(!phone || phone.length != 11){
      return wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      })
    }
    sendSms({
      phone
    }).then(res => {
      wx.showToast({
        title: '验证码发送成功',
        icon: 'none'
      })
    this.setData({ countDown: 60 })
    let timer = setInterval(() => {
      let countDown = this.data.countDown
@@ -24,6 +41,33 @@
      countDown --
      this.setData({ countDown })
    }, 1000)
    })
  },
  loginPhone() {
    const { code, phone } = this.data
    loginByPhone({code, phone}).then(res => {
      wx.setStorageSync('member', res.data.users)
      wx.setStorageSync('token', res.data.token)
      wx.showToast({
        title: '登录成功',
      })
      setTimeout(() => {
        wx.switchTab({
          url: '/pages/index/index',
        })
      }, 300)
    })
  },
  changeStatus() {
    if(!this.data.agreementFalg){
      return wx.showToast({
        title: '请先阅读并同意相关协议',
        icon: 'none'
      })
    }
    this.setData({
      status: '1'
    })
  },
  agreementChange(e) {
    this.setData({
@@ -35,6 +79,37 @@
    this.setData({
      primary: app.primary
    })
    this.initData()
  },
  onOpen(e){
    const { serviceHtml, privacyHtml } = this.data
    const { index } = e.target.dataset
    let activeHtml = index == '0' ? serviceHtml : privacyHtml
    this.setData({
      activeHtml,
      showModal: true
    })
  },
  onClose() {
    this.setData({showModal: false})
  },
  initData(){
    getDictData({
      code: 'ZBOM_CUSTOMIZED',
      label: 'SERVER_AGREEMENT'
    }).then(res => {
      this.setData({
        serviceHtml: res.data.code
      })
    })
    getDictData({
      code: 'ZBOM_CUSTOMIZED',
      label: 'PRIVACY_AGREEMENT'
    }).then(res => {
      this.setData({
        privacyHtml: res.data.code
      })
    })
  },
  /**