index.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import type { App } from "vue";
  2. import { createRouter, createWebHashHistory, type RouteRecordRaw } from "vue-router";
  3. export const Layout = () => import("@/layouts/index.vue");
  4. /**
  5. * 静态路由
  6. */
  7. export const constantRoutes: RouteRecordRaw[] = [
  8. {
  9. path: "/redirect",
  10. meta: { hidden: true },
  11. component: Layout,
  12. children: [
  13. {
  14. path: "/redirect/:path(.*)",
  15. component: () => import("@/views/redirect/index.vue"),
  16. },
  17. ],
  18. },
  19. {
  20. path: "/login",
  21. name: "Login",
  22. meta: { hidden: true },
  23. component: () => import("@/views/module_system/auth/index.vue"),
  24. },
  25. {
  26. path: "/enterprise/select",
  27. name: "EnterpriseSelect",
  28. meta: { hidden: true, title: "选择企业" },
  29. component: () => import("@/views/enterprise/select.vue"),
  30. },
  31. {
  32. path: "/401",
  33. name: "401",
  34. meta: { hidden: true, title: "401" },
  35. component: () => import("@/views/error/401.vue"),
  36. },
  37. {
  38. // 顾客页(收款链接 `/#/checkout/<token>` 的落点)—— **免登录**,所以必须放在
  39. // `constantRoutes` 里:动态路由要先生成权限表,而打开链接的人没有登录态。
  40. //
  41. // ★ `name` 是**对外承诺**,不是本地标签:免登录放行判据读的就是它
  42. // (`plugins/permission.ts` 的 `PUBLIC_ROUTE_NAMES`)。改名要把两边一起改,
  43. // 否则顾客页会静默变回「跳登录页」—— 页面本身没有任何报错。
  44. // ★ 路径形状由后端决定:`LsyCheckoutLinkService#buildUrl` 拼的是
  45. // `<base>/#/checkout/<token>`(hash 路由,`createWebHashHistory`),
  46. // 所以这里带不带前导 `/` 都一样,但**必须**是 `checkout/:token` 两段。
  47. path: "/checkout/:token",
  48. name: "Checkout",
  49. meta: { hidden: true, title: "收款" },
  50. component: () => import("@/views/checkout/index.vue"),
  51. },
  52. {
  53. // 汇安融顾客页(收款链接 `/#/checkout/alipay/<token>` 的落点)—— 免登录,同上一段。
  54. // ★ 为什么是**三段**路径而乐收赢是两段:`HarCheckoutLinkService#buildUrl` 的
  55. // PATH_PREFIX 是 `/#/checkout/alipay/`,`alipay` 是路径里的**字面段**,不是参数。
  56. // 若按乐收赢写成 `checkout/:token`,`alipay` 会被当成 token ⇒ 顾客页拿着 "alipay"
  57. // 去查链接,一律「链接无效」。
  58. // (路径段 2026-10-09 由 `har` 改来 —— 这串出现在顾客眼前,不带上游品牌;
  59. // 与后端 PATH_PREFIX 必须**同名**改,改单边就是整页 404。)
  60. path: "/checkout/alipay/:token",
  61. name: "HarCheckout",
  62. meta: { hidden: true, title: "收款" },
  63. component: () => import("@/views/checkout/har/index.vue"),
  64. },
  65. {
  66. path: "/404",
  67. name: "404",
  68. meta: { hidden: true, title: "404" },
  69. component: () => import("@/views/error/404.vue"),
  70. },
  71. {
  72. path: "/500",
  73. name: "500",
  74. meta: { hidden: true, title: "500" },
  75. component: () => import("@/views/error/500.vue"),
  76. },
  77. {
  78. path: "/",
  79. name: "/",
  80. redirect: "/home",
  81. component: Layout,
  82. children: [
  83. {
  84. path: "home",
  85. component: () => import("@/views/dashboard/tenant.vue"),
  86. // 用于 keep-alive 功能,需要与 SFC 中自动推导或显式声明的组件名称一致
  87. // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
  88. name: "Home",
  89. meta: {
  90. title: "首页",
  91. icon: "homepage",
  92. affix: true,
  93. keepAlive: true,
  94. },
  95. },
  96. {
  97. path: "profile",
  98. name: "Profile",
  99. meta: { title: "个人中心", icon: "user", hidden: true },
  100. component: () => import("@/views/current/profile.vue"),
  101. },
  102. ],
  103. },
  104. // 通配 404 必须置于静态路由最后,否则会抢先匹配 /、/home 等
  105. {
  106. path: "/:pathMatch(.*)*",
  107. component: () => import("@/views/error/404.vue"),
  108. meta: { hidden: true, title: "404" },
  109. },
  110. ];
  111. /**
  112. * 创建路由
  113. */
  114. const router = createRouter({
  115. history: createWebHashHistory(),
  116. routes: constantRoutes,
  117. // 刷新时,滚动条位置还原
  118. scrollBehavior: () => ({ left: 0, top: 0 }),
  119. });
  120. // 全局注册 router
  121. // 为了捕获并处理全局错误,在注册路由时添加错误处理
  122. export function setupRouter(app: App<Element>) {
  123. app.use(router);
  124. }
  125. export default router;