feat: 添加关键词词云系统 Zod 验证 Schema
This commit is contained in:
@@ -140,3 +140,75 @@ export type CreateDiscoveryTask = z.infer<typeof CreateDiscoveryTaskSchema>
|
||||
export type UpdateDiscoveryTask = z.infer<typeof UpdateDiscoveryTaskSchema>
|
||||
export type GetDiscoveryTasksQuery = z.infer<typeof GetDiscoveryTasksQuerySchema>
|
||||
export type BatchResetTasks = z.infer<typeof BatchResetTasksSchema>
|
||||
|
||||
// ================================
|
||||
// Keyword Cloud Schemas
|
||||
// ================================
|
||||
|
||||
// 视觉配置 Schema
|
||||
const VisualConfigSchema = z.object({
|
||||
color: z.enum(['primary', 'secondary', 'accent', 'gray']),
|
||||
size: z.enum(['text-5xl', 'text-4xl', 'text-3xl', 'text-2xl', 'text-xl', 'text-lg', 'text-base']),
|
||||
border: z.enum(['border-4', 'border-2']),
|
||||
rotation: z.string().regex(/^-?rotate-\d+$/).nullable().optional(),
|
||||
})
|
||||
|
||||
// 关键词输入 Schema
|
||||
export const KeywordInputSchema = z.object({
|
||||
word: z.string().min(1).max(100),
|
||||
trendScore: z.number().int().min(0).max(100),
|
||||
description: z.string().min(10).max(500),
|
||||
descriptionEn: z.string().max(500).optional(),
|
||||
detailPoints: z.array(z.string().min(5).max(100)).min(1).max(5),
|
||||
detailPointsEn: z.array(z.string().max(100)).max(5).optional(),
|
||||
visualConfig: VisualConfigSchema,
|
||||
})
|
||||
|
||||
// 批量写入关键词请求 Schema
|
||||
export const BatchKeywordsRequestSchema = z.object({
|
||||
quarter: z.string().regex(/^\d{4}-Q[1-4]$/, "格式应为 YYYY-QN"),
|
||||
keywords: z.array(KeywordInputSchema).min(1).max(50),
|
||||
})
|
||||
|
||||
// 季度 Schema
|
||||
export const QuarterSchema = z.object({
|
||||
quarter: z.string().regex(/^\d{4}-Q[1-4]$/),
|
||||
title: z.string().min(1).max(200),
|
||||
titleEn: z.string().max(200).optional(),
|
||||
subtitle: z.string().max(500).optional(),
|
||||
subtitleEn: z.string().max(500).optional(),
|
||||
displayOrder: z.number().int().min(0).default(0),
|
||||
isActive: z.boolean().default(true),
|
||||
})
|
||||
|
||||
// 视觉规则 Schema
|
||||
export const VisualStyleRuleSchema = z.object({
|
||||
name: z.string().min(1).max(100),
|
||||
minScore: z.number().int().min(0).max(100),
|
||||
maxScore: z.number().int().min(0).max(100),
|
||||
color: z.enum(['primary', 'secondary', 'accent', 'gray']),
|
||||
size: z.enum(['text-5xl', 'text-4xl', 'text-3xl', 'text-2xl', 'text-xl', 'text-lg', 'text-base']),
|
||||
border: z.enum(['border-4', 'border-2']),
|
||||
rotation: z.string().regex(/^-?rotate-\d+$/).nullable().optional(),
|
||||
priority: z.number().int().min(0).default(0),
|
||||
enabled: z.boolean().default(true),
|
||||
}).refine(data => data.minScore < data.maxScore, {
|
||||
message: "minScore 必须小于 maxScore",
|
||||
})
|
||||
|
||||
// API 响应 Schema
|
||||
export const KeywordCloudResponseSchema = z.object({
|
||||
success: z.boolean(),
|
||||
data: z.any().optional(),
|
||||
error: z.string().optional(),
|
||||
})
|
||||
|
||||
// ================================
|
||||
// Types
|
||||
// ================================
|
||||
|
||||
export type KeywordInput = z.infer<typeof KeywordInputSchema>
|
||||
export type BatchKeywordsRequest = z.infer<typeof BatchKeywordsRequestSchema>
|
||||
export type Quarter = z.infer<typeof QuarterSchema>
|
||||
export type VisualStyleRule = z.infer<typeof VisualStyleRuleSchema>
|
||||
export type KeywordCloudResponse = z.infer<typeof KeywordCloudResponseSchema>
|
||||
|
||||
Reference in New Issue
Block a user