@@ -162,6 +162,10 @@ export default defineComponent({
162162 const isSaving = ref (false );
163163 const errorMessage = ref (' ' );
164164
165+ // 本地分类管理
166+ const localCategories = ref <string []>([]);
167+ const localSubCategories = ref <{[key : string ]: string []}>({});
168+
165169 // 新提示词数据
166170 const newPrompt = ref <NewPromptData >({
167171 text: ' ' ,
@@ -173,8 +177,12 @@ export default defineComponent({
173177
174178 // 一级分类列表
175179 const categories = computed (() => {
176- // 直接从props中获取分类
180+ // 从props中获取分类
177181 const categorySet = new Set (props .promptLibraryData .map (item => item .category ));
182+
183+ // 添加本地新增的分类
184+ localCategories .value .forEach (cat => categorySet .add (cat ));
185+
178186 return Array .from (categorySet ).sort ();
179187 });
180188
@@ -191,6 +199,13 @@ export default defineComponent({
191199 filteredItems .forEach (item => {
192200 if (item .subCategory ) subCategorySet .add (item .subCategory );
193201 });
202+
203+ // 添加本地新增的二级分类
204+ if (localSubCategories .value [newPrompt .value .category ]) {
205+ localSubCategories .value [newPrompt .value .category ].forEach (
206+ subCat => subCategorySet .add (subCat )
207+ );
208+ }
194209 }
195210
196211 return Array .from (subCategorySet ).sort ();
@@ -220,6 +235,7 @@ export default defineComponent({
220235 newCategory .value = ' ' ;
221236 newSubCategory .value = ' ' ;
222237 errorMessage .value = ' ' ;
238+ // 注意:不重置localCategories和localSubCategories,保留用户添加的分类
223239 };
224240
225241 // 添加新一级分类
@@ -232,6 +248,9 @@ export default defineComponent({
232248 return ;
233249 }
234250
251+ // 添加到本地分类列表
252+ localCategories .value .push (newCategory .value .trim ());
253+
235254 // 设置新分类
236255 newPrompt .value .category = newCategory .value .trim ();
237256 showAddCategory .value = false ;
@@ -248,6 +267,14 @@ export default defineComponent({
248267 return ;
249268 }
250269
270+ // 确保一级分类在本地子分类映射中存在
271+ if (! localSubCategories .value [newPrompt .value .category ]) {
272+ localSubCategories .value [newPrompt .value .category ] = [];
273+ }
274+
275+ // 添加到本地二级分类列表
276+ localSubCategories .value [newPrompt .value .category ].push (newSubCategory .value .trim ());
277+
251278 // 设置新二级分类
252279 newPrompt .value .subCategory = newSubCategory .value .trim ();
253280 showAddSubCategory .value = false ;
@@ -378,6 +405,8 @@ export default defineComponent({
378405 subCategories ,
379406 canSaveToLibrary ,
380407 errorMessage ,
408+ localCategories ,
409+ localSubCategories ,
381410
382411 // 方法
383412 addNewCategory ,
0 commit comments