feat:首页和案例库功能
This commit is contained in:
@@ -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
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user