From a932178509f8547d7d630a43cf09fec39826c5b8 Mon Sep 17 00:00:00 2001 From: tone Date: Sat, 27 Dec 2025 13:13:16 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=8D=9A=E5=AE=A2URL=E5=88=B0=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/blog/components/AddBlog.tsx | 31 ++++-------------- .../(with-menu)/web/blog/components/utils.ts | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 apps/frontend/app/console/(with-menu)/web/blog/components/utils.ts diff --git a/apps/frontend/app/console/(with-menu)/web/blog/components/AddBlog.tsx b/apps/frontend/app/console/(with-menu)/web/blog/components/AddBlog.tsx index 753e2fc..b3592b4 100644 --- a/apps/frontend/app/console/(with-menu)/web/blog/components/AddBlog.tsx +++ b/apps/frontend/app/console/(with-menu)/web/blog/components/AddBlog.tsx @@ -17,6 +17,7 @@ import { useState } from "react"; import { toast } from "sonner"; import { BlogPermissionCheckBoxs } from "./BlogPermissionCheckBoxs"; import { AdminAPI } from "@/lib/api/client"; +import { handleCopyShareURL } from "./utils"; interface AddBlogProps { children: React.ReactNode; @@ -34,30 +35,6 @@ export default function AddBlog({ children, onRefresh }: AddBlogProps) { password: "", }); - const handleCopyShareURL = () => { - const slug = blog.slug.trim(); - if (slug.length === 0) { - return toast.warning('请先填写Slug') - } - - let url = `${window.location.origin}/blog/${slug}`; - - const password = blog.password.trim(); - if (blog.permissions.includes(BlogPermission.ByPassword)) { - if (password.length === 0) { - return toast.warning('开启了密码保护,但没有填写有效的密码,无法生成有效URL') - } else { - url += `?p=${blog.password.trim()}`; - } - } - - navigator.clipboard.writeText(url).then(() => { - toast.success('复制成功'); - }, () => { - toast.error('复制失败,请手动复制'); - }); - }; - const handleSubmit = async () => { try { const res = await AdminAPI.createBlog({ @@ -175,7 +152,11 @@ export default function AddBlog({ children, onRefresh }: AddBlogProps) {
- +
diff --git a/apps/frontend/app/console/(with-menu)/web/blog/components/utils.ts b/apps/frontend/app/console/(with-menu)/web/blog/components/utils.ts new file mode 100644 index 0000000..f247ffa --- /dev/null +++ b/apps/frontend/app/console/(with-menu)/web/blog/components/utils.ts @@ -0,0 +1,32 @@ +import { BlogPermission } from "@/lib/types/Blog.Permission.enum"; +import { toast } from "sonner"; + +export function handleCopyShareURL(data: { + slug: string; + password: string; + permissions: BlogPermission[]; +}) { + const slug = data.slug.trim(); + const password = data.password.trim(); + const permissions = data.permissions; + + if (slug.length === 0) { + return toast.warning('请先填写Slug') + } + + let url = `${window.location.origin}/blog/${slug}`; + + if (permissions.includes(BlogPermission.ByPassword)) { + if (password.length === 0) { + return toast.warning('开启了密码保护,但无法获取有效的密码,无法生成有效URL') + } else { + url += `?p=${password}`; + } + } + + navigator.clipboard.writeText(url).then(() => { + toast.success('复制成功'); + }, () => { + toast.error('复制失败,请手动复制'); + }); +}; \ No newline at end of file