Compare commits

...

2 Commits

Author SHA1 Message Date
kk 3a154198e9 清除缓存
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 42s
2026-07-10 15:25:36 +08:00
kk c84c9df5d4 注册后跳回首页/增加用户信息缓存日志
Uni-app H5 Deploy (Prod + Staging) / deploy (release) Successful in 45s
2026-07-10 15:13:53 +08:00
4 changed files with 71 additions and 6 deletions
+13
View File
@@ -113,8 +113,11 @@ export default {
}); });
const data = res.data || {}; const data = res.data || {};
console.log('[loading] login response:', JSON.stringify(data, null, 2));
if (data.code === 0 && data.data) { if (data.code === 0 && data.data) {
const result = data.data; const result = data.data;
console.log('[loading] login result:', JSON.stringify(result, null, 2));
// 清除 URL 中的 code 参数,避免刷新重复处理 // 清除 URL 中的 code 参数,避免刷新重复处理
const url = new URL(window.location.href); const url = new URL(window.location.href);
@@ -126,11 +129,13 @@ export default {
// 已注册 → 缓存 JWT → 跳转首页 // 已注册 → 缓存 JWT → 跳转首页
uni.setStorageSync('token', result.token); uni.setStorageSync('token', result.token);
uni.setStorageSync('user_info', result.user_info); uni.setStorageSync('user_info', result.user_info);
console.log('[loading] stored user_info:', JSON.stringify(result.user_info, null, 2));
this.goToHome(); this.goToHome();
} else { } else {
// 未注册 → 缓存临时数据 → 跳转注册页 // 未注册 → 缓存临时数据 → 跳转注册页
uni.setStorageSync('temp_token', result.temp_token); uni.setStorageSync('temp_token', result.temp_token);
uni.setStorageSync('auth_info', result.auth_info); uni.setStorageSync('auth_info', result.auth_info);
console.log('[loading] stored auth_info:', JSON.stringify(result.auth_info, null, 2));
this.goToRegister(); this.goToRegister();
} }
} else { } else {
@@ -152,6 +157,14 @@ export default {
}, },
goToRegister() { goToRegister() {
// 记录扫码时的原始 URL,注册完成后跳回
const scanUrl = this.deviceId
? `/pages/index/index?device_id=${this.deviceId}`
: '';
if (scanUrl) {
uni.setStorageSync('__scan_redirect_url', scanUrl);
}
const url = this.deviceId const url = this.deviceId
? `/pages/register/register?device_id=${this.deviceId}` ? `/pages/register/register?device_id=${this.deviceId}`
: '/pages/register/register'; : '/pages/register/register';
+46 -1
View File
@@ -103,7 +103,7 @@
<!-- 蓝色个人信息区域 --> <!-- 蓝色个人信息区域 -->
<view class="user-header"> <view class="user-header">
<view class="user-info"> <view class="user-info">
<view class="avatar-wrapper"> <view class="avatar-wrapper" @click="handleAvatarClick">
<image class="avatar" :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" /> <image class="avatar" :src="userInfo.avatar || '/static/default-avatar.png'" mode="aspectFill" />
</view> </view>
<view class="user-detail"> <view class="user-detail">
@@ -122,6 +122,13 @@
</view> </view>
</view> </view>
<!-- 退出登录 -->
<view class="menu-list logout-btn" @click="handleLogout">
<view class="menu-item">
<text class="menu-text" style="color: #e4393c; text-align: center; width: 100%;">退出登录</text>
</view>
</view>
<!-- 开发调试工具仅开发环境显示 --> <!-- 开发调试工具仅开发环境显示 -->
<view v-if="isDev" class="dev-tools"> <view v-if="isDev" class="dev-tools">
<view class="dev-tools-title">开发工具</view> <view class="dev-tools-title">开发工具</view>
@@ -171,6 +178,8 @@ export default {
categoryList: [], categoryList: [],
activeCategory: 'all', activeCategory: 'all',
userInfo: { nickname: '', phone: '', avatar: '' }, userInfo: { nickname: '', phone: '', avatar: '' },
avatarClickCount: 0,
avatarClickTimer: null,
menuList: [ menuList: [
{ title: '我的订单', action: 'order' }, { title: '我的订单', action: 'order' },
{ title: '常见问题', action: 'faq' }, { title: '常见问题', action: 'faq' },
@@ -254,11 +263,13 @@ export default {
// 从缓存加载用户信息 // 从缓存加载用户信息
loadUserInfo() { loadUserInfo() {
const cached = getCachedUserInfo(); const cached = getCachedUserInfo();
console.log('[index] getCachedUserInfo:', JSON.stringify(cached, null, 2));
if (cached) { if (cached) {
this.userInfo = { ...this.userInfo, ...cached }; this.userInfo = { ...this.userInfo, ...cached };
} else { } else {
this.userInfo = { nickname: '', phone: '', avatar: '' }; this.userInfo = { nickname: '', phone: '', avatar: '' };
} }
console.log('[index] this.userInfo:', JSON.stringify(this.userInfo, null, 2));
}, },
async fetchProducts() { async fetchProducts() {
this.loading = true; this.loading = true;
@@ -307,6 +318,39 @@ export default {
}, },
handleNavPrev() { this.currentTab = 'home'; }, handleNavPrev() { this.currentTab = 'home'; },
handleNavNext() { uni.showToast({ title: '暂无下一页', icon: 'none' }); }, handleNavNext() { uni.showToast({ title: '暂无下一页', icon: 'none' }); },
handleAvatarClick() {
this.avatarClickCount++;
clearTimeout(this.avatarClickTimer);
if (this.avatarClickCount >= 10) {
// 点击10次,清除缓存
this.avatarClickCount = 0;
this.clearCacheAndReload();
} else {
// 2秒后重置计数
this.avatarClickTimer = setTimeout(() => {
this.avatarClickCount = 0;
}, 2000);
}
},
handleLogout() {
uni.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
this.clearCacheAndReload();
}
}
});
},
clearCacheAndReload() {
uni.clearStorageSync();
uni.showToast({ title: '已退出登录', icon: 'success' });
setTimeout(() => {
location.reload();
}, 1000);
},
onVConsoleChange(e) { onVConsoleChange(e) {
const enabled = e.detail.value; const enabled = e.detail.value;
if (enabled) { if (enabled) {
@@ -455,6 +499,7 @@ page { height: 100%; background-color: #fff; }
.menu-item:last-child { border-bottom: none; } .menu-item:last-child { border-bottom: none; }
.menu-text { font-size: 30rpx; color: #333; } .menu-text { font-size: 30rpx; color: #333; }
.menu-arrow { font-size: 28rpx; color: #ccc; } .menu-arrow { font-size: 28rpx; color: #ccc; }
.logout-btn { margin-top: 20rpx; }
/* 开发工具区域 */ /* 开发工具区域 */
.dev-tools { margin-top: 20rpx; background-color: #fff; border-radius: 16rpx; overflow: hidden; } .dev-tools { margin-top: 20rpx; background-color: #fff; border-radius: 16rpx; overflow: hidden; }
+7 -2
View File
@@ -201,9 +201,14 @@ export default {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ title: '注册成功', icon: 'success' }); uni.showToast({ title: '注册成功', icon: 'success' });
// 跳转首页 // 跳转到扫码时的页面(优先使用缓存的扫码URL)
setTimeout(() => { setTimeout(() => {
const url = this.deviceId const scanRedirectUrl = uni.getStorageSync('__scan_redirect_url');
uni.removeStorageSync('__scan_redirect_url'); // 使用后立即清除
const url = scanRedirectUrl
? scanRedirectUrl
: this.deviceId
? `/pages/index/index?device_id=${this.deviceId}` ? `/pages/index/index?device_id=${this.deviceId}`
: '/pages/index/index'; : '/pages/index/index';
uni.redirectTo({ url }); uni.redirectTo({ url });
+3 -1
View File
@@ -72,7 +72,9 @@ export function logout() {
*/ */
export function getCachedUserInfo() { export function getCachedUserInfo() {
try { try {
return uni.getStorageSync('user_info') || null; const userInfo = uni.getStorageSync('user_info');
console.log('[auth-guard] getCachedUserInfo raw:', JSON.stringify(userInfo, null, 2));
return userInfo || null;
} catch { } catch {
return null; return null;
} }