Files
gen2d/frontend/src/api/prompt.ts
T
Gmarker689 f44fd56e22 fix: 自定义标签融入原生标签栏,点击切换而非消失
- StyleSelector 新增 customTags 属性,自定义标签作为「自定义标签」行展示在原生标签栏中
- 自定义标签点击切换 true/false,不再移除 key,解决点击消失问题
- CustomTagsEditor 简化为仅输入框+添加按钮
- extractTags 仅提取激活态自定义标签(value=true)
- 导出 CUSTOM_PREFIX 供组件使用
2026-05-25 19:55:29 +08:00

53 lines
1.3 KiB
TypeScript
Executable File

import { post } from './client'
import { STYLE_CATEGORIES, PROJECT_TYPES, PROJECT_TYPE_KEY, CUSTOM_PREFIX, getCustomTags } from '../utils/style'
interface OptimizePromptParams {
tags: string[]
assetType: string
prompt: string
userNote?: string
}
interface OptimizePromptResponse {
prompt: string
rawText: string
}
/**
* 从风格键值对中提取标签的中文名称作为 tags,包含自定义标签
*/
export function extractTags(style: Record<string, string>): string[] {
const tags: string[] = []
// 工程类型标签
const projectType = style[PROJECT_TYPE_KEY]
if (projectType) {
const pt = PROJECT_TYPES.find(p => p.value === projectType)
if (pt) tags.push(pt.label)
}
// 风格分类标签
for (const cat of STYLE_CATEGORIES) {
const value = style[cat.key]
if (!value) continue
const option = cat.options.find(o => o.value === value)
if (option) tags.push(option.label)
}
// 自定义标签(仅包含激活的)
const customTags = getCustomTags(style).filter(
tag => style[`${CUSTOM_PREFIX}${tag}`] === 'true'
)
tags.push(...customTags)
return tags
}
/**
* 调用后端提示词优化接口
*/
export async function optimizePrompt(
params: OptimizePromptParams,
): Promise<OptimizePromptResponse> {
return post<OptimizePromptResponse>('/api/v1/prompt/optimize', params)
}