diff --git a/package.json b/package.json index 382c85f..3a9958e 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,6 @@ "tailwindcss": "^4.2.0", "tw-animate-css": "^1.4.0", "typescript": "^5.9.3", - "vite": "v8.0.0-beta.14" + "vite": "v8.0.0-beta.15" } } \ No newline at end of file diff --git a/src/modules/query.ts b/src/modules/query.ts index 0c773ca..471126a 100644 --- a/src/modules/query.ts +++ b/src/modules/query.ts @@ -1,13 +1,23 @@ -import { Query } from '@kevisual/query'; +import { Query, DataOpts } from '@kevisual/query'; import { QueryLoginBrowser } from '@kevisual/api/query-login' -export const query = new Query({ +import { useContextKey } from '@kevisual/context'; +export const query = useContextKey('query', new Query({ url: '/api/router', -}); +})); +const afterResponse: DataOpts['afterResponse'] = async (response, ctx) => { + if (response.code === 401) { + await queryLogin.logout(); + setTimeout(() => { location.reload() }, 2000); + } + return response; +} +query.after(afterResponse); -export const queryClient = new Query({ +export const queryClient = useContextKey('queryClient', new Query({ url: '/client/router', -}); +})); -export const queryLogin = new QueryLoginBrowser({ +queryClient.after(afterResponse); +export const queryLogin = useContextKey('queryLogin', new QueryLoginBrowser({ query: query -}); \ No newline at end of file +})); \ No newline at end of file diff --git a/src/pages/auth/index.tsx b/src/pages/auth/index.tsx index 041ff38..afa034a 100644 --- a/src/pages/auth/index.tsx +++ b/src/pages/auth/index.tsx @@ -15,7 +15,7 @@ export const AuthProvider = ({ children, mustLogin }: Props) => { useEffect(() => { store.init() }, []) - const loginUrl = '/root/login?redirect=' + encodeURIComponent(window.location.href); + const loginUrl = '/root/login/?redirect=' + encodeURIComponent(window.location.href); if (mustLogin && !store.me) { return (
@@ -27,13 +27,15 @@ export const AuthProvider = ({ children, mustLogin }: Props) => {

需要登录

请先登录以继续访问此页面

- { + window.open(loginUrl, '_self') + }} > 立即登录 - + ) diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 24f345d..bc7e81a 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -1,31 +1,46 @@ -import { Link, Outlet, createRootRoute, useNavigate } from '@tanstack/react-router' +// import { LayoutMain } from '@/modules/layout' +const LayoutMain = null; +import { Link, Outlet, createRootRoute } from '@tanstack/react-router' import { TanStackRouterDevtools } from '@tanstack/react-router-devtools' import { Toaster } from '@/components/ui/sonner' import { AuthProvider } from '@/pages/auth' import { TooltipProvider } from '@/components/ui/tooltip' +import { Home } from 'lucide-react'; export const Route = createRootRoute({ component: RootComponent, }) +const BaseHeader = (props: { main?: React.ComponentType | null }) => { + if (props.main) { + const MainComponent = props.main + return + } + return ( + <> +
+
+ + + +
+
+
+ + ) +} function RootComponent() { return (
- -
- - Home - -
-
- + + -
+
@@ -33,6 +48,5 @@ function RootComponent() {
- ) } \ No newline at end of file