bugfix:未登录循环注册

This commit is contained in:
2026-09-13 01:08:11 +08:00
parent 0a8d60d87f
commit f897e1a391
12 changed files with 268 additions and 38 deletions
@@ -1,4 +1,5 @@
import { request } from '../../utils/request'
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { PagedResult, ClosetShareItem } from '../../types/models'
Page({
@@ -17,6 +18,11 @@ Page({
onShow() {
this.syncTabBar()
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
redirectToLogin()
return
}
this.refresh()
},
+7 -1
View File
@@ -1,4 +1,5 @@
import { request } from '../../utils/request'
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { HoroscopeData } from '../../types/models'
const COLOR_MAP: Record<string, string> = {
@@ -25,6 +26,11 @@ Page({
onShow() {
this.syncTabBar()
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
redirectToLogin()
return
}
if (!this.data.horoscope) this.fetchHoroscope(0)
},
+2
View File
@@ -48,6 +48,8 @@ Page({
expireTime: data.expire_time,
})
wx.setStorageSync(STORAGE_KEYS.USER_INFO, data.user_info)
// 新登录用户重置未读红点,进入 tab 页后由 tabBar 拉取真实值
wx.setStorageSync(STORAGE_KEYS.UNREAD, 0)
this.setData({ userInfo: data.user_info })
if (data.user_info.is_new_user) {
this.showWelcomeGift(data.user_info)
+17 -4
View File
@@ -1,5 +1,7 @@
import { request } from '../../utils/request'
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { PagedResult, NotificationItem } from '../../types/models'
import { STORAGE_KEYS } from '../../utils/config'
import { formatRelativeTime } from '../../utils/format'
const FILTERS = [
@@ -21,16 +23,27 @@ Page({
},
onShow() {
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
redirectToLogin()
return
}
this.refresh()
this.fetchUnread()
},
fetchUnread() {
request<{ unread_count: number }>({ url: '/notification/unread', showError: false })
request<{ unread_count: number }>({
url: '/notification/unread',
showError: false,
silentAuth: true,
})
.then((res) => {
wx.setStorageSync('zt_closet_unread', res.unread_count)
const unread = res.unread_count || 0
wx.setStorageSync(STORAGE_KEYS.UNREAD, unread)
const tabBar = (this as any).getTabBar && (this as any).getTabBar()
if (tabBar && tabBar.refreshUnread) tabBar.refreshUnread()
// 直接更新红点,避免 tabBar 内部再发一次请求
if (tabBar && tabBar.setUnread) tabBar.setUnread(unread)
})
.catch(() => {})
},
+7 -1
View File
@@ -1,4 +1,5 @@
import { request } from '../../utils/request'
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { PagedResult, OutfitItem } from '../../types/models'
import { OutfitSource, IsPublic } from '../../utils/config'
@@ -15,6 +16,11 @@ Page({
onShow() {
this.syncTabBar()
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
redirectToLogin()
return
}
const openCollect = wx.getStorageSync('zt_open_collect')
if (openCollect) {
wx.removeStorageSync('zt_open_collect')
+9 -5
View File
@@ -1,4 +1,5 @@
import { request, uploadFile } from '../../utils/request'
import { request, uploadFile, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { UserInfo, QuotaItem } from '../../types/models'
import { QuotaType, STORAGE_KEYS } from '../../utils/config'
import { formatDate } from '../../utils/format'
@@ -46,16 +47,19 @@ Page({
onShow() {
this.syncTabBar()
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
redirectToLogin()
return
}
this.fetchUser()
this.fetchQuota()
},
syncTabBar() {
const tabBar = (this as any).getTabBar && (this as any).getTabBar()
if (tabBar) {
tabBar.setData({ selected: 4 })
if (tabBar.refreshUnread) tabBar.refreshUnread()
}
// 红点由 tabBar 自身在登录态下同步,这里只更新选中态
if (tabBar) tabBar.setData({ selected: 4 })
},
fetchUser() {
+7 -1
View File
@@ -1,4 +1,5 @@
import { request } from '../../utils/request'
import { request, redirectToLogin } from '../../utils/request'
import * as auth from '../../utils/auth'
import { PagedResult, ClothesItem, QuotaItem } from '../../types/models'
import { QuotaType } from '../../utils/config'
@@ -28,6 +29,11 @@ Page({
onShow() {
this.syncTabBar()
// 未登录直接回登录页(幂等跳转),不再发出必然 401 的请求
if (!auth.isLoggedIn()) {
redirectToLogin()
return
}
this.refresh()
},