spring
16 小时以前 b83e8417c341636a6da3a8eb7db7c151ef3c00cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { useUserStore } from "@/store/modules/user";
 
/**
 * 检查用户登录状态,未登录则跳转到登录页面
 * @returns 返回用户是否已登录
 */
export function checkLogin(): boolean {
  const userStore = useUserStore();
 
  if (!userStore.userInfo) {
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    const currentPagePath = `/${currentPage.route}`;
 
    uni.navigateTo({
      url: `/pages/login/index?redirect=${encodeURIComponent(currentPagePath)}`,
    });
    return false;
  }
 
  return true;
}