chore: initial commit

This commit is contained in:
2026-07-22 17:50:30 +08:00
parent d46cdd676e
commit 3abf272e33
190 changed files with 18073 additions and 0 deletions

55
src/schemas/blog/post.ts Normal file
View File

@@ -0,0 +1,55 @@
import { z } from 'zod'
import { sysFileFormSchema } from '@/schemas'
export const postSchema = z.object({
id: z.number().int(),
title: z.string(),
cover_id: z.number().int(),
cover: z.string(),
slug: z.string(),
content: z.string(),
summary: z.string(),
status: z.number().int(),
view: z.number().int(),
sort: z.number().int(),
category_name: z.string(),
category_id: z.number().int().optional(),
published_at: z.string(),
created_at: z.string(),
updated_at: z.string(),
})
export type Post = z.infer<typeof postSchema>
export const postFormSchema = z
.object({
id: z.number().int().optional(),
title: z.string().min(1, '请输入文章标题!'),
slug: z
.string()
.min(1, '请输入 URL 别名!')
.regex(/^[A-Za-z0-9-]+$/, '只允许字母、数字和短横线(-)'),
summary: z.string(),
status: z.number().int(),
published_at: z.string().min(1, '请选择发布日期!'),
cover: sysFileFormSchema,
sort: z.coerce.number<number>().int().min(0, '排序值不能小于0'),
content: z.string().optional(),
category_id: z
.number()
.int()
.optional()
.refine((v) => v !== undefined, '请选择文章分类'),
})
.transform((data) => {
const { cover, ...rest } = data
return {
...rest,
cover_id: cover && cover.id,
}
})
export type PostFormInput = z.input<typeof postFormSchema>
export type PostFormOutput = z.output<typeof postFormSchema>