ll
liukangdong
2024-12-09 9ce28811e94fa042adb7cabe6581b0393c6d576d
h5/pages/login.vue
@@ -25,51 +25,85 @@
</template>
<script>
import { loginPost, getUserInfo, sendSMsPost } from '@/api'
import { mapState, mapMutations } from 'vuex'
   import {
      loginPost,
      getUserInfo,
      sendSMsPost,
      ywWxAuthorize
   } from '@/api'
   import {
      mapState,
      mapMutations
   } from 'vuex'
export default {
  name: 'login',
  data() {
    return {
      form: {
            phone: '18888888888',
            code: '1'
               phone: '',
               code: ''
      },
         downTime: 0
            downTime: 0,
            // code: '011dfEkl2PzcFe4ZxSnl22NKXz4dfEkQ'
            code: ''
    }
  },
  onLoad() {
  },
  onBackPress(options) {
    uni.redirectTo({
      url: '/pages/login/login'
      onShow() {
         // return
         var that = this
         let url = window.location.href
         if (url.indexOf('code=') !== -1 || this.code) {
            let code = ''
            const query = url.split('?')
            for (const q of query) {
               if (q.indexOf('code=') !== -1) {
                  let statusIndex = q.indexOf('&state')
                  code = q.substring(q.indexOf('code=') + 5, statusIndex)
               }
            }
            ywWxAuthorize({
               code: code || this.code
            }).then(res => {
               if (res.code === 200) {
                  that.$store.commit('setOpenId', res.data.openid)
                  if (res.data.token && res.data.token != '') {
                     that.$store.commit('setToken', res.data.token)
                     getUserInfo().then(ress => {
                        that.$store.commit('setUserInfo', ress.data)
    })
    return true
                     setTimeout(() => {
                        uni.redirectTo({
                           url: "/pages/index"
                        })
                     }, 300)
                  }
               }
            })
         } else {
            let url = 'https://zhcg.fnwtzx.com/yunwei_h5'
            const appID = 'wx95ac1efb67f0330d'
            let uri = encodeURIComponent(url)
            let authURL =
               `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appID}&redirect_uri=${uri}&response_type=code&scope=snsapi_base#wechat_redirect`
            window.location.href = authURL
         }
  },
      // onBackPress(options) {
      //    uni.redirectTo({
      //       url: '/pages/login/login'
      //    })
      //    return true
      // },
  methods: {
    ...mapMutations(["setToken", "setUserInfo"]),
      sendSms() {
         this.downTime = 60
         let timer = setInterval(() => {
            if(this.downTime == 0) return clearInterval(timer)
            this.downTime = this.downTime - 1
         }, 1000)
         const { form } = this
         sendSMsPost({
            phone: form.phone,
            type: 0
         }).then(res => {
            this.showToast('短信发送成功')
         })
      },
    onLogin() {
      const { form, ProtocolFlag } = this
      // if (!ProtocolFlag) return uni.showToast({
      //   title: '请先阅读并同意用户协议',
      //   icon: 'none'
      // })
            const {
               form,
               ProtocolFlag
            } = this
      if (!form.phone) return uni.showToast({
        title: '手机号不能为空',
        icon: 'none'
@@ -78,9 +112,10 @@
        title: '验证码不能为空',
        icon: 'none'
      })
      loginPost({
        ...form,
        openId: this.$store.state.openId
               openid: this.$store.state.openId
      }).then(res => {
        if (res.code === 200) {
          this.setToken(res.data)
@@ -93,7 +128,26 @@
          })
        }
      })
    }
         },
         sendSms() {
            this.downTime = 60
            let timer = setInterval(() => {
               if (this.downTime == 0) return clearInterval(timer)
               this.downTime = this.downTime - 1
            }, 1000)
            const {
               form
            } = this
            sendSMsPost({
               phone: form.phone,
               type: 0
            }).then(res => {
               this.showToast('短信发送成功')
            })
         },
  }
}
</script>
@@ -108,6 +162,7 @@
  align-items: center;
  flex-direction: column;
  background: linear-gradient( 180deg, #C5DDFF 0%, #FFFFFF 100%);
  .login_title {
    font-weight: 500;
    font-size: 52rpx;
@@ -116,14 +171,17 @@
      width: 100%;
      padding-left: 60rpx;
  }
   .login_title2{
      margin-top: 10rpx;
      margin-bottom: 80rpx;
   }
  .login_list {
    width: 100%;
    padding: 0 60rpx;
    box-sizing: border-box;
    .login_list_item {
      width: 100%;
      border-radius: 50rpx;
@@ -135,22 +193,27 @@
      display: flex;
      align-items: center;
      justify-content: space-between;
      &:last-child {
        margin-bottom: 0 !important;
      }
      image {
        flex-shrink: 0;
        width: 40rpx;
        height: 40rpx;
      }
      .btn{
         width: 145rpx;
         color:  $primaryColor;
            text-align: center;
      }
         .gray{
            color: #999999;
         }
      input {
        flex: 1;
        height: 100%;
@@ -160,17 +223,20 @@
      }
    }
  }
  .login_btn {
    width: 100%;
    padding: 0 60rpx;
    box-sizing: border-box;
    margin-top: 60rpx;
    .for_psd {
      color: $uni-color-primary;
      width: 140rpx;
      text-align: center;
      margin: 40rpx auto;
    }
    .login_btn_n {
      width: 100%;
      height: 98rpx;
@@ -185,6 +251,7 @@
         font-size: 32rpx;
    }
  }
  .deal_wrap {
    position: absolute;
    width: 100%;
@@ -194,15 +261,18 @@
    display: flex;
    justify-content: center;
    align-items: center;
    .deal {
      color: $uni-color-primary;
    }
    .checked {
      width: 48rpx;
      margin-right: 12rpx;
    }
  }
}
.modal {
  width: 690rpx;
  min-height: 920rpx;