Skip to content

Commit

Permalink
feat: 新增命令菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
besscroft committed Sep 27, 2024
1 parent 972f3fb commit efb7ade
Show file tree
Hide file tree
Showing 13 changed files with 804 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import DashHeader from '~/components/layout/DashHeader'
import { BaseSide } from '~/components/layout/BaseSide'

import { AntdRegistry } from '@ant-design/nextjs-registry'
import Command from '~/components/admin/Command'

export default function AdminLayout({
children,
Expand All @@ -17,6 +18,7 @@ export default function AdminLayout({
<BaseSide/>
</aside>
<main className="flex w-full h-full flex-1 flex-col p-2">
<Command />
<AntdRegistry>{children}</AntdRegistry>
</main>
</div>
Expand Down
8 changes: 4 additions & 4 deletions components/MasonryItem.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use client'

import {
Dialog,
CustomDialog,
DialogContent,
} from '~/components/ui/Dialog'
} from '~/components/ui/CustomDialog'
import { useButtonStore } from '~/app/providers/button-store-Providers'
import { CopyrightType, DataProps, ImageType } from '~/types'
import { Image, Tabs, Tab, Card, CardHeader, CardBody, CardFooter, Button, Chip, Link, Avatar, Tooltip } from '@nextui-org/react'
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function MasonryItem() {
}

return (
<Dialog
<CustomDialog
defaultOpen={false}
open={MasonryView}
onOpenChange={(open: boolean) => {
Expand Down Expand Up @@ -365,6 +365,6 @@ export default function MasonryItem() {
</div>
</div>
</DialogContent>
</Dialog>
</CustomDialog>
)
}
106 changes: 106 additions & 0 deletions components/admin/Command.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
'use client'

import * as React from 'react'
import {
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandSeparator,
} from '~/components/ui/command'
import { useButtonStore } from '~/app/providers/button-store-Providers'
import { Archive, Milestone, Image, Server, ImageUp, MonitorDot, Copyright, Info, SquareAsterisk, ShieldCheck } from 'lucide-react'
import { useRouter } from 'next-nprogress-bar'

export default function Command() {
const router = useRouter()
const { searchOpen, setSearchOpen } = useButtonStore(
(state) => state,
)

return (
<CommandDialog open={searchOpen} onOpenChange={setSearchOpen}>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>没有任何结果.</CommandEmpty>
<CommandGroup heading="主菜单">
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin')
setSearchOpen(false)
}}>
<MonitorDot className="mr-2 h-4 w-4" />
<span>控制台</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/upload')
setSearchOpen(false)
}}>
<ImageUp className="mr-2 h-4 w-4" />
<span>上传</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/list')
setSearchOpen(false)
}}>
<Image className="mr-2 h-4 w-4" />
<span>图片维护</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/tag')
setSearchOpen(false)
}}>
<Milestone className="mr-2 h-4 w-4" />
<span>相册管理</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/copyright')
setSearchOpen(false)
}}>
<Copyright className="mr-2 h-4 w-4" />
<span>版权管理</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/about')
setSearchOpen(false)
}}>
<Info className="mr-2 h-4 w-4" />
<span>关于</span>
</CommandItem>
</CommandGroup>
<CommandSeparator />
<CommandGroup heading="二级菜单">
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/settings/preferences')
setSearchOpen(false)
}}>
<Archive className="mr-2 h-4 w-4" />
<span>首选项</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/settings/password')
setSearchOpen(false)
}}>
<SquareAsterisk className="mr-2 h-4 w-4" />
<span>密码修改</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/settings/storages')
setSearchOpen(false)
}}>
<Server className="mr-2 h-4 w-4" />
<span>存储</span>
</CommandItem>
<CommandItem className="cursor-pointer" onSelect={() => {
router.push('/admin/settings/authenticator')
setSearchOpen(false)
}}>
<ShieldCheck className="mr-2 h-4 w-4" />
<span>双因素验证</span>
</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>
)
}
26 changes: 26 additions & 0 deletions components/admin/SearchBorder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client'

import { Button } from '~/components/ui/button'
import { cn } from '~/utils'
import { MagnifyingGlassIcon } from '@radix-ui/react-icons'
import { useButtonStore } from '~/app/providers/button-store-Providers'

export default function SearchBorder() {
const { setSearchOpen } = useButtonStore(
(state) => state,
)

return (
<Button
variant={"outline"}
className={cn(
"w-[240px] justify-start text-left font-normal",
"text-muted-foreground"
)}
onClick={() => setSearchOpen(true)}
>
<MagnifyingGlassIcon className="mr-2 h-4 w-4" />
<span>搜索</span>
</Button>
)
}
20 changes: 20 additions & 0 deletions components/admin/SearchButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'

import { Search } from 'lucide-react'
import { useButtonStore } from '~/app/providers/button-store-Providers'
import { usePathname } from 'next/navigation'

export default function SearchButton() {
const pathname = usePathname()
const { setSearchOpen } = useButtonStore(
(state) => state,
)

return (
<>
{
pathname.startsWith('/admin') && <Search onClick={() => setSearchOpen(true)} size={20} />
}
</>
)
}
2 changes: 2 additions & 0 deletions components/layout/DashHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Navbar, NavbarBrand, NavbarContent, NavbarItem } from '@nextui-org/react'
import Logo from '~/components/layout/Logo'
import DynamicNavbar from '~/components/layout/DynamicNavbar'
import SearchBorder from '~/components/admin/SearchBorder'

export default function DashHeader() {
return (
Expand All @@ -9,6 +10,7 @@ export default function DashHeader() {
<Logo />
</NavbarBrand>
<NavbarContent className="hidden sm:flex gap-4 select-none" justify="center">
<SearchBorder />
</NavbarContent>
<NavbarContent justify="end">
<NavbarItem className="flex h-full items-center space-x-2">
Expand Down
4 changes: 4 additions & 0 deletions components/layout/DynamicNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DropMenu } from '~/components/layout/DropMenu'
import DynamicDropMenu from '~/components/layout/DynamicDropMenu'
import { fetchTagsShow } from '~/server/lib/query'
import { DataProps } from '~/types'
import SearchButton from '~/components/admin/SearchButton'

export default async function DynamicNavbar() {
const getData = async () => {
Expand All @@ -18,6 +19,9 @@ export default async function DynamicNavbar() {

return (
<>
<div className="flex sm:hidden">
<SearchButton />
</div>
<div className="flex mx-2 sm:hidden">
<DynamicDropMenu {...props} />
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/ui/Dialog.tsx → components/ui/CustomDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as DialogPrimitive from '@radix-ui/react-dialog'

import { cn } from '~/utils'

const Dialog = DialogPrimitive.Root
const CustomDialog = DialogPrimitive.Root

const DialogTrigger = DialogPrimitive.Trigger

Expand Down Expand Up @@ -109,7 +109,7 @@ const DialogDescription = React.forwardRef<
DialogDescription.displayName = DialogPrimitive.Description.displayName

export {
Dialog,
CustomDialog,
DialogPortal,
DialogOverlay,
DialogClose,
Expand Down
Loading

0 comments on commit efb7ade

Please sign in to comment.