- 后台 header/登录页改用本地 256x256 天鹅图标,标题统一为「同城陪玩管理后台」 - 后台 favicon 换成本地图标,去掉外部 unpkg 依赖 - 小程序登录页改用本地 /static/logo-icon.jpg(11KB),移除 unsplash 占位图与远程兜底
571 行
15 KiB
Vue
571 行
15 KiB
Vue
<template>
|
||
<view class="auth-login-page" :class="{ 'theme-warm': currentThemeKey === 'warm' }">
|
||
<!-- 顶部品牌视觉与应用 Slogan -->
|
||
<view class="brand-header">
|
||
<view class="brand-logo-wrap">
|
||
<image class="brand-logo-img" :src="APP_LOGO" mode="aspectFill" />
|
||
</view>
|
||
<text class="brand-app-name">同城陪玩生活圈</text>
|
||
<text class="brand-slogan">年轻人的同城搭子与温暖陪伴社交平台</text>
|
||
</view>
|
||
<!-- 微信手机号授权快捷登录主操作区 (微信官方推荐格式) -->
|
||
<view class="main-action-section">
|
||
<button
|
||
class="btn-wechat-primary btn-active"
|
||
open-type="getPhoneNumber"
|
||
@getphonenumber="handleGetPhoneNumber"
|
||
@click="handleFallbackLogin"
|
||
>
|
||
<image class="wechat-icon-svg" :src="ICONS.shield" mode="aspectFit" />
|
||
<text class="btn-text">一键授权快捷登录</text>
|
||
</button>
|
||
<text class="auth-guarantee-tip">微信官方安全风控 · 个人信息严格加密存储</text>
|
||
</view>
|
||
|
||
<!-- 底部合规声明与服务协议勾选 (单行紧凑排列) -->
|
||
<view class="protocol-section" @click="agreedProtocol = !agreedProtocol">
|
||
<view class="checkbox" :class="{ checked: agreedProtocol }">
|
||
<view class="checkbox-inner" v-if="agreedProtocol"></view>
|
||
</view>
|
||
<view class="protocol-text">
|
||
<text>登录注册即同意</text>
|
||
<text class="protocol-link" @click.stop="openUserAgreement">《用户服务协议》</text>
|
||
<text>与</text>
|
||
<text class="protocol-link" @click.stop="openPrivacyAgreement">《隐私保护指引》</text>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, onMounted } from 'vue';
|
||
import { onLoad, onShow } from '@dcloudio/uni-app';
|
||
import { ICONS } from '@/common/icons.js';
|
||
import { getCurrentThemeKey, applyThemeToNativeUI } from '@/common/theme.js';
|
||
import { getPlatformConfigs, loginWithWechatPhone } from '@/common/api.js';
|
||
import { useShare } from '@/common/share.js';
|
||
|
||
useShare({
|
||
title: '同城陪伴 · 账号登录与注册',
|
||
timelineTitle: '同城陪伴 · 专业游戏陪玩与生活陪伴',
|
||
path: '/pages/index/index'
|
||
});
|
||
|
||
const APP_LOGO = '/static/logo-icon.jpg';
|
||
const DEFAULT_AVATAR = 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=200';
|
||
|
||
const currentThemeKey = ref(getCurrentThemeKey());
|
||
const agreedProtocol = ref(true);
|
||
const redirectUrl = ref('');
|
||
|
||
// 动态协议与隐私政策配置 (支持管理后台灵活自定义配置与动态热更新)
|
||
const platformProtocol = ref({
|
||
userAgreementTitle: '用户服务协议',
|
||
userAgreementContent: '1. 账号使用规范:用户注册与使用同城生活陪伴服务须符合国家法律法规,严禁利用平台从事任何违法违规行为。\n2. 资金与交易保障:平台提供全额担保交易,订单完成前款项由官方账户托管,碰面出示4位核销码确认后自动结算至大神钱包。\n3. 履约安全守则:所有同城活动须在合规公开商业街区进行,严禁私下导流与脱离平台交易。\n4. 争议与售后仲裁:若遇服务不符或搭子违约,可随时在订单中发起申诉,由平台运营仲裁专员裁决。',
|
||
privacyPolicyTitle: '隐私保护指引',
|
||
privacyPolicyContent: '1. 信息收集范围:为保障同城陪玩交易安全与现场4位核销码核验,平台在获得您授权后会依法收集手机号与必要位置信息。\n2. 数据加密保护:平台全面接入微信小程序官方安全风控规范,所有用户数据均实施高强度加密脱敏存储。\n3. 权限撤回与管理:您可随时在小程序系统设置中撤回位置或通讯授权,平台未经您的明确许可绝不会向任何第三方泄露您的隐私数据。'
|
||
});
|
||
|
||
const loadProtocolConfig = async () => {
|
||
try {
|
||
const res = await getPlatformConfigs();
|
||
if (res && res.platform_protocol) {
|
||
const p = res.platform_protocol;
|
||
if (typeof p === 'object') {
|
||
if (p.userAgreementTitle) platformProtocol.value.userAgreementTitle = p.userAgreementTitle;
|
||
if (p.userAgreementContent || p.content) {
|
||
platformProtocol.value.userAgreementContent = p.userAgreementContent || p.content;
|
||
}
|
||
if (p.privacyPolicyTitle) platformProtocol.value.privacyPolicyTitle = p.privacyPolicyTitle;
|
||
if (p.privacyPolicyContent) {
|
||
platformProtocol.value.privacyPolicyContent = p.privacyPolicyContent;
|
||
}
|
||
}
|
||
}
|
||
} catch (err) {
|
||
console.warn('[Login] 动态拉取后台协议配置降级:', err);
|
||
}
|
||
};
|
||
|
||
onLoad((options) => {
|
||
if (options && options.redirect) {
|
||
try {
|
||
redirectUrl.value = decodeURIComponent(options.redirect);
|
||
} catch (_) {
|
||
redirectUrl.value = options.redirect;
|
||
}
|
||
}
|
||
});
|
||
|
||
onMounted(() => {
|
||
currentThemeKey.value = getCurrentThemeKey();
|
||
applyThemeToNativeUI(currentThemeKey.value);
|
||
loadProtocolConfig();
|
||
});
|
||
|
||
onShow(() => {
|
||
currentThemeKey.value = getCurrentThemeKey();
|
||
applyThemeToNativeUI(currentThemeKey.value);
|
||
loadProtocolConfig();
|
||
});
|
||
|
||
const completeLogin = (userId, customData = {}, sessionToken = '') => {
|
||
if (customData.status === '已封禁' || customData.status === '封禁') {
|
||
uni.showModal({
|
||
title: '账号已封禁',
|
||
content: '您的账号已被管理员封禁,无法登录系统',
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
return;
|
||
}
|
||
uni.showLoading({ title: '正在登录...' });
|
||
|
||
setTimeout(() => {
|
||
uni.hideLoading();
|
||
// 仅接受服务端签发的 token,避免出现"旧 token 属主 + 新 userId"的身份错配
|
||
if (!sessionToken) {
|
||
uni.showToast({ title: '登录凭证缺失,请重试', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.removeStorageSync('user_has_logged_out');
|
||
uni.setStorageSync('userId', userId);
|
||
uni.setStorageSync('userToken', sessionToken);
|
||
uni.setStorageSync('userInfo', {
|
||
id: userId,
|
||
nickname: customData.nickname || '微信用户',
|
||
avatar: customData.avatar || DEFAULT_AVATAR,
|
||
phone: customData.phone || '',
|
||
...customData
|
||
});
|
||
|
||
uni.$emit('login-success', { userId, user: customData });
|
||
uni.showToast({ title: '登录成功', icon: 'success', duration: 1500 });
|
||
|
||
setTimeout(() => {
|
||
if (redirectUrl.value) {
|
||
const rawTarget = redirectUrl.value;
|
||
const pureTarget = rawTarget.split('?')[0];
|
||
const isNativeTab = [
|
||
'/pages/index/index',
|
||
'/pages/activity/list',
|
||
'/pages/order/list',
|
||
'/pages/user/index',
|
||
'pages/index/index',
|
||
'pages/activity/list',
|
||
'pages/order/list',
|
||
'pages/user/index'
|
||
].includes(pureTarget);
|
||
|
||
if (isNativeTab) {
|
||
uni.switchTab({ url: pureTarget.startsWith('/') ? pureTarget : `/${pureTarget}` });
|
||
} else {
|
||
uni.redirectTo({
|
||
url: rawTarget,
|
||
fail: () => {
|
||
uni.reLaunch({ url: rawTarget });
|
||
}
|
||
});
|
||
}
|
||
} else {
|
||
uni.navigateBack({
|
||
fail: () => {
|
||
uni.switchTab({ url: '/pages/user/index' });
|
||
}
|
||
});
|
||
}
|
||
}, 400);
|
||
}, 350);
|
||
};
|
||
|
||
const handleGetPhoneNumber = async (e) => {
|
||
if (!agreedProtocol.value) {
|
||
uni.showToast({ title: '请先阅读并勾选服务协议', icon: 'none' });
|
||
return;
|
||
}
|
||
|
||
// #ifdef MP-WEIXIN
|
||
if (!e || !e.detail || !(e.detail.code || e.detail.encryptedData)) {
|
||
console.warn('[WeChat Login] 未授权手机号或环境受限:', e?.detail?.errMsg);
|
||
uni.showModal({
|
||
title: '登录提示',
|
||
content: '需要授权微信手机号才能登录。请点击“一键授权快捷登录”,并允许获取手机号后重试。',
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
return;
|
||
}
|
||
|
||
if (!e.detail.code) {
|
||
uni.showModal({
|
||
title: '登录提示',
|
||
content: '当前微信版本暂不支持手机号快捷登录,请升级微信后重试。',
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
return;
|
||
}
|
||
|
||
uni.showLoading({ title: '正在获取手机号...' });
|
||
try {
|
||
let wxCode = '';
|
||
try {
|
||
const loginRes = await new Promise((resolve, reject) => {
|
||
uni.login({
|
||
provider: 'weixin',
|
||
success: (res) => resolve(res),
|
||
fail: (err) => reject(err)
|
||
});
|
||
});
|
||
wxCode = loginRes.code || '';
|
||
} catch (_) {}
|
||
|
||
const res = await loginWithWechatPhone({
|
||
phoneCode: e.detail.code,
|
||
wxCode
|
||
});
|
||
|
||
uni.hideLoading();
|
||
if (res && (res.user || res.userId)) {
|
||
const userObj = res.user || { id: res.userId, phone: res.phone };
|
||
const sessionToken = res.userToken || res.token || '';
|
||
completeLogin(userObj.id, userObj, sessionToken);
|
||
}
|
||
} catch (err) {
|
||
uni.hideLoading();
|
||
console.warn('[WeChat Login] 微信手机号解析未成功:', err);
|
||
if (err.message && err.message.includes('封禁')) {
|
||
uni.showModal({
|
||
title: '账号已封禁',
|
||
content: err.message,
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
return;
|
||
}
|
||
uni.showModal({
|
||
title: '登录失败',
|
||
content: `${err.message || '微信手机号解析未成功'},请稍后重试。`,
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
}
|
||
// #endif
|
||
|
||
// #ifndef MP-WEIXIN
|
||
uni.showToast({ title: '请在微信小程序内使用手机号快捷登录', icon: 'none' });
|
||
// #endif
|
||
};
|
||
|
||
const handleFallbackLogin = () => {
|
||
// #ifndef MP-WEIXIN
|
||
if (!agreedProtocol.value) {
|
||
uni.showToast({ title: '请先阅读并勾选服务协议', icon: 'none' });
|
||
return;
|
||
}
|
||
uni.showToast({ title: '请在微信小程序内使用手机号快捷登录', icon: 'none' });
|
||
// #endif
|
||
};
|
||
|
||
const openUserAgreement = () => {
|
||
uni.navigateTo({
|
||
url: '/pages/common/protocol?type=service',
|
||
fail: () => {
|
||
uni.showModal({
|
||
title: platformProtocol.value.userAgreementTitle || '用户服务协议',
|
||
content: platformProtocol.value.userAgreementContent,
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
}
|
||
});
|
||
};
|
||
|
||
const openPrivacyAgreement = () => {
|
||
uni.navigateTo({
|
||
url: '/pages/common/protocol?type=privacy',
|
||
fail: () => {
|
||
uni.showModal({
|
||
title: platformProtocol.value.privacyPolicyTitle || '隐私保护指引',
|
||
content: platformProtocol.value.privacyPolicyContent,
|
||
showCancel: false,
|
||
confirmText: '我知道了'
|
||
});
|
||
}
|
||
});
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
.auth-login-page {
|
||
min-height: 100vh;
|
||
background-color: #0A0F1D;
|
||
box-sizing: border-box;
|
||
padding: 40rpx 36rpx calc(60rpx + env(safe-area-inset-bottom));
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
|
||
/* 顶部品牌区 */
|
||
.brand-header {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
margin-top: 60rpx;
|
||
margin-bottom: 64rpx;
|
||
|
||
.brand-logo-wrap {
|
||
width: 140rpx;
|
||
height: 140rpx;
|
||
border-radius: 40rpx;
|
||
background: linear-gradient(135deg, #6366F1, #8B5CF6);
|
||
padding: 6rpx;
|
||
box-shadow: 0 12rpx 32rpx rgba(99, 102, 241, 0.4);
|
||
margin-bottom: 24rpx;
|
||
|
||
.brand-logo-img {
|
||
width: 100%;
|
||
height: 100%;
|
||
border-radius: 36rpx;
|
||
}
|
||
}
|
||
|
||
.brand-app-name {
|
||
font-size: 38rpx;
|
||
font-weight: 800;
|
||
color: #F8FAFC;
|
||
letter-spacing: 2rpx;
|
||
margin-bottom: 8rpx;
|
||
}
|
||
|
||
.brand-slogan {
|
||
font-size: 24rpx;
|
||
color: #94A3B8;
|
||
text-align: center;
|
||
}
|
||
}
|
||
|
||
/* 主操作按钮区 */
|
||
.main-action-section {
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
margin-bottom: 40rpx;
|
||
|
||
.btn-wechat-primary {
|
||
width: 100%;
|
||
height: 92rpx;
|
||
border-radius: 46rpx;
|
||
background: #07C160;
|
||
color: #FFFFFF;
|
||
font-size: 30rpx;
|
||
font-weight: 700;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 16rpx;
|
||
box-shadow: 0 8rpx 24rpx rgba(7, 193, 96, 0.35);
|
||
border: none;
|
||
margin: 0;
|
||
|
||
&::after {
|
||
border: none;
|
||
}
|
||
|
||
.wechat-icon-svg {
|
||
width: 38rpx;
|
||
height: 38rpx;
|
||
}
|
||
|
||
.btn-text {
|
||
letter-spacing: 1rpx;
|
||
}
|
||
}
|
||
|
||
.auth-guarantee-tip {
|
||
font-size: 20rpx;
|
||
color: #64748B;
|
||
margin-top: 14rpx;
|
||
}
|
||
}
|
||
|
||
/* 协议勾选 (一行紧凑完整展示) */
|
||
.protocol-section {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 10rpx;
|
||
margin-top: auto;
|
||
padding: 20rpx 0;
|
||
width: 100%;
|
||
box-sizing: border-box;
|
||
flex-wrap: nowrap;
|
||
|
||
.checkbox {
|
||
width: 28rpx;
|
||
height: 28rpx;
|
||
border-radius: 6rpx;
|
||
border: 2rpx solid #64748B;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
|
||
&.checked {
|
||
background: #07C160;
|
||
border-color: #07C160;
|
||
|
||
.checkbox-inner {
|
||
width: 10rpx;
|
||
height: 10rpx;
|
||
background: #FFFFFF;
|
||
border-radius: 2rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
.protocol-text {
|
||
font-size: 20rpx;
|
||
color: #94A3B8;
|
||
line-height: 1.2;
|
||
white-space: nowrap;
|
||
display: flex;
|
||
align-items: center;
|
||
flex-shrink: 0;
|
||
|
||
.protocol-link {
|
||
color: #07C160;
|
||
font-weight: 600;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 浅色暖阳模式适配 */
|
||
.theme-warm {
|
||
background-color: #FAF8F5;
|
||
|
||
.brand-header {
|
||
.brand-app-name {
|
||
color: #1C1917;
|
||
}
|
||
.brand-slogan {
|
||
color: #78716C;
|
||
}
|
||
}
|
||
|
||
.main-action-section {
|
||
.auth-guarantee-tip {
|
||
color: #A8A29E;
|
||
}
|
||
}
|
||
|
||
.protocol-section {
|
||
.checkbox {
|
||
border-color: #D6D3D1;
|
||
}
|
||
|
||
.protocol-text {
|
||
color: #78716C;
|
||
|
||
.protocol-link {
|
||
color: #07C160;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
/* ===== Premium visual layer: 登录 ===== */
|
||
.auth-login-page {
|
||
background:
|
||
radial-gradient(80% 42% at 50% 4%, rgba(99, 102, 241, 0.18), transparent 62%),
|
||
radial-gradient(70% 36% at 80% 28%, rgba(217, 164, 65, 0.06), transparent 70%),
|
||
var(--surface-0);
|
||
animation: loginFadeIn 0.5s var(--ease-out) both;
|
||
|
||
.brand-logo-wrap {
|
||
position: relative;
|
||
padding: 6rpx;
|
||
border-radius: 40rpx;
|
||
background: linear-gradient(145deg, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.02));
|
||
box-shadow:
|
||
0 20rpx 48rpx rgba(99, 102, 241, 0.28),
|
||
0 0 0 1rpx rgba(255, 255, 255, 0.08);
|
||
}
|
||
|
||
.brand-app-name {
|
||
letter-spacing: 1rpx;
|
||
}
|
||
|
||
.brand-slogan {
|
||
color: #8B98B5;
|
||
letter-spacing: 0.4rpx;
|
||
}
|
||
|
||
.btn-wechat-primary {
|
||
height: 96rpx;
|
||
border-radius: 48rpx;
|
||
background: linear-gradient(135deg, #10B981 0%, #059669 55%, #047857 100%);
|
||
box-shadow:
|
||
0 18rpx 38rpx rgba(16, 185, 129, 0.28),
|
||
inset 0 1rpx 0 rgba(255, 255, 255, 0.28);
|
||
transition: transform var(--motion-fast, 120ms) var(--ease-out, ease-out);
|
||
}
|
||
|
||
.btn-wechat-primary:active {
|
||
transform: scale(0.98);
|
||
}
|
||
|
||
.auth-guarantee-tip {
|
||
color: #6B7894;
|
||
letter-spacing: 0.2rpx;
|
||
}
|
||
|
||
.protocol-section .checkbox {
|
||
border-color: #4B5874;
|
||
}
|
||
|
||
.protocol-section .protocol-text {
|
||
color: #7C89A6;
|
||
}
|
||
|
||
.protocol-section .protocol-link {
|
||
color: #34D399;
|
||
}
|
||
}
|
||
|
||
.auth-login-page.theme-warm {
|
||
background:
|
||
radial-gradient(80% 42% at 50% 4%, rgba(234, 88, 12, 0.08), transparent 62%),
|
||
#FDFBF7;
|
||
|
||
.brand-logo-wrap {
|
||
background: linear-gradient(145deg, #FFFFFF, #FFF3E6);
|
||
box-shadow:
|
||
0 20rpx 42rpx rgba(234, 88, 12, 0.14),
|
||
0 0 0 1rpx #F0ECE4;
|
||
}
|
||
|
||
.brand-slogan {
|
||
color: #A8A29E;
|
||
}
|
||
|
||
.auth-guarantee-tip {
|
||
color: #A8A29E;
|
||
}
|
||
|
||
.protocol-section .protocol-text {
|
||
color: #78716C;
|
||
}
|
||
}
|
||
|
||
@keyframes loginFadeIn {
|
||
from {
|
||
opacity: 0;
|
||
transform: translateY(12rpx);
|
||
}
|
||
to {
|
||
opacity: 1;
|
||
transform: translateY(0);
|
||
}
|
||
}
|
||
</style>
|