提示词库抽屉里面的分类改为动态从后端获取

This commit is contained in:
jingrow 2026-06-25 21:38:11 +08:00
parent f6b9020a79
commit 04f693f301

View File

@ -4,8 +4,10 @@ import { NDrawer, NDrawerContent, NSpin } from 'naive-ui'
import { Icon } from '@iconify/vue'
import { t } from '@/shared/i18n'
import { getPrompts, type PromptTemplate } from '@/shared/api/prompts'
import { getPageTypeMeta } from '@/shared/api/common'
const CATEGORIES = ['', 'General Chat', 'Copywriting', 'Content Marketing', 'E-commerce', 'Data Analysis', 'Summarization', 'Translation & Localization', 'Customer Support', 'Business Strategy', 'Market & Competitor Analysis', 'Education & Learning', 'Agent Design', 'Code Generation', 'Debugging', 'Creative Generation', 'Structured Output', 'Planning & Decision Making', 'Prompt Engineering', 'Research & Retrieval', 'Automation & Workflow']
const categories = ref<string[]>([''])
const loadingCategories = ref(false)
const props = withDefaults(defineProps<{
show: boolean
@ -54,6 +56,23 @@ async function loadTemplates() {
}
}
//
async function loadCategories() {
loadingCategories.value = true
try {
const result = await getPageTypeMeta('Ai Prompt')
if (result.success && result.data?.fields) {
const catField = result.data.fields.find((f: any) => f.fieldname === 'category')
if (catField?.options) {
const list = catField.options.split('\n').filter((o: string) => o.trim())
categories.value = ['', ...list]
}
}
} finally {
loadingCategories.value = false
}
}
// +
function applyFilters() {
let list = allTemplates.value
@ -76,7 +95,7 @@ watch(() => props.show, async (val) => {
if (val) {
searchText.value = ''
activeCategory.value = ''
await loadTemplates()
await Promise.all([loadTemplates(), loadCategories()])
}
})
@ -123,7 +142,7 @@ function pasteTemplate(tpl: PromptTemplate) {
<!-- 分类标签 -->
<div class="category-chips">
<button
v-for="cat in CATEGORIES"
v-for="cat in categories"
:key="cat"
class="chip"
:class="{ active: activeCategory === cat }"