feat:首页和案例库功能

This commit is contained in:
李伊帆
2026-09-21 15:41:52 +08:00
parent 24d001e0f5
commit b0a711f70a
35 changed files with 1201 additions and 354 deletions

View File

@@ -1,7 +1,9 @@
import { getAccessToken } from '@/utils/auth-storage'
import { clearAuthSession, getAccessToken } from '@/utils/auth-storage'
export const LOGIN_PAGE = '/pages/Login/user-login/index'
let redirectingToLogin = false
export function isLoggedIn() {
return Boolean(getAccessToken())
}
@@ -14,6 +16,26 @@ export function ensureLoggedIn(showToast = true) {
if (showToast)
uni.showToast({ title: '请先登录', icon: 'none' })
uni.reLaunch({ url: LOGIN_PAGE })
redirectToLogin()
return false
}
/** 登录态失效(如接口返回 401)时清除会话并跳转登录页 */
export function handleUnauthorized(message = '登录已过期,请重新登录') {
if (redirectingToLogin)
return
redirectingToLogin = true
clearAuthSession()
uni.showToast({ title: message, icon: 'none' })
redirectToLogin()
}
function redirectToLogin() {
uni.reLaunch({
url: LOGIN_PAGE,
complete: () => {
redirectingToLogin = false
},
})
}