解决登录显示、首页显示bug

This commit is contained in:
2026-05-19 11:06:46 +08:00
parent 2f7e097e6c
commit 00a859c551
181 changed files with 55329 additions and 998 deletions

View File

@@ -191,7 +191,7 @@
<!-- 退出登录 -->
<view class="logout-section">
<button class="logout-btn" @click="logout">退出登录</button>
<button class="logout-btn" @click="showLogoutConfirm">退出登录</button>
</view>
<!-- 账号注销 -->
@@ -207,6 +207,7 @@ import { ref, onMounted } from 'vue'
import { onBackPress } from '@dcloudio/uni-app'
import supa from '@/components/supadb/aksupainstance.uts'
import { goToLogin } from '@/utils/utils.uts'
import { logout as logoutStore } from '@/utils/store.uts'
// 拦截返回事件,强制跳转到个人中心页
onBackPress((_options): boolean => {
@@ -260,9 +261,55 @@ const cacheSize = ref<string>('0.0 MB')
const currentLanguage = ref<string>('简体中文')
const currentTheme = ref<string>('自动')
const appVersion = ref<string>('1.0.0')
const isLoggingOut = ref<boolean>(false)
const statusBarHeight = ref<number>(0)
const resetLocalUserInfo = (): void => {
userInfo.value = {
id: '',
phone: null,
email: null,
nickname: null,
avatar_url: null
} as UserType
}
const clearAuthStorage = (): void => {
const keys: Array<string> = [
'userInfo',
'user_id',
'access_token',
'refresh_token',
'token',
'currentUser',
'current_user',
'user',
'auth_user',
'supabase.auth.token'
]
for (let i: number = 0; i < keys.length; i++) {
const key = keys[i]
try {
uni.removeStorageSync(key)
} catch (e) {
console.error('[settings] 清理登录态失败:', key, e)
}
}
}
const getStoredUserId = (): string => {
if (userInfo.value.id != null && userInfo.value.id !== '') {
return userInfo.value.id
}
const storageId = uni.getStorageSync('user_id') as string | null
if (storageId != null && storageId !== '') {
return storageId
}
return ''
}
const loadUserInfo = () => {
const userStore = uni.getStorageSync('userInfo')
if (userStore != null) {
@@ -520,38 +567,70 @@ const rateApp = () => {
})
}
const doLogout = (): void => {
const executeLogout = async (): Promise<void> => {
if (isLoggingOut.value) {
return
}
isLoggingOut.value = true
uni.showLoading({
title: '正在退出...'
})
uni.removeStorageSync('userInfo')
uni.removeStorageSync('user_id')
uni.removeStorageSync('access_token')
try {
logoutStore()
uni.hideLoading()
try {
await supa.signOut()
} catch (signOutError) {
console.error('[settings] supa.signOut failed:', signOutError)
}
uni.showToast({
title: '已退出登录',
icon: 'success'
})
clearAuthStorage()
resetLocalUserInfo()
setTimeout(() => {
uni.reLaunch({
url: '/pages/user/login'
uni.hideLoading()
uni.showToast({
title: '退出成功',
icon: 'success',
duration: 1200
})
}, 1000)
uni.$emit('authChanged', { loggedIn: false })
setTimeout(() => {
uni.switchTab({
url: '/pages/main/profile'
})
}, 1000)
} catch (e) {
console.error('[settings] logout failed:', e)
uni.hideLoading()
uni.showToast({
title: '网络异常',
icon: 'none',
duration: 1500
})
} finally {
isLoggingOut.value = false
}
}
const getStoredUserId = (): string => {
if (userInfo.value.id != null && userInfo.value.id !== '') {
return userInfo.value.id
const showLogoutConfirm = (): void => {
if (isLoggingOut.value) {
return
}
const storageId = uni.getStorageSync('user_id')
if (storageId != null) {
return storageId as string
}
return ''
uni.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
confirmText: '退出',
cancelText: '取消',
success: (res) => {
if (res.confirm) {
executeLogout()
}
}
})
}
const doDeleteAccount = (): void => {
@@ -570,9 +649,8 @@ const doDeleteAccount = (): void => {
.execute()
}
uni.removeStorageSync('userInfo')
uni.removeStorageSync('user_id')
uni.removeStorageSync('access_token')
clearAuthStorage()
resetLocalUserInfo()
uni.hideLoading()
uni.showToast({
@@ -588,18 +666,6 @@ const doDeleteAccount = (): void => {
}, 1500)
}
// 退出登录
const logout = () => {
uni.showModal({
title: '退出登录',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
doLogout()
}
}
})
}
const deleteAccount = () => {
uni.showModal({
title: '注销账号',