From 38fa0a0a073b17c0c24e124b8d1295c19be59b75 Mon Sep 17 00:00:00 2001 From: tone <3341154833@qq.com> Date: Sun, 22 Jun 2025 23:31:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96blogPermissionCheckBoxs?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/blog/components/AddBlog.tsx | 41 +++++-------------- .../components/BlogPermissionCheckBoxs.tsx | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+), 31 deletions(-) create mode 100644 tone-page-web/app/console/(with-menu)/web/blog/components/BlogPermissionCheckBoxs.tsx diff --git a/tone-page-web/app/console/(with-menu)/web/blog/components/AddBlog.tsx b/tone-page-web/app/console/(with-menu)/web/blog/components/AddBlog.tsx index 7b869e3..1853ead 100644 --- a/tone-page-web/app/console/(with-menu)/web/blog/components/AddBlog.tsx +++ b/tone-page-web/app/console/(with-menu)/web/blog/components/AddBlog.tsx @@ -16,27 +16,13 @@ import { AdminApi } from "@/lib/api"; import { BlogPermission } from "@/lib/types/Blog.Permission.enum"; import { useState } from "react"; import { toast } from "sonner"; +import { BlogPermissionCheckBoxs } from "./BlogPermissionCheckBoxs"; interface AddBlogProps { children: React.ReactNode; onRefresh: () => void; } -const blogPermissions = [ - { - permission: BlogPermission.Public, - localText: '公开可读', - }, - { - permission: BlogPermission.ByPassword, - localText: '受密码保护', - }, - { - permission: BlogPermission.List, - localText: '显示在列表中', - }, -] as const; - export default function AddBlog({ children, onRefresh }: AddBlogProps) { const [open, setOpen] = useState(false); const [blog, setBlog] = useState({ @@ -120,22 +106,15 @@ export default function AddBlog({ children, onRefresh }: AddBlogProps) {
{ - blogPermissions.map((v, i) => ( -
- { - setBlog({ - ...blog, - permissions: newChecked ? - [...blog.permissions, v.permission] : - [...blog.permissions].filter(p => p !== v.permission), - }) - }} /> - -
- )) + setBlog({ + ...blog, + permissions: n ? + [...blog.permissions, p] : + [...blog.permissions].filter(p => p !== p), + })} + /> }
diff --git a/tone-page-web/app/console/(with-menu)/web/blog/components/BlogPermissionCheckBoxs.tsx b/tone-page-web/app/console/(with-menu)/web/blog/components/BlogPermissionCheckBoxs.tsx new file mode 100644 index 0000000..978eafd --- /dev/null +++ b/tone-page-web/app/console/(with-menu)/web/blog/components/BlogPermissionCheckBoxs.tsx @@ -0,0 +1,41 @@ +import { Checkbox } from "@/components/ui/checkbox"; +import { Label } from "@/components/ui/label"; +import { BlogPermission } from "@/lib/types/Blog.Permission.enum"; + +const blogPermissions = [ + { + permission: BlogPermission.Public, + localText: '公开可读', + }, + { + permission: BlogPermission.ByPassword, + localText: '受密码保护', + }, + { + permission: BlogPermission.List, + localText: '显示在列表中', + }, +] as const; + +interface BlogPermissionCheckBoxsProps { + permissions: BlogPermission[]; + onCheckedChange: (permission: BlogPermission, newState: boolean) => void; +} + +export function BlogPermissionCheckBoxs({ permissions, onCheckedChange }: BlogPermissionCheckBoxsProps) { + return ( + <> + { + blogPermissions.map((v, i) => ( +
+ onCheckedChange(v.permission, !!newChecked)} /> + +
+ )) + } + + ) +} \ No newline at end of file