lin
2026-05-15 083fc3bf0f01788bc69b5072026a500ebc0dc086
pages/login/login.vue
@@ -1,18 +1,22 @@
<template>
   <view>
   <view style="background: url('/static/imgs/loginBg.png') center bottom / 100% no-repeat;height: calc(100vh - 44px);">
      <view class="login-title">
         <view class="login-title-1">手机号登录</view>
         <view class="login-title-2">未注册的手机号将自动注册</view>
         <image style="height: 140rpx;width: 140rpx;" src="@/static/imgs/loginLogo.png" mode="scaleToFill"></image>
         <view class="login-title-1">
            <text>购你所想</text>
            <text>购你所爱</text>
         </view>
         <view class="login-title-2">欢迎登录购有趣</view>
      </view>
      <view class="login-type">
         <view class="login-type-v">
            <view :class="formData.loginType == 1 ? 'active' : ''" @tap="loginTypeClick(1)">账号密码登录</view>
            <view :class="formData.loginType == 2 ? 'active' : ''" @tap="loginTypeClick(2)">短信登录</view>
            <view :class="formData.loginType == 1 ? 'active' : ''" @tap="loginTypeClick(1)">账号密码登录</view>
         </view>
      </view>
      <view class="login-list">
         <view class="login-item">
            <input type="tel" v-model="formData.phone" placeholder="请输入手机号" />
            <input type="tel" maxlength="11" v-model="formData.phone" placeholder="请输入手机号" />
         </view>
         <view class="login-item" v-if="formData.loginType == 1">
            <input type="password" v-model="formData.pass" placeholder="请输入密码" />
@@ -25,7 +29,7 @@
      </view>
      <view class="loginBtn">
         <view class="loginBtn-desc">
            <image @click="agreeClick" class="loginBtn-icon" :src="!loginAct ? '/static/imgs/check.png' : '/static/imgs/checked.png'" ></image>
            <image @click="agreeClick" class="loginBtn-icon" :src="!loginAct ? '/static/imgs/check.png' : '/static/imgs/checked.png'" mode=""></image>
            <text>我已阅读并同意</text>
            <text class="blue" @tap="agreeDialog1">《注册协议》</text>
            <text class="blue" @tap="agreeDialog2">《隐私政策》</text>
@@ -36,6 +40,7 @@
            <view class="fr" @tap="$util.goPages('/pages/findpass/findpass')">忘记密码</view>
         </view>
      </view>
      <!-- <image style="height: 576rpx;width: 100%;" src="@/static/imgs/loginBg.png" mode="scaleToFill"></image> -->
      <agreePup ref="agreePup1" :gp="1" title="注册协议"></agreePup>
      <agreePup ref="agreePup2" :gp="2" title="隐私政策"></agreePup>
   </view>
@@ -54,7 +59,7 @@
               phone: '',
               code: '',
               pass: '',
               loginType: 1,
               loginType: 2,
            },
            phoneReg: /^\d{11}$/,
            backUrl: '',
@@ -77,103 +82,62 @@
         agreeClick () {
            this.loginAct = !this.loginAct
         },
      async loginUser() {
        let t = this
        if (!t.loginAct) {
          return uni.showToast({
            title: '请阅读并同意协议政策',
            icon: 'error'
          })
        }
        if (t.formData.phone == '' || !t.phoneReg.test(t.formData.phone)) {
          return uni.showToast({
            title: '手机号错误!',
            icon: 'error'
          })
        }
        if (t.formData.pass == '' && t.formData.loginType == 1) {
          return uni.showToast({
            title: '请输入密码!',
            icon: 'error'
          })
        }
        if (t.formData.code == '' && t.formData.loginType == 2) {
          return uni.showToast({
            title: '请输入验证码!',
            icon: 'error'
          })
        }
        try {
          // 登录接口
          const res = await t.$util.post('User/Login', this.formData)
          if (res.code == 1) {
            uni.setStorageSync('lzsc-token', res.data.userToken)
            uni.setStorageSync('user-info', JSON.stringify(res.data))
            let isSwitch = 0
            let goUrl = ''
            // qxgLogin接口
            const ygxRes = await new Promise((resolve, reject) => {
              uni.request({
                url: t.$webHost + '/api/v2/auth/qxgIosUnionLogin?phone=' + t.$util.getUserInfo().phone,
                success: resolve,
                fail: reject
              })
            })
            console.log(ygxRes);
            if(!ygxRes.data.data.boughtEquity){
              goUrl = '/pages/quanyi/index'
              t.$util.goPages(goUrl)
              return
            }
            t.qxgLogin = ygxRes.data.data
            uni.setStorageSync('qxgLogin', t.qxgLogin)
            if (this.backUrl == '') {
              isSwitch = 1
              goUrl = '/pages/index/index'
            } else {
              goUrl = this.backUrl
            }
            uni.showToast({
              title: res.msg || '登录成功'
            })
            setTimeout(() => {
              if (isSwitch == 1) {
                t.$util.goSwitch(goUrl)
              } else {
                t.$util.goPages(goUrl)
              }
            }, 1500)
          } else {
            uni.showToast({
              title: res.msg || '登录失败',
              icon: 'error'
            })
          }
        } catch (err) {
          console.error(err)
          uni.showToast({
            title: '请求失败',
            icon: 'error'
          })
        }
      },
         loginUser () {
            let t = this
            if(!t.loginAct) {
               return uni.showToast({
                  title: '请阅读并同意协议政策',
                  icon: 'error'
               })
            }
            if(t.formData.phone == '' || !t.phoneReg.test(t.formData.phone)){
               return uni.showToast({
                  title: '手机号错误!',
                  icon: 'error',
               })
            }
            if(t.formData.pass == '' && t.formData.loginType == 1){
               return uni.showToast({
                  title: '请输入密码!',
                  icon: 'error',
               })
            }
            if(t.formData.code == '' && t.formData.loginType == 2){
               return uni.showToast({
                  title: '请输入验证码!',
                  icon: 'error',
               })
            }
            t.$util.post('User/Login', this.formData).then(res => {
               if(res.code == 1) {
                  uni.setStorageSync('pig-token', res.data.userToken)
                  uni.setStorageSync('user-info', JSON.stringify(res.data))
                  let isSwitch = 0
                  let goUrl = ''
                  if(this.backUrl == ''){
                     isSwitch = 1
                     goUrl = '/pages/index/index'
                  } else {
                     goUrl = this.backUrl
                  }
                  uni.showToast({
                     title: res.msg || '登录成功'
                  })
                  setTimeout(() => {
                     if(isSwitch == 1) {
                        t.$util.goSwitch(goUrl)
                     } else {
                        t.$util.goPages(goUrl)
                     }
                  }, 1500)
               } else {
                  uni.showToast({
                     title: res.msg || '登录失败',
                     icon: 'error'
                  })
               }
            })
         },
         sendCode () {
            let t = this
            if(this.formData.phone == '' || !this.phoneReg.test(t.formData.phone)){