@skyroc/scripts 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (333) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +508 -0
  3. package/dist/cli.mjs +78 -0
  4. package/dist/config-BKkdncJS.mjs +987 -0
  5. package/dist/index.mjs +14 -0
  6. package/package.json +83 -0
  7. package/templates/admin/.env +62 -0
  8. package/templates/admin/.env.prod +7 -0
  9. package/templates/admin/.env.test +7 -0
  10. package/templates/admin/.oxlintrc.json +6 -0
  11. package/templates/admin/README.md +508 -0
  12. package/templates/admin/index.html +14 -0
  13. package/templates/admin/package.json +105 -0
  14. package/templates/admin/public/favicon.svg +3 -0
  15. package/templates/admin/src/App.tsx +71 -0
  16. package/templates/admin/src/assets/audio/wechat-style-notification.wav +0 -0
  17. package/templates/admin/src/assets/imgs/skyroc.jpg +0 -0
  18. package/templates/admin/src/assets/svg-icon/activity.svg +1 -0
  19. package/templates/admin/src/assets/svg-icon/at-sign.svg +1 -0
  20. package/templates/admin/src/assets/svg-icon/avatar.svg +1 -0
  21. package/templates/admin/src/assets/svg-icon/banner.svg +1 -0
  22. package/templates/admin/src/assets/svg-icon/cast.svg +1 -0
  23. package/templates/admin/src/assets/svg-icon/chrome.svg +1 -0
  24. package/templates/admin/src/assets/svg-icon/copy.svg +1 -0
  25. package/templates/admin/src/assets/svg-icon/custom-icon.svg +1 -0
  26. package/templates/admin/src/assets/svg-icon/empty-data.svg +1 -0
  27. package/templates/admin/src/assets/svg-icon/error.svg +1 -0
  28. package/templates/admin/src/assets/svg-icon/expectation.svg +1 -0
  29. package/templates/admin/src/assets/svg-icon/heart.svg +1 -0
  30. package/templates/admin/src/assets/svg-icon/logo.svg +15 -0
  31. package/templates/admin/src/assets/svg-icon/network-error.svg +1 -0
  32. package/templates/admin/src/assets/svg-icon/no-icon.svg +1 -0
  33. package/templates/admin/src/assets/svg-icon/no-permission.svg +1 -0
  34. package/templates/admin/src/assets/svg-icon/not-found.svg +1 -0
  35. package/templates/admin/src/assets/svg-icon/service-error.svg +1 -0
  36. package/templates/admin/src/bootstrap.tsx +60 -0
  37. package/templates/admin/src/components/SkyrocAvatar.tsx +13 -0
  38. package/templates/admin/src/components/SystemLogo.tsx +7 -0
  39. package/templates/admin/src/config.ts +125 -0
  40. package/templates/admin/src/features/antd/AntdProvider.tsx +21 -0
  41. package/templates/admin/src/features/auth/components/UserAvatar.tsx +76 -0
  42. package/templates/admin/src/features/auth/use-auth-form-rules.ts +83 -0
  43. package/templates/admin/src/features/auth/use-auth.ts +96 -0
  44. package/templates/admin/src/features/auth/use-login.ts +72 -0
  45. package/templates/admin/src/features/effects/GlobalEffect.tsx +15 -0
  46. package/templates/admin/src/features/menus/dynamic-routes.ts +10 -0
  47. package/templates/admin/src/features/menus/extras.ts +3 -0
  48. package/templates/admin/src/features/menus/menu-category.ts +14 -0
  49. package/templates/admin/src/features/menus/menu-config.ts +5 -0
  50. package/templates/admin/src/features/router/RouterProvider.tsx +18 -0
  51. package/templates/admin/src/features/router/guard.ts +97 -0
  52. package/templates/admin/src/features/router/index.ts +52 -0
  53. package/templates/admin/src/features/router/routeTree.gen.ts +237 -0
  54. package/templates/admin/src/features/router/router-ref.ts +24 -0
  55. package/templates/admin/src/locales/antd.ts +8 -0
  56. package/templates/admin/src/locales/index.ts +22 -0
  57. package/templates/admin/src/locales/sync.ts +14 -0
  58. package/templates/admin/src/main.tsx +9 -0
  59. package/templates/admin/src/pages/(admin)/home/index.tsx +46 -0
  60. package/templates/admin/src/pages/(admin)/layout.tsx +44 -0
  61. package/templates/admin/src/pages/(auth)/login/index.tsx +102 -0
  62. package/templates/admin/src/pages/(auth)/login/layout.tsx +71 -0
  63. package/templates/admin/src/pages/(auth)/login-out.tsx +27 -0
  64. package/templates/admin/src/pages/(errors)/403.tsx +16 -0
  65. package/templates/admin/src/pages/(errors)/404.tsx +16 -0
  66. package/templates/admin/src/pages/(errors)/500.tsx +16 -0
  67. package/templates/admin/src/pages/__root.tsx +54 -0
  68. package/templates/admin/src/pages/error.tsx +19 -0
  69. package/templates/admin/src/pages/index.tsx +14 -0
  70. package/templates/admin/src/pages/loading.tsx +45 -0
  71. package/templates/admin/src/pages/not-found.tsx +9 -0
  72. package/templates/admin/src/plugins/app.tsx +47 -0
  73. package/templates/admin/src/plugins/assets.ts +4 -0
  74. package/templates/admin/src/plugins/index.ts +32 -0
  75. package/templates/admin/src/service/adapter.ts +63 -0
  76. package/templates/admin/src/service/api/auth/api.ts +31 -0
  77. package/templates/admin/src/service/api/auth/hooks.ts +28 -0
  78. package/templates/admin/src/service/api/auth/index.ts +10 -0
  79. package/templates/admin/src/service/api/auth/keys.ts +7 -0
  80. package/templates/admin/src/service/api/auth/urls.ts +7 -0
  81. package/templates/admin/src/service/api/index.ts +2 -0
  82. package/templates/admin/src/service/api/route/api.ts +7 -0
  83. package/templates/admin/src/service/api/route/hooks.ts +21 -0
  84. package/templates/admin/src/service/api/route/index.ts +10 -0
  85. package/templates/admin/src/service/api/route/keys.ts +3 -0
  86. package/templates/admin/src/service/api/route/urls.ts +5 -0
  87. package/templates/admin/src/service/queryClient.ts +13 -0
  88. package/templates/admin/src/service/request/index.ts +62 -0
  89. package/templates/admin/src/styles/scss/global.scss +1 -0
  90. package/templates/admin/src/styles/scss/scrollbar.scss +28 -0
  91. package/templates/admin/src/types/auto-imports.d.ts +186 -0
  92. package/templates/admin/src/types/global.d.ts +16 -0
  93. package/templates/admin/src/types/router.d.ts +14 -0
  94. package/templates/admin/src/types/storage.d.ts +17 -0
  95. package/templates/admin/src/types/vite-env.d.ts +117 -0
  96. package/templates/admin/src/utils/common.tsx +38 -0
  97. package/templates/admin/src/utils/icon.ts +9 -0
  98. package/templates/admin/src/utils/service.ts +75 -0
  99. package/templates/admin/src/utils/storage.ts +7 -0
  100. package/templates/admin/tsconfig.json +22 -0
  101. package/templates/admin/uno.config.ts +18 -0
  102. package/templates/admin/vite.config.ts +13 -0
  103. package/templates/admin-shell/i18n/atoms/lang.ts +20 -0
  104. package/templates/admin-shell/i18n/config/default.ts +11 -0
  105. package/templates/admin-shell/i18n/features/lang/LangEffect.tsx +25 -0
  106. package/templates/admin-shell/i18n/features/lang/LangSwitch.tsx +49 -0
  107. package/templates/admin-shell/i18n/hooks/use-lang.ts +47 -0
  108. package/templates/admin-shell/i18n/i18n.ts +116 -0
  109. package/templates/admin-shell/i18n/index.ts +23 -0
  110. package/templates/admin-shell/i18n/langs/en-us/common.json +49 -0
  111. package/templates/admin-shell/i18n/langs/en-us/datatable.json +8 -0
  112. package/templates/admin-shell/i18n/langs/en-us/dropdown.json +9 -0
  113. package/templates/admin-shell/i18n/langs/en-us/form.json +27 -0
  114. package/templates/admin-shell/i18n/langs/en-us/icon.json +13 -0
  115. package/templates/admin-shell/i18n/langs/en-us/notification.json +20 -0
  116. package/templates/admin-shell/i18n/langs/en-us/page.json +442 -0
  117. package/templates/admin-shell/i18n/langs/en-us/request.json +8 -0
  118. package/templates/admin-shell/i18n/langs/en-us/route.json +84 -0
  119. package/templates/admin-shell/i18n/langs/en-us/system.json +9 -0
  120. package/templates/admin-shell/i18n/langs/en-us/theme.json +173 -0
  121. package/templates/admin-shell/i18n/langs/index.ts +63 -0
  122. package/templates/admin-shell/i18n/langs/zh-cn/common.json +49 -0
  123. package/templates/admin-shell/i18n/langs/zh-cn/datatable.json +8 -0
  124. package/templates/admin-shell/i18n/langs/zh-cn/dropdown.json +9 -0
  125. package/templates/admin-shell/i18n/langs/zh-cn/form.json +27 -0
  126. package/templates/admin-shell/i18n/langs/zh-cn/icon.json +13 -0
  127. package/templates/admin-shell/i18n/langs/zh-cn/notification.json +20 -0
  128. package/templates/admin-shell/i18n/langs/zh-cn/page.json +442 -0
  129. package/templates/admin-shell/i18n/langs/zh-cn/request.json +8 -0
  130. package/templates/admin-shell/i18n/langs/zh-cn/route.json +84 -0
  131. package/templates/admin-shell/i18n/langs/zh-cn/system.json +9 -0
  132. package/templates/admin-shell/i18n/langs/zh-cn/theme.json +173 -0
  133. package/templates/admin-shell/i18n/types/i18n.ts +29 -0
  134. package/templates/admin-shell/i18n/types.ts +53 -0
  135. package/templates/admin-shell/i18n/utils/helpers.ts +18 -0
  136. package/templates/admin-shell/layouts/AdminLayout.tsx +161 -0
  137. package/templates/admin-shell/layouts/constant.ts +56 -0
  138. package/templates/admin-shell/layouts/context.tsx +101 -0
  139. package/templates/admin-shell/layouts/features/menus/MenuBadge.tsx +76 -0
  140. package/templates/admin-shell/layouts/features/menus/dynamic-routes.ts +146 -0
  141. package/templates/admin-shell/layouts/features/menus/menu-generator.tsx +444 -0
  142. package/templates/admin-shell/layouts/features/menus/menu-renderer.tsx +149 -0
  143. package/templates/admin-shell/layouts/features/menus/permissions.ts +28 -0
  144. package/templates/admin-shell/layouts/features/menus/use-menus.ts +98 -0
  145. package/templates/admin-shell/layouts/features/use-route.ts +30 -0
  146. package/templates/admin-shell/layouts/index.ts +44 -0
  147. package/templates/admin-shell/layouts/materials/index.ts +6 -0
  148. package/templates/admin-shell/layouts/materials/libs/admin-layout/index.module.css +63 -0
  149. package/templates/admin-shell/layouts/materials/libs/admin-layout/index.module.css.d.ts +18 -0
  150. package/templates/admin-shell/layouts/materials/libs/admin-layout/index.tsx +238 -0
  151. package/templates/admin-shell/layouts/materials/libs/admin-layout/shared.ts +67 -0
  152. package/templates/admin-shell/layouts/materials/libs/page-tab/ButtonTab.tsx +44 -0
  153. package/templates/admin-shell/layouts/materials/libs/page-tab/ChromeTab.tsx +54 -0
  154. package/templates/admin-shell/layouts/materials/libs/page-tab/ChromeTabBg.tsx +30 -0
  155. package/templates/admin-shell/layouts/materials/libs/page-tab/SliderTab.tsx +44 -0
  156. package/templates/admin-shell/layouts/materials/libs/page-tab/SvgClose.tsx +51 -0
  157. package/templates/admin-shell/layouts/materials/libs/page-tab/hook.ts +34 -0
  158. package/templates/admin-shell/layouts/materials/libs/page-tab/index.module.css +120 -0
  159. package/templates/admin-shell/layouts/materials/libs/page-tab/index.module.css.d.ts +18 -0
  160. package/templates/admin-shell/layouts/materials/libs/page-tab/index.tsx +76 -0
  161. package/templates/admin-shell/layouts/materials/libs/page-tab/shared.ts +32 -0
  162. package/templates/admin-shell/layouts/materials/types/index.ts +322 -0
  163. package/templates/admin-shell/layouts/modules/AdminContent.tsx +285 -0
  164. package/templates/admin-shell/layouts/modules/AdminFooter.tsx +13 -0
  165. package/templates/admin-shell/layouts/modules/AdminLogo.tsx +28 -0
  166. package/templates/admin-shell/layouts/modules/AdminSider.tsx +50 -0
  167. package/templates/admin-shell/layouts/modules/admin-header/AdminHeader.tsx +132 -0
  168. package/templates/admin-shell/layouts/modules/admin-header/components/Breadcrumb.tsx +62 -0
  169. package/templates/admin-shell/layouts/modules/admin-header/components/ThemeButton.tsx +24 -0
  170. package/templates/admin-shell/layouts/modules/admin-menu/AdminMenu.tsx +37 -0
  171. package/templates/admin-shell/layouts/modules/admin-menu/components/FirstLevelMenu.tsx +156 -0
  172. package/templates/admin-shell/layouts/modules/admin-menu/components/HorizontalMenu.tsx +88 -0
  173. package/templates/admin-shell/layouts/modules/admin-menu/components/MenuPortal.tsx +28 -0
  174. package/templates/admin-shell/layouts/modules/admin-menu/components/VerticalMenu.tsx +123 -0
  175. package/templates/admin-shell/layouts/modules/admin-menu/enum.ts +47 -0
  176. package/templates/admin-shell/layouts/modules/admin-menu/modules/Horizontal.tsx +22 -0
  177. package/templates/admin-shell/layouts/modules/admin-menu/modules/TopHybridHeaderFirst.tsx +15 -0
  178. package/templates/admin-shell/layouts/modules/admin-menu/modules/TopHybridSidebarFirst.tsx +18 -0
  179. package/templates/admin-shell/layouts/modules/admin-menu/modules/Vertical.tsx +14 -0
  180. package/templates/admin-shell/layouts/modules/admin-menu/modules/VerticalHybridHeaderFirst.tsx +18 -0
  181. package/templates/admin-shell/layouts/modules/admin-menu/modules/VerticalMix.tsx +132 -0
  182. package/templates/admin-shell/layouts/modules/admin-search/AdminSearch.tsx +36 -0
  183. package/templates/admin-shell/layouts/modules/admin-search/components/SearchFooter.tsx +38 -0
  184. package/templates/admin-shell/layouts/modules/admin-search/components/SearchModal.tsx +171 -0
  185. package/templates/admin-shell/layouts/modules/admin-search/components/SearchResult.tsx +43 -0
  186. package/templates/admin-shell/layouts/modules/admin-tab/AdminTab.tsx +125 -0
  187. package/templates/admin-shell/layouts/modules/admin-tab/components/TabContextMenu.tsx +107 -0
  188. package/templates/admin-shell/layouts/modules/admin-tab/hooks/useTabScroll.ts +86 -0
  189. package/templates/admin-shell/layouts/modules/shared/logo.ts +42 -0
  190. package/templates/admin-shell/layouts/modules/theme-drawer/ThemeDrawer.tsx +68 -0
  191. package/templates/admin-shell/layouts/modules/theme-drawer/components/AnimatedCollapse.tsx +36 -0
  192. package/templates/admin-shell/layouts/modules/theme-drawer/components/AnimatedItem.tsx +35 -0
  193. package/templates/admin-shell/layouts/modules/theme-drawer/components/LayoutModeCard.tsx +110 -0
  194. package/templates/admin-shell/layouts/modules/theme-drawer/components/SettingItem.tsx +31 -0
  195. package/templates/admin-shell/layouts/modules/theme-drawer/modules/ConfigOperation.tsx +53 -0
  196. package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/CustomPicker.tsx +105 -0
  197. package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/ThemeColor.tsx +58 -0
  198. package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/ThemeSchema.tsx +42 -0
  199. package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/ThemeToken.tsx +44 -0
  200. package/templates/admin-shell/layouts/modules/theme-drawer/modules/appearance/index.tsx +23 -0
  201. package/templates/admin-shell/layouts/modules/theme-drawer/modules/general/GlobalSettings.tsx +57 -0
  202. package/templates/admin-shell/layouts/modules/theme-drawer/modules/general/ThemeGeneral.tsx +20 -0
  203. package/templates/admin-shell/layouts/modules/theme-drawer/modules/general/WatermarkSettings.tsx +103 -0
  204. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/ContentSettings.tsx +100 -0
  205. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/FooterSettings.tsx +71 -0
  206. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/HeaderSettings.tsx +63 -0
  207. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/LayoutMode.tsx +73 -0
  208. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/SiderSettings.tsx +124 -0
  209. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/TabSettings.tsx +95 -0
  210. package/templates/admin-shell/layouts/modules/theme-drawer/modules/layout/ThemeLayout.tsx +32 -0
  211. package/templates/admin-shell/layouts/modules/theme-drawer/modules/preset/ThemePreset.tsx +132 -0
  212. package/templates/admin-shell/layouts/options.tsx +79 -0
  213. package/templates/admin-shell/layouts/setup.ts +102 -0
  214. package/templates/admin-shell/layouts/state/AdminEffect.tsx +56 -0
  215. package/templates/admin-shell/layouts/state/AdminTabEffect.tsx +28 -0
  216. package/templates/admin-shell/layouts/state/index.ts +3 -0
  217. package/templates/admin-shell/layouts/state/menus/MenuToggler.tsx +53 -0
  218. package/templates/admin-shell/layouts/state/menus/use-admin-menu-badges.ts +46 -0
  219. package/templates/admin-shell/layouts/state/menus/use-admin-menus.tsx +164 -0
  220. package/templates/admin-shell/layouts/state/tabs/index.ts +1 -0
  221. package/templates/admin-shell/layouts/state/tabs/shared.tsx +148 -0
  222. package/templates/admin-shell/layouts/state/tabs/use-admin-tab.ts +377 -0
  223. package/templates/admin-shell/layouts/state/use-admin-state.ts +118 -0
  224. package/templates/admin-shell/layouts/types/router.d.ts +10 -0
  225. package/templates/admin-shell/layouts/types/storage.ts +18 -0
  226. package/templates/admin-shell/notification/NotificationButton.tsx +91 -0
  227. package/templates/admin-shell/notification/NotificationContext.ts +8 -0
  228. package/templates/admin-shell/notification/NotificationPanel.tsx +194 -0
  229. package/templates/admin-shell/notification/NotificationProvider.tsx +59 -0
  230. package/templates/admin-shell/notification/index.ts +12 -0
  231. package/templates/admin-shell/notification/mock.ts +59 -0
  232. package/templates/admin-shell/notification/notification-store.ts +438 -0
  233. package/templates/admin-shell/notification/notification.css +60 -0
  234. package/templates/admin-shell/notification/types.ts +104 -0
  235. package/templates/admin-shell/notification/use-notification.ts +51 -0
  236. package/templates/admin-shell/notification/useNotificationContext.ts +14 -0
  237. package/templates/admin-shell/runtime/app-update.ts +156 -0
  238. package/templates/admin-shell/runtime/dayjs.ts +20 -0
  239. package/templates/admin-shell/runtime/iconify.ts +17 -0
  240. package/templates/admin-shell/runtime/index.ts +10 -0
  241. package/templates/admin-shell/runtime/nprogress.ts +25 -0
  242. package/templates/admin-shell/runtime/plugins.ts +62 -0
  243. package/templates/admin-shell/styles/global.css +54 -0
  244. package/templates/admin-shell/styles/nprogress.css +85 -0
  245. package/templates/admin-shell/styles/reset.css +378 -0
  246. package/templates/admin-shell/theme/antd/AntdProvider.tsx +106 -0
  247. package/templates/admin-shell/theme/antd/index.ts +23 -0
  248. package/templates/admin-shell/theme/antd/shared.ts +80 -0
  249. package/templates/admin-shell/theme/antd/ui.ts +250 -0
  250. package/templates/admin-shell/theme/antd-algorithm/algorithm/dark/colors.ts +99 -0
  251. package/templates/admin-shell/theme/antd-algorithm/algorithm/dark/index.ts +87 -0
  252. package/templates/admin-shell/theme/antd-algorithm/algorithm/default/colors.ts +91 -0
  253. package/templates/admin-shell/theme/antd-algorithm/algorithm/default/index.ts +77 -0
  254. package/templates/admin-shell/theme/antd-algorithm/index.ts +80 -0
  255. package/templates/admin-shell/theme/antd-algorithm/seed/index.ts +41 -0
  256. package/templates/admin-shell/theme/antd-algorithm/shared/colorAlgorithm.ts +10 -0
  257. package/templates/admin-shell/theme/antd-algorithm/shared/genColorMapToken.ts +165 -0
  258. package/templates/admin-shell/theme/antd-algorithm/shared/genCommonMapToken.ts +23 -0
  259. package/templates/admin-shell/theme/antd-algorithm/shared/genControlHeight.ts +14 -0
  260. package/templates/admin-shell/theme/antd-algorithm/shared/genFontMapToken.ts +274 -0
  261. package/templates/admin-shell/theme/antd-algorithm/shared/genRadiusMapToken.ts +139 -0
  262. package/templates/admin-shell/theme/antd-algorithm/shared/genSizeMapToken.ts +114 -0
  263. package/templates/admin-shell/theme/antd-algorithm/types/index.ts +20 -0
  264. package/templates/admin-shell/theme/components/ThemeEffect.tsx +55 -0
  265. package/templates/admin-shell/theme/components/ThemeSchemaSegmented.tsx +27 -0
  266. package/templates/admin-shell/theme/components/ThemeSchemaSwitch.tsx +77 -0
  267. package/templates/admin-shell/theme/components/shared.ts +5 -0
  268. package/templates/admin-shell/theme/config/default.ts +108 -0
  269. package/templates/admin-shell/theme/config/index.ts +1 -0
  270. package/templates/admin-shell/theme/hooks/index.ts +2 -0
  271. package/templates/admin-shell/theme/hooks/use-theme.ts +244 -0
  272. package/templates/admin-shell/theme/index.ts +78 -0
  273. package/templates/admin-shell/theme/presets/azir.json +39 -0
  274. package/templates/admin-shell/theme/presets/compact.json +38 -0
  275. package/templates/admin-shell/theme/presets/dark.json +93 -0
  276. package/templates/admin-shell/theme/presets/default.json +95 -0
  277. package/templates/admin-shell/theme/presets/index.ts +29 -0
  278. package/templates/admin-shell/theme/presets/shadcn.json +99 -0
  279. package/templates/admin-shell/theme/setup.ts +115 -0
  280. package/templates/admin-shell/theme/types/index.ts +27 -0
  281. package/templates/admin-shell/theme/types/theme.d.ts +316 -0
  282. package/templates/admin-shell/theme/utils/dark-mode.ts +46 -0
  283. package/templates/admin-shell/theme/utils/filters.ts +20 -0
  284. package/templates/admin-shell/theme/utils/index.ts +3 -0
  285. package/templates/admin-shell/theme/utils/settings.ts +43 -0
  286. package/templates/admin-shell/types/api/auth.d.ts +148 -0
  287. package/templates/admin-shell/types/api/common.d.ts +54 -0
  288. package/templates/admin-shell/types/api/route.d.ts +104 -0
  289. package/templates/admin-shell/types/api/service.d.ts +51 -0
  290. package/templates/admin-shell/types/api/system-manage.d.ts +160 -0
  291. package/templates/admin-shell/types/app/common.d.ts +31 -0
  292. package/templates/admin-shell/types/app/global.d.ts +71 -0
  293. package/templates/admin-shell/types/app/menu.d.ts +57 -0
  294. package/templates/admin-shell/types/app/router.d.ts +201 -0
  295. package/templates/admin-shell/types/app/storage.d.ts +10 -0
  296. package/templates/admin-shell/types/app/union-key.d.ts +156 -0
  297. package/templates/admin-shell/types/locales/i18n.d.ts +135 -0
  298. package/templates/admin-shell/ui/antd/components/AppTree.tsx +62 -0
  299. package/templates/admin-shell/ui/antd/components/BeyondHiding.tsx +42 -0
  300. package/templates/admin-shell/ui/antd/components/ButtonIcon.tsx +123 -0
  301. package/templates/admin-shell/ui/antd/components/ButtonLink.tsx +30 -0
  302. package/templates/admin-shell/ui/antd/components/ErrorBoundary.tsx +45 -0
  303. package/templates/admin-shell/ui/antd/components/ExceptionBase.tsx +69 -0
  304. package/templates/admin-shell/ui/antd/components/FullScreen.tsx +33 -0
  305. package/templates/admin-shell/ui/antd/components/PinToggler.tsx +35 -0
  306. package/templates/admin-shell/ui/antd/components/ReloadButton.tsx +20 -0
  307. package/templates/admin-shell/ui/antd/components/index.ts +12 -0
  308. package/templates/admin-shell/ui/antd/components/styles/button-icon-animations.css +246 -0
  309. package/templates/admin-shell/ui/antd/index.ts +1 -0
  310. package/templates/admin-shell/ui/antd/styles.d.ts +1 -0
  311. package/templates/admin-shell/ui/compose/animate-feature.ts +5 -0
  312. package/templates/admin-shell/ui/compose/components/BetterScroll.tsx +51 -0
  313. package/templates/admin-shell/ui/compose/components/DarkModeContainer.tsx +22 -0
  314. package/templates/admin-shell/ui/compose/components/FlipText.tsx +41 -0
  315. package/templates/admin-shell/ui/compose/components/I18nLabel.tsx +18 -0
  316. package/templates/admin-shell/ui/compose/components/LazyAnimate.tsx +10 -0
  317. package/templates/admin-shell/ui/compose/components/LookForward.tsx +24 -0
  318. package/templates/admin-shell/ui/compose/components/NumberTicker.tsx +105 -0
  319. package/templates/admin-shell/ui/compose/components/Portal.tsx +74 -0
  320. package/templates/admin-shell/ui/compose/components/SvgIcon.tsx +39 -0
  321. package/templates/admin-shell/ui/compose/components/TypingAnimation.tsx +83 -0
  322. package/templates/admin-shell/ui/compose/components/WaveBg.tsx +56 -0
  323. package/templates/admin-shell/ui/compose/components/index.ts +11 -0
  324. package/templates/admin-shell/ui/compose/index.ts +2 -0
  325. package/templates/admin-shell/ui/compose/table/DragContent.tsx +239 -0
  326. package/templates/admin-shell/ui/compose/table/TableHeaderOperation.tsx +210 -0
  327. package/templates/admin-shell/ui/compose/table/hooks.ts +196 -0
  328. package/templates/admin-shell/ui/compose/table/index.ts +16 -0
  329. package/templates/admin-shell/ui/compose/table/types.ts +244 -0
  330. package/templates/admin-shell/ui/compose/table/use-table-operate.ts +136 -0
  331. package/templates/admin-shell/ui/compose/table/use-table-scroll.ts +49 -0
  332. package/templates/admin-shell/ui/compose/table/use-table.ts +303 -0
  333. package/templates/admin.meta.json +756 -0
@@ -0,0 +1,125 @@
1
+ import type { AdminDevtoolsConfig } from '@skyroc/web-admin-devtools';
2
+ import { defaultThemeSettings } from '@shell/theme';
3
+ import type { NProgress } from 'nprogress';
4
+
5
+ import { menuCategoryKeys } from './features/menus/menu-category';
6
+ import { localStg } from './utils/storage';
7
+
8
+ // ============================================================================
9
+ // Re-export antd UI helpers from admin-theme package
10
+ // (保持 auto-import 兼容,所有 showXxx 函数可继续作为全局变量使用)
11
+ // ============================================================================
12
+ export {
13
+ destroyMessage,
14
+ destroyNotification,
15
+ showConfirmModal,
16
+ showErrorMessage,
17
+ showErrorModal,
18
+ showErrorNotification,
19
+ showInfoMessage,
20
+ showInfoModal,
21
+ showInfoNotification,
22
+ showLoadingMessage,
23
+ showMessage,
24
+ showModal,
25
+ showNotification,
26
+ showSuccessMessage,
27
+ showSuccessModal,
28
+ showSuccessNotification,
29
+ showWarningMessage,
30
+ showWarningModal,
31
+ showWarningNotification
32
+ } from '@shell/theme';
33
+
34
+ // ============================================================================
35
+ // NProgress
36
+ // ============================================================================
37
+
38
+ const _nprogress = { instance: null as NProgress | null };
39
+
40
+ export function initNProgress(nprogress: NProgress) {
41
+ _nprogress.instance = nprogress;
42
+ }
43
+
44
+ // ============================================================================
45
+ // Global Config
46
+ // ============================================================================
47
+
48
+ function createConfig() {
49
+ return {
50
+ // ======System Config======
51
+ /** - 是否自动检测更新 */
52
+ automaticallyDetectUpdate: true,
53
+
54
+ /** - 是否开发环境 */
55
+ isDev: import.meta.env.DEV,
56
+ /** - 开发工具配置 */
57
+ devtools: {
58
+ jotai: {
59
+ name: import.meta.env.VITE_APP_TITLE,
60
+ panel: true,
61
+ position: 'bottom-left',
62
+ timeline: true,
63
+ triggerOffset: {
64
+ left: defaultThemeSettings.sider.width + 8
65
+ }
66
+ },
67
+ position: 'bottom-right',
68
+ query: true,
69
+ router: true
70
+ } satisfies AdminDevtoolsConfig,
71
+ /** - 生成菜单的分类 key,来源于 setupAdminLayouts 使用的 menuCategories。 */
72
+ genMenuLayouts: menuCategoryKeys,
73
+ /** - 默认首页 */
74
+ defaultHome: import.meta.env.VITE_ROUTE_HOME,
75
+
76
+ localIconPrefix: import.meta.env.VITE_ICON_LOCAL_PREFIX,
77
+
78
+ defaultIcon: import.meta.env.VITE_MENU_ICON,
79
+
80
+ routeMode: import.meta.env.VITE_AUTH_ROUTE_MODE,
81
+
82
+ /** - Nprogress 实例 */
83
+ get nprogress(): NProgress {
84
+ if (!_nprogress.instance) {
85
+ console.error('nprogress is not initialized, please call initNProgress function first');
86
+ throw new Error('nprogress is not initialized');
87
+ }
88
+ return _nprogress.instance;
89
+ },
90
+
91
+ /// //////////////////////////////////////////////////////////////////////////////
92
+ // ======Theme Config======
93
+ /// //////////////////////////////////////////////////////////////////////////////
94
+ /** - 默认主题配置 */
95
+ get defaultThemeColor(): string {
96
+ return localStg.get('themeColor') || defaultThemeSettings.themeColor;
97
+ },
98
+ get defaultDarkMode(): boolean {
99
+ return localStg.get('darkMode') ?? defaultThemeSettings.themeScheme === 'dark';
100
+ },
101
+
102
+ /// //////////////////////////////////////////////////////////////////////////////
103
+ // ======Lang Config======
104
+ /// //////////////////////////////////////////////////////////////////////////////
105
+ /** - 默认语言配置 */
106
+ get defaultLang(): I18n.LangType {
107
+ return localStg.get('lang') || 'zh-CN';
108
+ },
109
+ /** - 默认语言选项 */
110
+ get defaultLangOptions(): I18n.LangOption[] {
111
+ return [
112
+ {
113
+ key: 'zh-CN',
114
+ label: '中文'
115
+ },
116
+ {
117
+ key: 'en-US',
118
+ label: 'English'
119
+ }
120
+ ];
121
+ }
122
+ } as const;
123
+ }
124
+
125
+ export const globalConfig = createConfig();
@@ -0,0 +1,21 @@
1
+ import { useLang } from '@shell/i18n';
2
+ import { AntdProvider } from '@shell/theme';
3
+ import type { PropsWithChildren } from 'react';
4
+
5
+ import { antdLocales } from '@/locales/antd';
6
+ import { useUserInfoQuery } from '@/service/api';
7
+
8
+ const AppAntdProvider = (props: PropsWithChildren) => {
9
+ const { children } = props;
10
+
11
+ const { locale } = useLang();
12
+ const { data: userInfo } = useUserInfoQuery();
13
+
14
+ return (
15
+ <AntdProvider locale={antdLocales[locale]} userName={userInfo?.userName}>
16
+ {children}
17
+ </AntdProvider>
18
+ );
19
+ };
20
+
21
+ export default AppAntdProvider;
@@ -0,0 +1,76 @@
1
+ import { showConfirmModal } from '@shell/theme';
2
+ import { ButtonIcon } from '@shell/ui/antd';
3
+ import { SvgIcon } from '@shell/ui/compose';
4
+ import { useLocation, useNavigate } from '@tanstack/react-router';
5
+ import { Button as AButton, Dropdown as ADropdown, type MenuProps } from 'antd';
6
+ import { memo } from 'react';
7
+ import { useTranslation } from 'react-i18next';
8
+
9
+ import { useUserInfoQuery } from '@/service/api';
10
+
11
+ import { useAuth } from '../use-auth';
12
+
13
+ const UserAvatar = () => {
14
+ const { isLoggedIn } = useAuth();
15
+
16
+ const { data: userInfo } = useUserInfoQuery();
17
+
18
+ const { t } = useTranslation();
19
+
20
+ const navigate = useNavigate();
21
+
22
+ const location = useLocation();
23
+
24
+ const fullPath = location.href;
25
+
26
+ function logout() {
27
+ showConfirmModal({
28
+ cancelText: t('common.cancel'),
29
+ content: t('common.logoutConfirm'),
30
+ okText: t('common.confirm'),
31
+ onOk: () => {
32
+ navigate({ to: '/login-out', search: { redirect: fullPath } });
33
+ },
34
+ title: t('common.tip')
35
+ });
36
+ }
37
+
38
+ function onClick({ key }: { key: string }) {
39
+ if (key === 'logout') {
40
+ logout();
41
+ }
42
+ }
43
+
44
+ function loginOrRegister() {
45
+ navigate({ to: '/login' });
46
+ }
47
+
48
+ const items: MenuProps['items'] = [
49
+ {
50
+ key: 'logout',
51
+ label: (
52
+ <div className="flex-center gap-8px">
53
+ <SvgIcon className="text-lg" icon="ph:sign-out" />
54
+ {t('common.logout')}
55
+ </div>
56
+ )
57
+ }
58
+ ];
59
+
60
+ if (isLoggedIn) {
61
+ return (
62
+ <ADropdown menu={{ items, onClick }} placement="bottomRight" trigger={['click']}>
63
+ <div>
64
+ <ButtonIcon className="px-12px">
65
+ <SvgIcon className="text-2xl" icon="ph:user-circle" />
66
+ <span className="text-md font-medium">{userInfo?.userName}</span>
67
+ </ButtonIcon>
68
+ </div>
69
+ </ADropdown>
70
+ );
71
+ }
72
+
73
+ return <AButton onClick={loginOrRegister}>{t('page.login.common.loginOrRegister')}</AButton>;
74
+ };
75
+
76
+ export default memo(UserAvatar);
@@ -0,0 +1,83 @@
1
+ import { REG_CODE_SIX, REG_EMAIL, REG_PHONE, REG_PWD, REG_USER_NAME } from '@skyroc/utils';
2
+ import type { FormInstance, FormRule } from 'antd';
3
+
4
+ function createRequiredRule(message: string): FormRule {
5
+ return {
6
+ message,
7
+ required: true
8
+ };
9
+ }
10
+
11
+ export function useAuthFormRules() {
12
+ const { t } = useTranslation();
13
+
14
+ const patternRules = {
15
+ code: {
16
+ message: t('form.code.invalid'),
17
+ pattern: REG_CODE_SIX,
18
+ validateTrigger: 'onChange'
19
+ },
20
+ email: {
21
+ message: t('form.email.invalid'),
22
+ pattern: REG_EMAIL,
23
+ validateTrigger: 'onChange'
24
+ },
25
+ phone: {
26
+ message: t('form.phone.invalid'),
27
+ pattern: REG_PHONE,
28
+ validateTrigger: 'onChange'
29
+ },
30
+ pwd: {
31
+ message: t('form.pwd.invalid'),
32
+ pattern: REG_PWD,
33
+ validateTrigger: 'onChange'
34
+ },
35
+ userName: {
36
+ message: t('form.userName.invalid'),
37
+ pattern: REG_USER_NAME,
38
+ validateTrigger: 'onChange'
39
+ }
40
+ } satisfies Record<string, FormRule>;
41
+
42
+ const formRules = {
43
+ code: [createRequiredRule(t('form.code.required')), patternRules.code],
44
+ email: [createRequiredRule(t('form.email.required')), patternRules.email],
45
+ phone: [createRequiredRule(t('form.phone.required')), patternRules.phone],
46
+ pwd: [createRequiredRule(t('form.pwd.required')), patternRules.pwd],
47
+ userName: [createRequiredRule(t('form.userName.required')), patternRules.userName]
48
+ } satisfies Record<string, FormRule[]>;
49
+
50
+ /** The default required rule */
51
+ const defaultRequiredRule = createRequiredRule(t('form.required'));
52
+
53
+ /** Create a rule for confirming the password */
54
+ function createConfirmPwdRule(form: FormInstance) {
55
+ const confirmPwdRule: FormRule[] = [
56
+ { message: t('form.confirmPwd.required'), required: true },
57
+ {
58
+ message: t('form.confirmPwd.invalid'),
59
+ validateTrigger: 'onChange',
60
+ validator: (rule, value) => {
61
+ const pwd = form.getFieldValue('password');
62
+ const confirmPwd = typeof value === 'string' ? value : '';
63
+
64
+ if (confirmPwd.trim() !== '' && confirmPwd !== pwd) {
65
+ return Promise.reject(rule.message);
66
+ }
67
+
68
+ return Promise.resolve();
69
+ }
70
+ }
71
+ ];
72
+
73
+ return confirmPwdRule;
74
+ }
75
+
76
+ return {
77
+ createConfirmPwdRule,
78
+ createRequiredRule,
79
+ defaultRequiredRule,
80
+ formRules,
81
+ patternRules
82
+ };
83
+ }
@@ -0,0 +1,96 @@
1
+ import { setAtomValue } from '@skyroc/core-state';
2
+ import { cacheTabs, useMenus } from '@shell/layouts';
3
+ import { atom, useAtom } from 'jotai';
4
+
5
+ import { useUserInfoQuery } from '@/service/api';
6
+ import { queryClient } from '@/service/queryClient';
7
+ import { localStg } from '@/utils/storage';
8
+
9
+ const initToken = getToken();
10
+
11
+ interface AuthState {
12
+ /** 是否完成首轮认证初始化。 */
13
+ initialized: boolean;
14
+ /** 当前 access token,空值表示未登录。 */
15
+ token: string | null;
16
+ }
17
+
18
+ const initState: AuthState = {
19
+ token: initToken,
20
+ initialized: false
21
+ };
22
+
23
+ const authAtom = atom(initState);
24
+
25
+ export function getToken() {
26
+ return localStg.get('token');
27
+ }
28
+
29
+ export function clearAuthStorage() {
30
+ localStg.remove('token');
31
+ localStg.remove('refreshToken');
32
+ }
33
+
34
+ export function setAuth(data: Api.Auth.LoginToken) {
35
+ setAtomValue(authAtom, prev => ({ ...prev, token: data.token }));
36
+
37
+ localStg.set('token', data.token);
38
+ localStg.set('refreshToken', data.refreshToken);
39
+ }
40
+
41
+ export function useAuth() {
42
+ const [state, setState] = useAtom(authAtom);
43
+ const { clearMenus, getHomeRoute, home, initMenus } = useMenus();
44
+ const isLoggedIn = Boolean(state.token);
45
+ const { data: userInfo, refetch } = useUserInfoQuery();
46
+
47
+ async function initAuth() {
48
+ try {
49
+ const { data } = await refetch();
50
+
51
+ if (!data) {
52
+ return null;
53
+ }
54
+
55
+ await initMenus(data);
56
+
57
+ setState(prev => ({ ...prev, initialized: true }));
58
+
59
+ return data;
60
+ } catch {
61
+ return null;
62
+ }
63
+ }
64
+
65
+ /**
66
+ * 退出登录:清掉本地这一整套登录状态。
67
+ *
68
+ * 声明成 async 是为了给"先请求后端作废令牌、再清本地"留出位置——两件事的顺序不能反, 清本地是同步的,先清了请求就带不上 Authorization。这个 app 的后端没有登出接口, 所以眼下只有清理这一半。
69
+ */
70
+ async function logout() {
71
+ if (userInfo) {
72
+ localStg.set('lastLoginUserId', userInfo.userId);
73
+ }
74
+
75
+ queryClient.clear();
76
+
77
+ setState(prev => ({ ...prev, token: '' }));
78
+
79
+ clearAuthStorage();
80
+ clearMenus();
81
+ cacheTabs();
82
+ }
83
+
84
+ return {
85
+ token: state.token,
86
+ userInfo: userInfo || undefined,
87
+ isLoggedIn,
88
+ logout,
89
+ getHomeRoute,
90
+ homeRoute: home,
91
+ initMenus,
92
+ initAuth,
93
+ isAuthInitialized: state.initialized,
94
+ setAuth
95
+ };
96
+ }
@@ -0,0 +1,72 @@
1
+ import { useLoading } from '@skyroc/hooks';
2
+ import { useNavigate, useRouter, useSearch } from '@tanstack/react-router';
3
+
4
+ import { useLoginMutation } from '@/service/api';
5
+ import { localStg } from '@/utils/storage';
6
+
7
+ import { useAuth } from './use-auth';
8
+
9
+ export function useInitLogin() {
10
+ const { endLoading, loading, startLoading } = useLoading();
11
+
12
+ const search = useSearch({ from: '/(auth)/login/' });
13
+
14
+ const { t } = useTranslation();
15
+
16
+ const { initAuth, setAuth } = useAuth();
17
+
18
+ const navigate = useNavigate();
19
+ const router = useRouter();
20
+
21
+ const { mutate: toLogin } = useLoginMutation();
22
+
23
+ async function login(params: Api.Auth.LoginParams, redirect = true) {
24
+ if (loading) return;
25
+
26
+ startLoading();
27
+
28
+ toLogin(params, {
29
+ onError: () => {
30
+ endLoading();
31
+ },
32
+ onSuccess: async data => {
33
+ setAuth(data);
34
+
35
+ const info = await initAuth();
36
+
37
+ if (info) {
38
+ await router.invalidate();
39
+
40
+ const lastLoginUserId = localStg.get('lastLoginUserId');
41
+
42
+ let needRedirect = redirect;
43
+
44
+ if (!lastLoginUserId || lastLoginUserId !== info.userId) {
45
+ needRedirect = false;
46
+
47
+ localStg.remove('globalTabs');
48
+ localStg.remove('lastLoginUserId');
49
+ }
50
+
51
+ if (needRedirect) {
52
+ await navigate({ to: search.redirect || '/', replace: true });
53
+ } else {
54
+ await navigate({ to: '/', replace: true });
55
+ }
56
+
57
+ showSuccessNotification({
58
+ description: t('page.login.common.welcomeBack', { userName: info.userName }),
59
+ title: t('page.login.common.loginSuccess')
60
+ });
61
+ } else {
62
+ endLoading();
63
+ }
64
+ }
65
+ });
66
+ }
67
+
68
+ return {
69
+ login,
70
+ loading
71
+ };
72
+ }
@@ -0,0 +1,15 @@
1
+ import { LangEffect } from '@shell/i18n';
2
+ import { ThemeEffect } from '@shell/theme';
3
+
4
+ import { syncLocales } from '@/locales/sync';
5
+
6
+ const GlobalEffect = () => {
7
+ return (
8
+ <>
9
+ <ThemeEffect />
10
+ <LangEffect onLocaleChange={syncLocales} />
11
+ </>
12
+ );
13
+ };
14
+
15
+ export default GlobalEffect;
@@ -0,0 +1,10 @@
1
+ import { createAdminDynamicRouteLoader } from '@shell/layouts';
2
+
3
+ import { routeTree } from '@/features/router/routeTree.gen';
4
+ import { queryMenusOptions } from '@/service/api/route/hooks';
5
+ import { queryClient } from '@/service/queryClient';
6
+
7
+ export const loadAdminDynamicRoutes = createAdminDynamicRouteLoader({
8
+ routeTree,
9
+ loadBackendRoutes: () => queryClient.ensureQueryData(queryMenusOptions())
10
+ });
@@ -0,0 +1,3 @@
1
+ export const menuExtras = {};
2
+
3
+ export type ExtraKey = keyof typeof menuExtras;
@@ -0,0 +1,14 @@
1
+ import type { AdminLayoutMenuCategory } from '@shell/layouts';
2
+
3
+ export const menuCategories = {
4
+ admin: {
5
+ key: 'admin',
6
+ layout: '/(admin)'
7
+ }
8
+ } as const satisfies Record<string, AdminLayoutMenuCategory>;
9
+
10
+ type MenuCategories = typeof menuCategories;
11
+
12
+ export type MenuCategoryKey = keyof MenuCategories;
13
+
14
+ export const menuCategoryKeys = Object.keys(menuCategories) as MenuCategoryKey[];
@@ -0,0 +1,5 @@
1
+ import type { MenuNodeCallback } from '@shell/layouts';
2
+
3
+ export const menuNodeCallback: MenuNodeCallback = () => {
4
+ return [];
5
+ };
@@ -0,0 +1,18 @@
1
+ import { RouterProvider as TanStackRouterProvider } from '@tanstack/react-router';
2
+
3
+ import { useAuth } from '../auth/use-auth';
4
+
5
+ import { router } from '.';
6
+
7
+ const RouterProvider = memo(() => {
8
+ const { getHomeRoute, homeRoute, initAuth, isAuthInitialized, isLoggedIn, logout, userInfo } = useAuth();
9
+
10
+ return (
11
+ <TanStackRouterProvider
12
+ context={{ initAuth, isAuthInitialized, isLoggedIn, userInfo, logout, getHomeRoute, homeRoute }}
13
+ router={router}
14
+ />
15
+ );
16
+ });
17
+
18
+ export default RouterProvider;
@@ -0,0 +1,97 @@
1
+ import { hasAuthorizedRoutePath, hasMatchedRoutePermission, normalizePath } from '@shell/layouts';
2
+ import { redirect } from '@tanstack/react-router';
3
+ import type { MakeRouteMatchUnion, ParsedLocation } from '@tanstack/react-router';
4
+
5
+ export interface AdminRouteGuardOptions {
6
+ context: Router.RouterContext;
7
+ location: ParsedLocation;
8
+ matches: MakeRouteMatchUnion[];
9
+ preload?: boolean;
10
+ }
11
+
12
+ function getLoginRedirectSearch(location: ParsedLocation, context: Router.RouterContext) {
13
+ const homeRoute = normalizePath(context.homeRoute || context.getHomeRoute());
14
+ const currentPath = normalizePath(location.pathname);
15
+
16
+ if (currentPath === homeRoute && !location.searchStr) {
17
+ return;
18
+ }
19
+
20
+ return { redirect: location.href };
21
+ }
22
+
23
+ function getCurrentRoutePath(matches: MakeRouteMatchUnion[]) {
24
+ const currentMatch = matches.at(-1);
25
+
26
+ if (!currentMatch) {
27
+ return null;
28
+ }
29
+
30
+ return normalizePath(currentMatch.fullPath);
31
+ }
32
+
33
+ function getMatchedRouteHref(matches: MakeRouteMatchUnion[]) {
34
+ return matches.findLast(match => match.staticData?.href)?.staticData?.href || null;
35
+ }
36
+
37
+ function getRouteSwitchFallbackPath(context: Router.RouterContext, currentRoutePath: string | null) {
38
+ const homeRoute = normalizePath(context.homeRoute || context.getHomeRoute());
39
+
40
+ if (currentRoutePath !== homeRoute) {
41
+ return homeRoute;
42
+ }
43
+
44
+ return '/404';
45
+ }
46
+
47
+ async function resolveUserInfo(context: Router.RouterContext) {
48
+ if (context.isAuthInitialized && context.userInfo) {
49
+ return context.userInfo;
50
+ }
51
+
52
+ return context.initAuth();
53
+ }
54
+
55
+ async function guardResolvedUserInfo(
56
+ options: AdminRouteGuardOptions,
57
+ userInfo: Api.Auth.UserInfo | null
58
+ ) {
59
+ const { context, location, matches, preload } = options;
60
+
61
+ if (!userInfo) {
62
+ // 等登出走完再跳:/login 的守卫会重新读 token,没清完就跳过去会被当成还登录着。
63
+ await context.logout();
64
+
65
+ throw redirect({ to: '/login', search: getLoginRedirectSearch(location, context) });
66
+ }
67
+
68
+ if (import.meta.env.VITE_AUTH_ROUTE_MODE === 'static' && !hasMatchedRoutePermission(matches, userInfo)) {
69
+ throw redirect({ to: '/403' });
70
+ }
71
+
72
+ const currentRoutePath = getCurrentRoutePath(matches);
73
+
74
+ if (currentRoutePath && !hasAuthorizedRoutePath(currentRoutePath, userInfo)) {
75
+ throw redirect({ to: '/403' });
76
+ }
77
+
78
+ const href = getMatchedRouteHref(matches);
79
+
80
+ if (href && !preload) {
81
+ window.open(href, '_blank', 'noopener,noreferrer');
82
+
83
+ throw redirect({ to: getRouteSwitchFallbackPath(context, currentRoutePath), replace: true });
84
+ }
85
+ }
86
+
87
+ export async function guardAdminRoute(options: AdminRouteGuardOptions) {
88
+ const { context, location } = options;
89
+
90
+ if (!context.isLoggedIn) {
91
+ throw redirect({ to: '/login', search: getLoginRedirectSearch(location, context) });
92
+ }
93
+
94
+ const userInfo = await resolveUserInfo(context);
95
+
96
+ await guardResolvedUserInfo(options, userInfo);
97
+ }