wlzboy
5 天以前 7de1396e315896dbc72a9d54e44f77434ea90f18
app/pages/login.vue
@@ -45,7 +45,7 @@
          class="wechat-login-btn cu-btn block bg-green lg round"
          style="margin-top: 20rpx;">
          <text class="cuIcon-wechat" style="margin-right: 10rpx;"></text>
          微信一键登录
        手机号码快捷登录
        </button>
        <button 
          v-else-if="isWechat"
@@ -54,7 +54,7 @@
          class="wechat-login-btn cu-btn block bg-green lg round"
          style="margin-top: 20rpx;">
          <text class="cuIcon-wechat" style="margin-right: 10rpx;"></text>
          微信一键登录
          手机号码快捷登录
        </button>
        <!-- #endif -->
      </view>
@@ -85,7 +85,13 @@
        isWechat: false, // 是否为微信小程序环境
        wechatOpenId: '', // 微信OpenID
        wechatUnionId: '', // 微信UnionID
        // 页面参数
        pageOptions: {}
      }
    },
    onLoad(options) {
      // 保存页面参数
      this.pageOptions = options || {}
    },
    created() {
      this.getCode()
@@ -153,7 +159,15 @@
        this.$store.dispatch('GetInfo').then(res => {
          // 触发登录成功事件,启动消息轮询
          uni.$emit('user-login')
          this.$tab.reLaunch('/pages/index')
          // 检查是否有redirect参数指定跳转页面
          if (this.pageOptions.redirect) {
            // 解码redirect参数
            const redirectUrl = decodeURIComponent(this.pageOptions.redirect)
            this.$tab.reLaunch(redirectUrl)
          } else {
            // 默认跳转到首页
            this.$tab.reLaunch('/pages/index')
          }
        })
      },
      
@@ -181,8 +195,9 @@
        // 从本地存储中获取OpenID和UnionID
        const savedOpenId = uni.getStorageSync('wechat_openid')
        const savedUnionId = uni.getStorageSync('wechat_unionid')
        const autoLogin=true;
        
        if (savedOpenId) {
        if (savedOpenId && autoLogin) {
          console.log('检测到已保存的OpenID,尝试自动登录')
          this.wechatOpenId = savedOpenId
          this.wechatUnionId = savedUnionId // 可能为null
@@ -236,7 +251,15 @@
                  const { setToken } = require('@/utils/auth')
                  setToken(token)
                  
                  this.loginSuccess()
                  // 检查是否有redirect参数指定跳转页面
                  if (this.pageOptions.redirect) {
                    // 解码redirect参数
                    const redirectUrl = decodeURIComponent(this.pageOptions.redirect)
                    this.$tab.reLaunch(redirectUrl)
                  } else {
                    // 默认跳转到首页
                    this.$tab.reLaunch('/pages/index')
                  }
                } else {
                  this.$modal.msgError(response.msg || '登录失败')
                }
@@ -274,7 +297,15 @@
            const { setToken } = require('@/utils/auth')
            setToken(token)
            
            this.loginSuccess()
            // 检查是否有redirect参数指定跳转页面
            if (this.pageOptions.redirect) {
              // 解码redirect参数
              const redirectUrl = decodeURIComponent(this.pageOptions.redirect)
              this.$tab.reLaunch(redirectUrl)
            } else {
              // 默认跳转到首页
              this.$tab.reLaunch('/pages/index')
            }
          } else {
            // OpenID未绑定或验证失败,需要获取手机号绑定
            console.log('该OpenID尚未绑定或验证失败,需要获取手机号')