diff --git a/frontend/src/api/prompt.ts b/frontend/src/api/prompt.ts index f023b57..bda3d46 100755 --- a/frontend/src/api/prompt.ts +++ b/frontend/src/api/prompt.ts @@ -1,5 +1,5 @@ import { post } from './client' -import { STYLE_CATEGORIES, PROJECT_TYPES, PROJECT_TYPE_KEY, getCustomTags } from '../utils/style' +import { STYLE_CATEGORIES, PROJECT_TYPES, PROJECT_TYPE_KEY, CUSTOM_PREFIX, getCustomTags } from '../utils/style' interface OptimizePromptParams { tags: string[] @@ -34,8 +34,11 @@ export function extractTags(style: Record): string[] { if (option) tags.push(option.label) } - // 自定义标签 - tags.push(...getCustomTags(style)) + // 自定义标签(仅包含激活的) + const customTags = getCustomTags(style).filter( + tag => style[`${CUSTOM_PREFIX}${tag}`] === 'true' + ) + tags.push(...customTags) return tags } diff --git a/frontend/src/components/CreateProjectModal.tsx b/frontend/src/components/CreateProjectModal.tsx index 3edd8ec..a819adf 100644 --- a/frontend/src/components/CreateProjectModal.tsx +++ b/frontend/src/components/CreateProjectModal.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { PROJECT_TYPES, PROJECT_TYPE_KEY } from '../utils/style' +import { PROJECT_TYPES, PROJECT_TYPE_KEY, getCustomTags } from '../utils/style' import StyleSelector from './StyleSelector' import CustomTagsEditor from './CustomTagsEditor' @@ -91,9 +91,6 @@ export default function CreateProjectModal({
- - 工程类型 - ({ value: p.value, label: p.label })), }]} + customTags={getCustomTags(style)} />
diff --git a/frontend/src/components/CustomTagsEditor.tsx b/frontend/src/components/CustomTagsEditor.tsx index 6407e0b..3331c57 100644 --- a/frontend/src/components/CustomTagsEditor.tsx +++ b/frontend/src/components/CustomTagsEditor.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { getCustomTags, addCustomTag, removeCustomTag } from '../utils/style' +import { getCustomTags, addCustomTag } from '../utils/style' interface CustomTagsEditorProps { style: Record @@ -26,51 +26,14 @@ export default function CustomTagsEditor({ style, onChange }: CustomTagsEditorPr } return ( -
-
- 自定义标签 -
-
- {tags.map(tag => ( - - {tag} - - - ))} -
+
setInput(e.target.value)} onKeyDown={handleKeyDown} - placeholder="输入标签后按 Enter 添加" + placeholder="输入自定义标签后按 Enter 添加" style={{ flex: 1, padding: '6px 10px', fontSize: 13 }} />
diff --git a/frontend/src/components/ProjectConfigPanel.tsx b/frontend/src/components/ProjectConfigPanel.tsx index f504f6c..a5384b1 100644 --- a/frontend/src/components/ProjectConfigPanel.tsx +++ b/frontend/src/components/ProjectConfigPanel.tsx @@ -2,7 +2,7 @@ import { useEffect } from 'react' import { useParams } from 'react-router-dom' import { useProjectStore } from '../stores/project' import { useToastStore } from '../stores/toast' -import { PROJECT_TYPES, PROJECT_TYPE_KEY } from '../utils/style' +import { PROJECT_TYPES, PROJECT_TYPE_KEY, getCustomTags } from '../utils/style' import StyleSelector from './StyleSelector' import CustomTagsEditor from './CustomTagsEditor' import Skeleton from './Skeleton' @@ -73,9 +73,6 @@ export default function ProjectConfigPanel() {
-
- 工程类型 -
({ value: p.value, label: p.label })), }]} + customTags={getCustomTags(draftStyle)} />
diff --git a/frontend/src/components/PromptEditor.tsx b/frontend/src/components/PromptEditor.tsx index fbd43fc..27ecaef 100755 --- a/frontend/src/components/PromptEditor.tsx +++ b/frontend/src/components/PromptEditor.tsx @@ -1,4 +1,4 @@ -import { STYLE_CATEGORIES, PROJECT_TYPES, PROJECT_TYPE_KEY, getCustomTags } from '../utils/style' +import { STYLE_CATEGORIES, PROJECT_TYPES, PROJECT_TYPE_KEY, CUSTOM_PREFIX, getCustomTags } from '../utils/style' import styles from './GenerateForm.module.css' interface PromptEditorProps { @@ -32,7 +32,9 @@ function styleToDescription(kvPairs: Record): string { if (option) parts.push(`${cat.label}: ${option.label}`) } - const customTags = getCustomTags(kvPairs) + const customTags = getCustomTags(kvPairs).filter( + tag => kvPairs[`${CUSTOM_PREFIX}${tag}`] === 'true' + ) if (customTags.length > 0) parts.push(`标签: ${customTags.join(', ')}`) return parts.join(', ') diff --git a/frontend/src/components/StyleSelector.tsx b/frontend/src/components/StyleSelector.tsx index 06a7578..d995d26 100755 --- a/frontend/src/components/StyleSelector.tsx +++ b/frontend/src/components/StyleSelector.tsx @@ -1,5 +1,5 @@ import type { StyleCategory } from '../utils/style' -import { STYLE_CATEGORIES } from '../utils/style' +import { STYLE_CATEGORIES, CUSTOM_PREFIX } from '../utils/style' import styles from './StyleSelector.module.css' interface StyleSelectorProps { @@ -7,6 +7,13 @@ interface StyleSelectorProps { onChange: (key: string, value: string) => void compact?: boolean categories?: StyleCategory[] + customTags?: string[] +} + +const CUSTOM_TAG_CATEGORY: StyleCategory = { + key: '', // unused, pills use custom: prefix directly + label: '自定义标签', + options: [], } export default function StyleSelector({ @@ -14,6 +21,7 @@ export default function StyleSelector({ onChange, compact, categories, + customTags, }: StyleSelectorProps) { const cats = categories ?? STYLE_CATEGORIES return ( @@ -37,6 +45,27 @@ export default function StyleSelector({
))} + {customTags && customTags.length > 0 && ( +
+ {CUSTOM_TAG_CATEGORY.label} +
+ {customTags.map(tag => { + const key = `${CUSTOM_PREFIX}${tag}` + const isActive = value[key] === 'true' + return ( + + ) + })} +
+
+ )} ) } diff --git a/frontend/src/utils/style.ts b/frontend/src/utils/style.ts index 55d979b..222ffc3 100755 --- a/frontend/src/utils/style.ts +++ b/frontend/src/utils/style.ts @@ -8,7 +8,7 @@ export function mergeStyles( return { ...projectStyle, ...taskOverrides } } -const CUSTOM_PREFIX = 'custom:' +export const CUSTOM_PREFIX = 'custom:' export function isCustomKey(key: string): boolean { return key.startsWith(CUSTOM_PREFIX)