20 lines
460 B
TypeScript
20 lines
460 B
TypeScript
import { getAccessToken } from '@/utils/auth-storage'
|
|
|
|
export const LOGIN_PAGE = '/pages/Login/user-login/index'
|
|
|
|
export function isLoggedIn() {
|
|
return Boolean(getAccessToken())
|
|
}
|
|
|
|
/** 未登录时跳转登录页,返回是否已登录 */
|
|
export function ensureLoggedIn(showToast = true) {
|
|
if (isLoggedIn())
|
|
return true
|
|
|
|
if (showToast)
|
|
uni.showToast({ title: '请先登录', icon: 'none' })
|
|
|
|
uni.reLaunch({ url: LOGIN_PAGE })
|
|
return false
|
|
}
|