Skip to content

Commit 75c890c

Browse files
committed
修复:优化提示词库组件的分类选择逻辑,新增选择分类的方法并重置二级分类选择
1 parent 9c46146 commit 75c890c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

frontend/src/components/PromptLibrary.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<button
3131
class="tab"
3232
:class="{'tab-active': selectedCategory === ''}"
33-
@click="selectedCategory = ''"
33+
@click="selectCategory('')"
3434
>
3535
全部
3636
</button>
@@ -41,7 +41,7 @@
4141
:key="category"
4242
class="tab"
4343
:class="{'tab-active': selectedCategory === category}"
44-
@click="selectedCategory = category"
44+
@click="selectCategory(category)"
4545
>
4646
{{ category }}
4747
</button>
@@ -122,6 +122,12 @@ export default defineComponent({
122122
promptLibrary.value = newData;
123123
}, { deep: true, immediate: true });
124124
125+
// 监听一级分类变化,当一级分类变化时重置二级分类选择
126+
watch(selectedCategory, () => {
127+
// 重置二级分类
128+
selectedSubCategory.value = '';
129+
});
130+
125131
// 一级分类列表
126132
const categories = computed(() => {
127133
const categorySet = new Set(promptLibrary.value.map(item => item.category));
@@ -161,6 +167,17 @@ export default defineComponent({
161167
emit('select-prompt', prompt);
162168
};
163169
170+
// 选择一级分类
171+
const selectCategory = (category: string) => {
172+
// 如果选择相同的分类,不做处理
173+
if (selectedCategory.value === category) return;
174+
175+
// 更新选择的一级分类
176+
selectedCategory.value = category;
177+
// 重置二级分类选择
178+
selectedSubCategory.value = '';
179+
};
180+
164181
// 加载提示词库
165182
const loadPromptLibrary = async () => {
166183
try {
@@ -192,6 +209,7 @@ export default defineComponent({
192209
categories,
193210
subCategories,
194211
selectPrompt,
212+
selectCategory,
195213
isLoading,
196214
errorMessage,
197215
};

0 commit comments

Comments
 (0)