// src/router/index.ts
import { createRouter, createWebHistory } from "vue-router";
import NProgress from "nprogress";
import "nprogress/nprogress.css"; // 引入 NProgress 的 CSS 样式文件
import { ElMessage } from "element-plus";
const routes = [
  {
    path: "/login",
    name: "login",
    meta: { title: "", icon: "", showHeader: false },
    component: () => import("@/views/login/login.vue"),
  },
  {
    path: "/",
    redirect: "/login",
  },
  // 校友信息管理
  {
    path: "/alumni-info",
    component: () => import("@/views/alumni-info/alumni-info.vue"),
    meta: { title: "校友信息管理", icon: "el-icon-user",showHeader: true },
  },
  // 校友组织管理
  {
    path: "/alumni-organization",
    component: () =>
      import("@/views/alumni-organization/alumni-organization.vue"),
    meta: { title: "校友组织管理", icon: "el-icon-s-tools",showHeader: true },
  },
  // 校友活动管理
  {
    path: "/alumni-activity",
    component: () => import("@/views/alumni-activity/alumni-activity.vue"),
    meta: { title: "校友活动管理", icon: "el-icon-date",showHeader: true },
  },
  // 广场信息管理
  {
    path: "/alumni-square",
    component: () => import("@/views/alumni-square/alumni-square.vue"),
    meta: { title: "广场信息管理", icon: "el-icon-chat-dot-round",showHeader: true },
  },
  // 校友合作管理
  {
    path: "/alumni-cooperation",
    component: () =>
      import("@/views/alumni-cooperation/alumni-cooperation.vue"),
    meta: { title: "校友合作管理", icon: "el-icon-s-data",showHeader: true },
  },
  // 校友企业管理
  {
    path: "/alumni-enterprise",
    component: () => import("@/views/alumni-enterprise/alumni-enterprise.vue"),
    meta: { title: "校友企业管理", icon: "el-icon-office-building",showHeader: true },
  },
  // 校友风采管理
  {
    path: "/alumni-style",
    component: () => import("@/views/alumni-style/alumni-style.vue"),
    meta: { title: "校友风采管理", icon: "el-icon-user-solid",showHeader: true },
  },
  // 新闻聚焦管理
  {
    path: "/alumni-new",
    component: () => import("@/views/alumni-new/alumni-new.vue"),
    meta: { title: "新闻聚焦管理", icon: "el-icon-document",showHeader: true },
  },
  // 返校服务管理
  {
    path: "/homecoming-service",
    component: () =>
      import("@/views/homecoming-service/homecoming-service.vue"),
    meta: { title: "返校服务管理", icon: "el-icon-house",showHeader: true },
  },
  // 电子校友卡管理
  {
    path: "/alumni-card",
    component: () => import("@/views/alumni-card/alumni-card.vue"),
    meta: { title: "电子校友卡管理", icon: "el-icon-ticket",showHeader: true },
  },
  // 校友相册管理
  {
    path: "/alumni-album",
    component: () => import("@/views/alumni-album/alumni-album.vue"),
    meta: { title: "校友相册管理", icon: "el-icon-picture" ,showHeader: true},
  },
  // 权限管理
  {
    path: "/permission",
    component: () => import("@/views/permission/permission.vue"),
    meta: { title: "权限管理", icon: "el-icon-lock",showHeader: true },
  },
  // 操作日志
  {
    path: "/operation-log",
    component: () => import("@/views/operation-log/operation-log.vue"),
    meta: { title: "操作日志", icon: "el-icon-document-copy",showHeader: true },
  },
  // 系统设置
  {
    path: "/system-setting",
    component: () => import("@/views/system-setting/system-setting.vue"),
    meta: { title: "系统设置", icon: "el-icon-setting",showHeader: true },
  },
  {
    path: "/:pathMatch(.*)*",
    redirect: "/404",
  },
];
const router = createRouter({
  history: createWebHistory(),
  routes,
});

// 配置 NProgress
NProgress.configure({ showSpinner: false }); // 根据需要配置选项

// 在路由守卫中启动和停止 NProgress
router.beforeEach(async (to, from, next) => {
  NProgress.start(); // 开始加载进度条

  let token = sessionStorage.getItem("token");
  // if (to.path == "/login") {
  //   next();
  // } else {
  //   if (token) {
  //     next();
  //   } else {
  //     ElMessage({
  //       type: "error",
  //       showClose: true,
  //       message: "无权限进入此页面",
  //       center: true,
  //     });
  //     sessionStorage.removeItem("token")// 移出token
  //     sessionStorage.removeItem("id")// 移出用户id
  //     sessionStorage.removeItem("permissionList")// 移出权限列表
  //     sessionStorage.removeItem("permissionListFlat")
  //     next("/login");
  //   }
  // }
  next();
});
router.afterEach(() => {
  NProgress.done(); // 结束加载进度条
});
export default router;
