feat: 更新依赖版本,添加PWA更新组件,优化Sidebar组件,增加footer支持

This commit is contained in:
xiongxiao
2026-03-22 13:54:30 +08:00
committed by cnb
parent 518a3f2864
commit dd100fd7ef
9 changed files with 175 additions and 37 deletions

View File

@@ -1,10 +1,3 @@
import { QueryRouterServer } from '@kevisual/router/browser'
import { QueryRouterServer } from "@kevisual/router/browser"
import { useContextKey } from '@kevisual/context'
export const app = useContextKey('app', new QueryRouterServer())
// import '@kevisual/cnb-ai'
const url = 'https://kevisual.cn/root/cnb-ai/dist/app.js'
setTimeout(() => {
import(/* @vite-ignore */url)
}, 2000)
export const app = useContextKey('app', new QueryRouterServer())

View File

@@ -1 +1,8 @@
export * from './app.ts'
export * from './app.ts'
// import '@kevisual/cnb-ai'
const url = 'https://kevisual.cn/root/cnb-ai/dist/app.js'
setTimeout(() => {
import(/* @vite-ignore */url)
}, 2000)

View File

@@ -0,0 +1,60 @@
import { useState } from 'react';
import { useRegisterSW } from 'virtual:pwa-register/react';
import { Button } from '@/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from '@/components/ui/card';
function PWAUpdate() {
const {
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onNeedRefresh() {
setNeedRefresh(true);
},
});
const [isLoading, setIsLoading] = useState(false);
const handleUpdate = async () => {
setIsLoading(true);
await updateServiceWorker(true);
setIsLoading(false);
};
const handleDismiss = () => {
setNeedRefresh(false);
};
if (!needRefresh) {
return null;
}
return (
<div className="fixed bottom-4 right-4 z-50">
<Card className="w-80 shadow-lg">
<CardHeader className="pb-3">
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="pt-0" />
<CardFooter className="gap-2">
<Button variant="outline" size="sm" onClick={handleDismiss}>
</Button>
<Button size="sm" onClick={handleUpdate} disabled={isLoading}>
{isLoading ? '更新中...' : '立即更新'}
</Button>
</CardFooter>
</Card>
</div>
);
}
export default PWAUpdate;

View File

@@ -32,6 +32,7 @@ export interface SidebarProps {
children?: React.ReactNode
logo?: React.ReactNode
title?: React.ReactNode
footer?: React.ReactNode
defaultCollapsed?: boolean
defaultWidth?: number
minWidth?: number
@@ -44,6 +45,7 @@ export function Sidebar({
children,
logo,
title,
footer,
defaultCollapsed = false,
defaultWidth = 208,
minWidth = 120,
@@ -172,7 +174,6 @@ export function Sidebar({
</li>
)
}
return (
<>
<div className={cn('flex h-full', className)}>
@@ -194,7 +195,7 @@ export function Sidebar({
>
<aside
className={cn(
'border-r bg-white flex-shrink-0 flex flex-col'
'h-full border-r bg-white flex-shrink-0 flex flex-col'
)}
style={{ width: sidebarWidth }}
>
@@ -223,11 +224,18 @@ export function Sidebar({
{items.map((item) => renderNavItem(item))}
</ul>
</nav>
{/* Footer */}
{footer && (
<div className="border-t flex-shrink-0">
{footer}
</div>
)}
</aside>
</Resizable>
) : (
// 收起状态
<aside className="w-14 border-r bg-white flex-shrink-0 flex flex-col">
<aside className="h-full w-14 border-r bg-white flex-shrink-0 flex flex-col">
{/* Logo 区域 */}
<div className="h-12 flex items-center justify-center border-b px-2">
<div className="group relative flex-shrink-0">
@@ -248,6 +256,13 @@ export function Sidebar({
{items.map((item) => renderNavItem(item))}
</ul>
</nav>
{/* Footer */}
{footer && (
<div className="border-t flex-shrink-0">
{footer}
</div>
)}
</aside>
)}

View File

@@ -90,13 +90,10 @@ export const useLayoutStore = create<LayoutStore>((set, get) => ({
setIsAdmin: (isAdmin) => set({ isAdmin }),
init: async () => {
await queryLogin.init();
const token = await queryLogin.checkLocalToken();
const token = await queryLogin.checkTokenValid();
if (token) {
set({ me: {} });
try {
// const data = await stackQueryClient.fetchQuery({
// queryKey: authQueryKeys.me,
// }) as UserInfo;
const userInfo = await queryLogin.checkLocalUser();
if (userInfo) {
set({ me: userInfo as UserInfo, isAdmin: userInfo.orgs?.includes?.('admin') || false });

View File

@@ -33,7 +33,17 @@ const navItems: NavItem[] = [
export function SidebarLayout({ children }: { children: React.ReactNode }) {
return (
<Sidebar items={navItems} title='云原生' logo={<Logo className='w-6 h-6' />}>
<Sidebar items={navItems} title='云原生' logo={<Logo className='w-6 h-6' />}
footer={<div className="p-4 border-t text-sm text-gray-500 hover:text-gray-700">
<a
href="https://cnb.cool/kevisual/cnb-center"
target="_blank"
rel="noopener noreferrer"
>
CNB Center
</a>
</div>}
>
{children}
</Sidebar>
)