| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import { createRouter, createWebHistory } from "vue-router"
- import ScreenLayout from "../layout/ScreenLayout.vue"
- import { getToken } from "../utils/auth"
- import { ensureScreenAutoLogin, isScreenAutoLoginEnabled } from "../utils/screenAutoLogin"
- /**
- * 大屏路由表(路径与后端 /bigScreen/* 业务对应,便于联调)
- * meta.titleZh / titleBo:浏览器标题与页面双语标题参考
- */
- const routes = [
- {
- path: "/login",
- name: "Login",
- component: () => import("../views/login/index.vue"),
- meta: {
- titleZh: "登录",
- titleBo: "ཐོ་ཞུགས།",
- public: true
- }
- },
- {
- path: "/",
- component: ScreenLayout,
- redirect: "/home",
- meta: { requiresAuth: true },
- children: [
- {
- path: "home",
- name: "ScreenHome",
- component: () => import("../views/home/index.vue"),
- meta: {
- titleZh: "数字畜牧一张图",
- titleBo: "གཙོ་ངོས།"
- }
- },
- {
- path: "livestock-resources",
- name: "LivestockResources",
- component: () => import("../views/livestockResources/index.vue"),
- meta: {
- titleZh: "畜牧资源",
- titleBo: "སྐྱེས་ཁམས་ཐོན་ཁུངས།"
- }
- },
- {
- path: "trade-sales",
- name: "TradeSales",
- component: () => import("../views/tradeSales/index.vue"),
- meta: {
- titleZh: "交易销售",
- titleBo: "འབྲེལ་གཏོང་ཚོང་འབུལ།"
- }
- },
- {
- path: "common-prosperity",
- name: "CommonProsperity",
- component: () => import("../views/commonProsperity/index.vue"),
- meta: {
- titleZh: "共同富裕统计",
- titleBo: "སྤྱི་འགྲོས་ཕྱུག་པོའི་བསྡུས་རྩིས།"
- }
- },
- {
- path: "epidemic-risk",
- name: "EpidemicRisk",
- component: () => import("../views/epidemicRisk/index.vue"),
- meta: {
- titleZh: "疫病风险统计",
- titleBo: "ནད་རིམས་ཉེན་ཁའི་བསྡུས་རྩིས།"
- }
- },
- {
- path: ":pathMatch(.*)*",
- name: "NotFound",
- component: () => import("../views/error/404.vue"),
- meta: {
- titleZh: "页面不存在",
- titleBo: "ཤོག་ངོས་མི་འདུག"
- }
- }
- ]
- }
- ]
- const router = createRouter({
- // 与 ruoyi-ui router.base 一致;生产 import.meta.env.BASE_URL 为 /screen/
- history: createWebHistory(import.meta.env.BASE_URL),
- routes
- })
- /** 未登录跳转登录页;已登录访问 /login 则进首页;启用免密时先尝试自动登录 */
- router.beforeEach(async (to, _from, next) => {
- const token = getToken()
- if (to.path === "/login") {
- if (token) {
- next({ path: "/home" })
- return
- }
- if (isScreenAutoLoginEnabled()) {
- const ok = await ensureScreenAutoLogin()
- if (ok) {
- const redirect =
- typeof to.query.redirect === "string" ? to.query.redirect : "/home"
- next({ path: redirect })
- return
- }
- }
- next()
- return
- }
- const needAuth = to.matched.some((r) => r.meta.requiresAuth)
- if (needAuth && !getToken()) {
- if (isScreenAutoLoginEnabled()) {
- const ok = await ensureScreenAutoLogin()
- if (ok) {
- next()
- return
- }
- }
- next({ path: "/login", query: { redirect: to.fullPath } })
- return
- }
- next()
- })
- /** 根据路由 meta 更新浏览器标签标题 */
- router.afterEach((to) => {
- const zh = to.meta?.titleZh
- const appTitle = import.meta.env.VITE_APP_TITLE || "ruoyi-screen"
- document.title = zh ? `${zh} - ${appTitle}` : appTitle
- })
- export default router
|