feat(auth): 移除多角色体验账号直登,仅保留微信手机号授权登录
- 登录页删除体验账号卡片、切换按钮与全部 demo 登录/失败回退逻辑,微信授权失败只提示重试 - completeLogin 只接受服务端签发的 token,禁止无 token 的假登录 - 删除 /api/auth/demo-accounts、/api/auth/demo-login、loadDemoAccounts 与客户端 API - 停止种子 demo_accounts 配置并清理历史配置行;117 套件/763 用例全绿;线上接口已 404
这个提交包含在:
@@ -1572,22 +1572,3 @@ export async function loginWithWechatPhone({ phoneCode, wxCode } = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 体验账号列表(后台配置,DB 驱动;小程序端不再写死)
|
||||
*/
|
||||
export async function getDemoAccounts() {
|
||||
try {
|
||||
const res = await http.get('/auth/demo-accounts');
|
||||
return Array.isArray(res) ? res : [];
|
||||
} catch (err) {
|
||||
console.warn('[API] 获取体验账号异常:', err.message);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 体验登录:服务端校验账号在配置清单内后签发真实会话 token
|
||||
*/
|
||||
export async function demoLogin(userId) {
|
||||
return http.post('/auth/demo-login', { userId: Number(userId) });
|
||||
}
|
||||
|
||||
@@ -22,33 +22,6 @@
|
||||
<text class="auth-guarantee-tip">微信官方安全风控 · 个人信息严格加密存储</text>
|
||||
</view>
|
||||
|
||||
<!-- 多角色体验账号矩阵 (局长/买家/金牌大神) -->
|
||||
<view class="demo-accounts-card" v-if="demoAccounts.length > 0">
|
||||
<view class="demo-card-head">
|
||||
<text class="demo-title">多角色体验账号直登</text>
|
||||
<text class="demo-sub">评审与体验专用 · 一键切换角色</text>
|
||||
</view>
|
||||
|
||||
<view class="demo-list">
|
||||
<view
|
||||
v-for="acc in demoAccounts"
|
||||
:key="acc.userId"
|
||||
class="demo-item btn-active"
|
||||
@click="loginWithDemo(acc)"
|
||||
>
|
||||
<image class="demo-avatar" :src="acc.avatar || DEFAULT_AVATAR" mode="aspectFill" />
|
||||
<view class="demo-info">
|
||||
<view class="demo-name-row">
|
||||
<text class="demo-name">{{ acc.nickname }}</text>
|
||||
<text class="demo-badge" :class="acc.roleTag">{{ acc.roleDesc }}</text>
|
||||
</view>
|
||||
<text class="demo-feature">{{ acc.desc }}</text>
|
||||
</view>
|
||||
<button class="btn-switch-account btn-active">一键体验</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 底部合规声明与服务协议勾选 (单行紧凑排列) -->
|
||||
<view class="protocol-section" @click="agreedProtocol = !agreedProtocol">
|
||||
<view class="checkbox" :class="{ checked: agreedProtocol }">
|
||||
@@ -69,7 +42,7 @@ 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, getDemoAccounts, demoLogin } from '@/common/api.js';
|
||||
import { getPlatformConfigs, loginWithWechatPhone } from '@/common/api.js';
|
||||
|
||||
const APP_LOGO = 'https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=200';
|
||||
const DEFAULT_AVATAR = 'https://images.unsplash.com/photo-1535713875002-d1d0cf377fde?w=200';
|
||||
@@ -107,19 +80,6 @@ const loadProtocolConfig = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const demoAccounts = ref([]);
|
||||
const loadingDemoAccounts = ref(false);
|
||||
|
||||
const loadDemoAccounts = async () => {
|
||||
if (loadingDemoAccounts.value) return;
|
||||
loadingDemoAccounts.value = true;
|
||||
try {
|
||||
demoAccounts.value = await getDemoAccounts();
|
||||
} finally {
|
||||
loadingDemoAccounts.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onLoad((options) => {
|
||||
if (options && options.redirect) {
|
||||
try {
|
||||
@@ -134,7 +94,6 @@ onMounted(() => {
|
||||
currentThemeKey.value = getCurrentThemeKey();
|
||||
applyThemeToNativeUI(currentThemeKey.value);
|
||||
loadProtocolConfig();
|
||||
loadDemoAccounts();
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
@@ -157,15 +116,14 @@ const completeLogin = (userId, customData = {}, sessionToken = '') => {
|
||||
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
// 仅接受服务端签发的 token,避免出现"旧 token 属主 + 新 userId"的身份错配
|
||||
if (!sessionToken) {
|
||||
uni.showToast({ title: '登录凭证缺失,请重试', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
uni.removeStorageSync('user_has_logged_out');
|
||||
uni.setStorageSync('userId', userId);
|
||||
// userId 与 token 必须保持一致:无 token 的体验登录要清掉旧 token,
|
||||
// 否则会出现"旧 token 属主 + 新 userId"→ 服务端判定以他人身份操作(403)
|
||||
if (sessionToken) {
|
||||
uni.setStorageSync('userToken', sessionToken);
|
||||
} else {
|
||||
uni.removeStorageSync('userToken');
|
||||
}
|
||||
uni.setStorageSync('userToken', sessionToken);
|
||||
uni.setStorageSync('userInfo', {
|
||||
id: userId,
|
||||
nickname: customData.nickname || '微信用户',
|
||||
@@ -220,82 +178,75 @@ const handleGetPhoneNumber = async (e) => {
|
||||
}
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
if (e && e.detail && (e.detail.code || e.detail.encryptedData)) {
|
||||
if (e.detail.code) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
} 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 || '微信手机号解析未成功'},是否使用评审体验账号快捷登录?`,
|
||||
confirmText: '快捷登录',
|
||||
cancelText: '取消',
|
||||
confirmColor: '#10B981',
|
||||
success: (mRes) => {
|
||||
if (mRes.confirm) {
|
||||
loginFirstDemoAccount();
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
loginFirstDemoAccount();
|
||||
} else {
|
||||
if (!e || !e.detail || !(e.detail.code || e.detail.encryptedData)) {
|
||||
console.warn('[WeChat Login] 未授权手机号或环境受限:', e?.detail?.errMsg);
|
||||
uni.showModal({
|
||||
title: '登录提示',
|
||||
content: '未获得微信手机号授权(需非个人主体认证小程序支持)。是否使用体验账号直接登录?',
|
||||
confirmText: '快捷登录',
|
||||
cancelText: '取消',
|
||||
confirmColor: '#10B981',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
loginFirstDemoAccount();
|
||||
}
|
||||
}
|
||||
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
|
||||
loginFirstDemoAccount();
|
||||
uni.showToast({ title: '请在微信小程序内使用手机号快捷登录', icon: 'none' });
|
||||
// #endif
|
||||
};
|
||||
|
||||
@@ -305,36 +256,10 @@ const handleFallbackLogin = () => {
|
||||
uni.showToast({ title: '请先阅读并勾选服务协议', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
loginFirstDemoAccount();
|
||||
uni.showToast({ title: '请在微信小程序内使用手机号快捷登录', icon: 'none' });
|
||||
// #endif
|
||||
};
|
||||
|
||||
const loginWithDemo = async (acc) => {
|
||||
if (!agreedProtocol.value) {
|
||||
uni.showToast({ title: '请先阅读并勾选服务协议', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
uni.showLoading({ title: '正在登录...' });
|
||||
try {
|
||||
const res = await demoLogin(acc.userId);
|
||||
uni.hideLoading();
|
||||
completeLogin(res.userId, res.user || {}, res.userToken || '');
|
||||
} catch (e) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: (e && e.message) || '体验登录失败', icon: 'none' });
|
||||
}
|
||||
};
|
||||
|
||||
const loginFirstDemoAccount = async () => {
|
||||
if (!demoAccounts.value.length) await loadDemoAccounts();
|
||||
const first = demoAccounts.value[0];
|
||||
if (!first) {
|
||||
uni.showToast({ title: '体验账号未配置,请联系管理员', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
await loginWithDemo(first);
|
||||
};
|
||||
|
||||
const openUserAgreement = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/common/protocol?type=service',
|
||||
@@ -457,115 +382,6 @@ const openPrivacyAgreement = () => {
|
||||
}
|
||||
}
|
||||
|
||||
/* 体验账号卡片 */
|
||||
.demo-accounts-card {
|
||||
background: #151D30;
|
||||
border-radius: 28rpx;
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
padding: 28rpx 28rpx 16rpx;
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
.demo-card-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.demo-title {
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
color: #F8FAFC;
|
||||
}
|
||||
.demo-sub {
|
||||
font-size: 20rpx;
|
||||
color: #64748B;
|
||||
}
|
||||
}
|
||||
|
||||
.demo-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16rpx;
|
||||
|
||||
.demo-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18rpx;
|
||||
padding: 16rpx 20rpx;
|
||||
border-radius: 20rpx;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border: 1px solid rgba(255, 255, 255, 0.06);
|
||||
|
||||
.demo-avatar {
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
border-radius: 36rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.demo-info {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
|
||||
.demo-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
margin-bottom: 4rpx;
|
||||
|
||||
.demo-name {
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
color: #F8FAFC;
|
||||
}
|
||||
|
||||
.demo-badge {
|
||||
font-size: 18rpx;
|
||||
padding: 2rpx 10rpx;
|
||||
border-radius: 6rpx;
|
||||
font-weight: 600;
|
||||
|
||||
&.host {
|
||||
background: rgba(245, 158, 11, 0.2);
|
||||
color: #F59E0B;
|
||||
}
|
||||
&.buyer {
|
||||
background: rgba(99, 102, 241, 0.2);
|
||||
color: #818CF8;
|
||||
}
|
||||
&.expert {
|
||||
background: rgba(16, 185, 129, 0.2);
|
||||
color: #10B981;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.demo-feature {
|
||||
font-size: 20rpx;
|
||||
color: #94A3B8;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.btn-switch-account {
|
||||
font-size: 22rpx;
|
||||
color: #6366F1;
|
||||
font-weight: 600;
|
||||
padding: 8rpx 18rpx;
|
||||
border-radius: 12rpx;
|
||||
background: rgba(99, 102, 241, 0.15);
|
||||
border: none;
|
||||
margin: 0;
|
||||
line-height: 1.4;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 协议勾选 (一行紧凑完整展示) */
|
||||
.protocol-section {
|
||||
display: flex;
|
||||
@@ -636,39 +452,6 @@ const openPrivacyAgreement = () => {
|
||||
}
|
||||
}
|
||||
|
||||
.demo-accounts-card {
|
||||
background: #FFFFFF;
|
||||
border-color: #E7E5E4;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.06);
|
||||
|
||||
.demo-card-head {
|
||||
.demo-title {
|
||||
color: #1C1917;
|
||||
}
|
||||
.demo-sub {
|
||||
color: #A8A29E;
|
||||
}
|
||||
}
|
||||
|
||||
.demo-list .demo-item {
|
||||
background: #FDFBF7;
|
||||
border-color: #E7E5E4;
|
||||
|
||||
.demo-info .demo-name-row .demo-name {
|
||||
color: #1C1917;
|
||||
}
|
||||
|
||||
.demo-info .demo-feature {
|
||||
color: #78716C;
|
||||
}
|
||||
|
||||
.btn-switch-account {
|
||||
background: #FFF7ED;
|
||||
color: #EA580C;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.protocol-section {
|
||||
.checkbox {
|
||||
border-color: #D6D3D1;
|
||||
|
||||
在新工单中引用
屏蔽一个用户