移除前端中的会员卡和支付相关,新增微信一键登录

This commit is contained in:
2026-07-14 18:50:35 +08:00
parent 13b99428de
commit 6cc72ae0f7
26 changed files with 331 additions and 9159 deletions
+239 -3
View File
@@ -1,10 +1,61 @@
<template>
<template>
<view class="login-page">
<!-- 自定义Toast弹窗 -->
<view class="custom-toast" :class="{ show: toastShow }">
<text class="toast-text">{{ toastMessage }}</text>
</view>
<!-- ==================== 微信小程序登录 ==================== -->
<template v-if="isWechatMiniProgram">
<view class="login-header" :style="{ paddingTop: statusBarHeightPx }">
<view class="logo-wrapper">
<image class="logo-image" src="/static/logo.png" mode="aspectFit" />
<text class="app-name">活氧舱欢迎您</text>
<text class="app-slogan">享受运动拥抱健康</text>
</view>
</view>
<view class="wechat-card">
<view class="card-body wechat-login-body">
<text class="phone-display">微信一键登录</text>
<text class="auth-tip">授权获取您的微信信息</text>
<!-- 获取微信头像昵称 -->
<button
v-if="canUseGetUserProfile"
class="login-btn wechat-btn"
hover-class="wechat-btn-hover"
@tap="handleGetUserProfile"
:disabled="isLoading"
>
<text>{{ isLoading ? '登录中...' : '微信一键登录' }}</text>
</button>
<!-- 低版本兼容 -->
<button
v-else
class="login-btn wechat-btn"
hover-class="wechat-btn-hover"
open-type="getUserInfo"
@getuserinfo="handleGetUserInfo"
:disabled="isLoading"
>
<text>{{ isLoading ? '登录中...' : '微信一键登录' }}</text>
</button>
<view class="agreement-text" :class="{ shake: shakeAgreement }">
<checkbox-group @change="onAgreementChange">
<checkbox :checked="agreed" value="agreed" color="#07C160" />
</checkbox-group>
<text>登录即表示同意</text>
<text class="link" @tap="showAgreement">用户协议</text>
<text></text>
<text class="link" @tap="showPrivacy">隐私政策</text>
</view>
</view>
</view>
</template>
<!-- ==================== App/其他平台登录原有 ==================== -->
<template v-else>
<view class="login-header">
<view class="logo-wrapper">
<image class="logo-image" src="/static/logo.png" mode="aspectFit" />
@@ -98,15 +149,36 @@
</view>
</view>
</view>
</template>
</view>
</template>
<script setup>
import { ref, onUnmounted } from 'vue'
import { ref, onMounted, onUnmounted } from 'vue'
import { setToken, setRefreshToken } from '@/utils/request.js'
import { loginWithPhone, oneClickLogin, sendCode } from '@/api/main.js'
import { loginWithPhone, oneClickLogin, sendCode, login } from '@/api/main.js'
import VerifyCodeInput from '@/components/global/VerifyCodeInput.vue'
// ===== 平台检测 =====
const isWechatMiniProgram = ref(false)
const statusBarHeightPx = ref('0px')
onMounted(() => {
// 获取状态栏高度,为刘海屏留出安全空间
const sysInfo = uni.getSystemInfoSync()
statusBarHeightPx.value = (sysInfo.statusBarHeight || 0) + 'px'
// 检测当前是否为微信小程序环境
// #ifdef MP-WEIXIN
isWechatMiniProgram.value = true
// #endif
if (!isWechatMiniProgram.value) {
// 非微信小程序,保持原有默认卡片
activeCard.value = 'phone'
}
})
const activeCard = ref('phone')
const isLoading = ref(false)
const agreed = ref(true)
@@ -440,6 +512,121 @@ async function handleSmsLogin() {
}
}
// ===== 微信小程序登录 =====
const canUseGetUserProfile = ref(false)
// 检查是否支持 getUserProfile(基础库 2.10.4+
onMounted(() => {
// #ifdef MP-WEIXIN
if (wx.getUserProfile) {
canUseGetUserProfile.value = true
}
// #endif
})
/**
* 微信小程序登录(新版:getUserProfile
*/
function handleGetUserProfile() {
if (!agreed.value) {
triggerAgreementShake()
return
}
isLoading.value = true
// #ifdef MP-WEIXIN
wx.getUserProfile({
desc: '用于完善会员资料',
success: (profileRes) => {
const userInfo = profileRes.userInfo
console.log('[微信登录] 获取用户信息成功:', userInfo)
// 执行微信登录
performWechatLogin(userInfo)
},
fail: (err) => {
console.error('[微信登录] 获取用户信息失败:', err)
isLoading.value = false
// 用户拒绝授权时,仍然尝试静默登录
performWechatLogin(null)
}
})
// #endif
}
/**
* 微信小程序登录(旧版:getUserInfo
*/
function handleGetUserInfo(e) {
if (!agreed.value) {
triggerAgreementShake()
return
}
isLoading.value = true
const userInfo = e.detail.userInfo
if (userInfo) {
console.log('[微信登录] 获取用户信息成功:', userInfo)
}
performWechatLogin(userInfo)
}
/**
* 执行微信登录:调用 uni.login 获取 code,发送到后端
*/
function performWechatLogin(userInfo) {
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin',
success: async (loginRes) => {
const code = loginRes.code
console.log('[微信登录] 获取 code 成功:', code)
if (!code) {
showToast('微信登录失败,请重试')
isLoading.value = false
return
}
try {
const res = await login({
code: code,
nickname: userInfo?.nickName || '',
avatar: userInfo?.avatarUrl || ''
})
console.log('[微信登录] 后端返回:', res)
if (res && res.accessToken) {
setToken(res.accessToken)
if (res.refreshToken) {
setRefreshToken(res.refreshToken)
}
saveLoginInfo(res)
showToast('登录成功')
setTimeout(() => {
uni.switchTab({ url: '/pages/memberInfo/memberInfo' })
}, 1500)
} else {
showToast('登录失败,请重试')
}
} catch (e) {
console.error('[微信登录] 后端调用失败:', e)
showToast(e?.message || '登录失败,请重试')
} finally {
isLoading.value = false
}
},
fail: (err) => {
console.error('[微信登录] uni.login 失败:', err)
showToast('微信登录失败,请重试')
isLoading.value = false
}
})
// #endif
}
onUnmounted(() => {
if (timer) clearInterval(timer)
})
@@ -481,6 +668,8 @@ button::after {
display: flex;
flex-direction: column;
padding: 48rpx;
box-sizing: border-box;
overflow: hidden;
}
.login-header {
@@ -523,6 +712,53 @@ button::after {
height: 500rpx;
}
/* ===== 微信小程序登录卡片 ===== */
.wechat-card {
width: 100%;
box-sizing: border-box;
background: $bg-white;
border-radius: $radius-lg;
box-shadow: 0 24rpx 60rpx rgba(0, 0, 0, 0.18), 0 8rpx 20rpx rgba(0, 0, 0, 0.1);
padding: 48rpx 40rpx;
}
.wechat-login-body {
min-height: 400rpx;
justify-content: flex-start;
gap: 24rpx;
}
.wechat-btn {
width: 100%;
height: 100rpx;
border-radius: $radius-md;
border: none;
background: #07C160;
color: #ffffff;
font-size: 34rpx;
font-weight: $font-weight-bold;
box-shadow: 0 8rpx 24rpx rgba(7, 193, 96, 0.3);
margin-top: 24rpx;
display: flex;
justify-content: center;
align-items: center;
&:active {
transform: scale(0.98);
opacity: 0.9;
}
&[disabled] {
background: #A0E0B0;
box-shadow: none;
}
}
.wechat-btn-hover {
opacity: 0.85;
transform: scale(0.98);
}
.login-card {
position: absolute;
height: 620rpx;