Compare commits

...

1 Commits

Author SHA1 Message Date
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 27 additions and 5 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';
+2
View File
@@ -254,11 +254,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;
+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;
} }