feat: 编辑博客支持Slug字段,添加复制链接功能
This commit is contained in:
@@ -8,6 +8,9 @@ export class UpdateBlogDto {
|
|||||||
@IsString()
|
@IsString()
|
||||||
description: string;
|
description: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
slug: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
contentUrl: string;
|
contentUrl: string;
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { BlogPermissionCheckBoxs } from "./BlogPermissionCheckBoxs"
|
|||||||
import { BlogPermission } from "@/lib/types/Blog.Permission.enum"
|
import { BlogPermission } from "@/lib/types/Blog.Permission.enum"
|
||||||
import { SetPasswordDialog } from "./SetPasswordDialog"
|
import { SetPasswordDialog } from "./SetPasswordDialog"
|
||||||
import { AdminAPI } from "@/lib/api/client"
|
import { AdminAPI } from "@/lib/api/client"
|
||||||
|
import { copyShareURL } from "./utils"
|
||||||
|
|
||||||
interface BlogEditProps {
|
interface BlogEditProps {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -46,6 +47,7 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
|||||||
await AdminAPI.updateBlog(id, {
|
await AdminAPI.updateBlog(id, {
|
||||||
title: blog.title,
|
title: blog.title,
|
||||||
description: blog.description,
|
description: blog.description,
|
||||||
|
slug: blog.slug,
|
||||||
contentUrl: blog.contentUrl,
|
contentUrl: blog.contentUrl,
|
||||||
permissions: blog.permissions,
|
permissions: blog.permissions,
|
||||||
});
|
});
|
||||||
@@ -106,6 +108,17 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
|||||||
onChange={(e) => mutate({ ...blog, description: e.target.value }, false)}
|
onChange={(e) => mutate({ ...blog, description: e.target.value }, false)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
|
<Label htmlFor="slug" className="text-right">
|
||||||
|
Slug
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="slug"
|
||||||
|
className="col-span-3"
|
||||||
|
value={blog.slug}
|
||||||
|
onChange={(e) => mutate({ ...blog, slug: e.target.value }, false)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="grid grid-cols-4 items-center gap-4">
|
<div className="grid grid-cols-4 items-center gap-4">
|
||||||
<Label htmlFor="contentUrl" className="text-right">
|
<Label htmlFor="contentUrl" className="text-right">
|
||||||
文章URL
|
文章URL
|
||||||
@@ -151,6 +164,11 @@ export default function BlogEdit({ id, children, onRefresh }: BlogEditProps) {
|
|||||||
<div className="w-full flex justify-between">
|
<div className="w-full flex justify-between">
|
||||||
<div>
|
<div>
|
||||||
<Button variant='destructive' onClick={handleDelete}>删除</Button>
|
<Button variant='destructive' onClick={handleDelete}>删除</Button>
|
||||||
|
<Button variant='outline' className="ml-2" onClick={() => copyShareURL({
|
||||||
|
slug: blog.slug,
|
||||||
|
permissions: blog.permissions,
|
||||||
|
password: ''
|
||||||
|
})}>复制链接</Button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Button type="button" variant='secondary' onClick={() => setOpen(false)}>取消</Button>
|
<Button type="button" variant='secondary' onClick={() => setOpen(false)}>取消</Button>
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export async function createBlog(data: CreateBlogParams) {
|
|||||||
throw new APIError('Slug不得为空')
|
throw new APIError('Slug不得为空')
|
||||||
}
|
}
|
||||||
if (data.contentUrl.length === 0) {
|
if (data.contentUrl.length === 0) {
|
||||||
throw new APIError('文章链接不得为空')
|
throw new APIError('文章URL不得为空')
|
||||||
}
|
}
|
||||||
|
|
||||||
return clientFetch<Blog>('/api/admin/web/blog', {
|
return clientFetch<Blog>('/api/admin/web/blog', {
|
||||||
@@ -138,14 +138,29 @@ export async function removeBlog(id: string) {
|
|||||||
interface UpdateBlogParams {
|
interface UpdateBlogParams {
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
slug: string;
|
||||||
contentUrl: string;
|
contentUrl: string;
|
||||||
permissions: BlogPermission[],
|
permissions: BlogPermission[],
|
||||||
}
|
}
|
||||||
export async function updateBlog(id: string, data: UpdateBlogParams) {
|
export async function updateBlog(id: string, data: UpdateBlogParams) {
|
||||||
data.title = data.title.trim();
|
data.title = data.title.trim();
|
||||||
data.description = data.description.trim();
|
data.description = data.description.trim();
|
||||||
|
data.slug = data.slug.trim();
|
||||||
data.contentUrl = data.contentUrl.trim();
|
data.contentUrl = data.contentUrl.trim();
|
||||||
|
|
||||||
|
if (data.title.length === 0) {
|
||||||
|
throw new APIError('标题不得为空')
|
||||||
|
}
|
||||||
|
if (data.description.length === 0) {
|
||||||
|
throw new APIError('描述不得为空')
|
||||||
|
}
|
||||||
|
if (data.slug.length === 0) {
|
||||||
|
throw new APIError('Slug不得为空')
|
||||||
|
}
|
||||||
|
if (data.contentUrl.length === 0) {
|
||||||
|
throw new APIError('文章URL不得为空')
|
||||||
|
}
|
||||||
|
|
||||||
return clientFetch<Blog>(`/api/admin/web/blog/${id}`, {
|
return clientFetch<Blog>(`/api/admin/web/blog/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { BlogPermission } from "./Blog.Permission.enum";
|
|||||||
export interface Blog {
|
export interface Blog {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
slug: string;
|
||||||
description: string;
|
description: string;
|
||||||
viewCount: number;
|
viewCount: number;
|
||||||
contentUrl: string;
|
contentUrl: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user