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 || {};
console.log('[loading] login response:', JSON.stringify(data, null, 2));
if (data.code === 0 && data.data) {
const result = data.data;
console.log('[loading] login result:', JSON.stringify(result, null, 2));
// 清除 URL 中的 code 参数,避免刷新重复处理
const url = new URL(window.location.href);
@@ -126,11 +129,13 @@ export default {
// 已注册 → 缓存 JWT → 跳转首页
uni.setStorageSync('token', result.token);
uni.setStorageSync('user_info', result.user_info);
console.log('[loading] stored user_info:', JSON.stringify(result.user_info, null, 2));
this.goToHome();
} else {
// 未注册 → 缓存临时数据 → 跳转注册页
uni.setStorageSync('temp_token', result.temp_token);
uni.setStorageSync('auth_info', result.auth_info);
console.log('[loading] stored auth_info:', JSON.stringify(result.auth_info, null, 2));
this.goToRegister();
}
} else {
@@ -152,6 +157,14 @@ export default {
},
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
? `/pages/register/register?device_id=${this.deviceId}`
: '/pages/register/register';
+2
View File
@@ -254,11 +254,13 @@ export default {
// 从缓存加载用户信息
loadUserInfo() {
const cached = getCachedUserInfo();
console.log('[index] getCachedUserInfo:', JSON.stringify(cached, null, 2));
if (cached) {
this.userInfo = { ...this.userInfo, ...cached };
} else {
this.userInfo = { nickname: '', phone: '', avatar: '' };
}
console.log('[index] this.userInfo:', JSON.stringify(this.userInfo, null, 2));
},
async fetchProducts() {
this.loading = true;
+9 -4
View File
@@ -201,11 +201,16 @@ export default {
uni.hideLoading();
uni.showToast({ title: '注册成功', icon: 'success' });
// 跳转首页
// 跳转到扫码时的页面(优先使用缓存的扫码URL)
setTimeout(() => {
const url = this.deviceId
? `/pages/index/index?device_id=${this.deviceId}`
: '/pages/index/index';
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';
uni.redirectTo({ url });
}, 1500);
} else {
+3 -1
View File
@@ -72,7 +72,9 @@ export function logout() {
*/
export function getCachedUserInfo() {
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 {
return null;
}