Skip to content

Commit 86e8582

Browse files
committed
重构:移除提示词库中的中英文映射字典,优化翻译逻辑,改为从提示词库中查找已有翻译,加载失败时使用空数组替代示例数据
1 parent aec6ce7 commit 86e8582

File tree

3 files changed

+11
-110
lines changed

3 files changed

+11
-110
lines changed

frontend/src/components/PromptBadges.vue

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -95,47 +95,6 @@ interface PromptData {
9595
isTranslating?: boolean; // 是否正在翻译
9696
}
9797
98-
// 简单的中英文映射字典
99-
const translationMap: Record<string, string> = {
100-
'写实风格': 'realistic style',
101-
'动漫风格': 'anime style',
102-
'水彩画': 'watercolor',
103-
'油画': 'oil painting',
104-
'素描': 'sketch',
105-
'赛博朋克': 'cyberpunk',
106-
'未来主义': 'futurism',
107-
'极简主义': 'minimalism',
108-
'高清': 'high resolution',
109-
'高质量': 'high quality',
110-
'细节丰富': 'detailed',
111-
'精细': 'fine detail',
112-
'夜景': 'night scene',
113-
'黎明': 'dawn',
114-
'黄昏': 'dusk',
115-
'雨天': 'rainy',
116-
'雪景': 'snow scene',
117-
'海边': 'seaside',
118-
'森林': 'forest',
119-
'城市': 'city',
120-
'星空': 'starry sky',
121-
'广角镜头': 'wide-angle lens',
122-
'长焦镜头': 'telephoto lens',
123-
'鱼眼镜头': 'fisheye lens',
124-
'微距': 'macro',
125-
'景深': 'depth of field',
126-
'散景': 'bokeh',
127-
'低角度': 'low angle',
128-
'航拍': 'aerial photography',
129-
'逆光': 'backlight',
130-
'侧光': 'sidelight',
131-
'柔光': 'soft light',
132-
'硬光': 'hard light',
133-
'聚光': 'spotlight',
134-
'霓虹灯': 'neon lights',
135-
'金色光芒': 'golden rays',
136-
'蓝色调': 'blue tone'
137-
};
138-
13998
export default defineComponent({
14099
name: 'PromptBadges',
141100
@@ -293,15 +252,16 @@ export default defineComponent({
293252
isTranslating: true
294253
};
295254
296-
// 使用已有翻译
297-
if (isEnglish && translationMap[text]) {
298-
promptData.chinese = translationMap[text];
299-
promptData.isTranslating = false;
300-
console.log(`[本地翻译] 英->中: "${text}" -> "${translationMap[text]}"`);
301-
} else if (!isEnglish && translationMap[text]) {
302-
promptData.english = translationMap[text];
255+
// 查找提示词库中是否已有该提示词的翻译
256+
const existingPrompt = promptLibrary.value.find(p =>
257+
(isEnglish && p.english === text) || (!isEnglish && p.chinese === text)
258+
);
259+
260+
if (existingPrompt) {
261+
promptData.chinese = existingPrompt.chinese;
262+
promptData.english = existingPrompt.english;
303263
promptData.isTranslating = false;
304-
console.log(`[本地翻译] 中->英: "${text}" -> "${translationMap[text]}"`);
264+
console.log(`[库中查找] 文本: "${text}", 找到翻译: "${isEnglish ? existingPrompt.chinese : existingPrompt.english}"`);
305265
} else {
306266
console.log(`[需要翻译] 文本: "${text}", 当前状态:`, promptData);
307267
}

frontend/src/components/PromptLibraryEditor.vue

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,6 @@ interface NewPromptData {
137137
isEnglish: boolean; // 是否为英文
138138
}
139139
140-
// 简单的中英文映射字典
141-
const translationMap: Record<string, string> = {
142-
'写实风格': 'realistic style',
143-
'动漫风格': 'anime style',
144-
'水彩画': 'watercolor',
145-
'油画': 'oil painting',
146-
'素描': 'sketch',
147-
'赛博朋克': 'cyberpunk',
148-
'未来主义': 'futurism',
149-
'极简主义': 'minimalism',
150-
'高清': 'high resolution',
151-
'高质量': 'high quality',
152-
'细节丰富': 'detailed',
153-
'精细': 'fine detail',
154-
// ... 可以保留更多映射
155-
};
156-
157140
export default defineComponent({
158141
name: 'PromptLibraryEditor',
159142
@@ -335,15 +318,6 @@ export default defineComponent({
335318
const isEnglish = /^[a-zA-Z0-9\s\-_,.]+$/.test(text);
336319
newPrompt.value.isEnglish = isEnglish;
337320
338-
// 检查本地翻译字典
339-
if (isEnglish && translationMap[text]) {
340-
newPrompt.value.translated = translationMap[text];
341-
return;
342-
} else if (!isEnglish && translationMap[text]) {
343-
newPrompt.value.translated = translationMap[text];
344-
return;
345-
}
346-
347321
// 检查是否已存在于提示词库中
348322
const existingPrompt = props.promptLibraryData.find(p =>
349323
(p.english === text && newPrompt.value.isEnglish) ||

frontend/src/pages/PromptManager.vue

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -132,41 +132,8 @@ export default defineComponent({
132132
} catch (error) {
133133
console.error('加载提示词库失败:', error);
134134
135-
// 加载失败时使用示例数据
136-
promptLibrary.value = [
137-
{
138-
id: '1',
139-
text: '写实风格',
140-
chinese: '写实风格',
141-
english: 'realistic style',
142-
category: '风格',
143-
subCategory: '基础风格'
144-
},
145-
{
146-
id: '2',
147-
text: '水彩画',
148-
chinese: '水彩画',
149-
english: 'watercolor',
150-
category: '风格',
151-
subCategory: '绘画媒介'
152-
},
153-
{
154-
id: '3',
155-
text: '高清',
156-
chinese: '高清',
157-
english: 'high resolution',
158-
category: '质量',
159-
subCategory: '分辨率'
160-
},
161-
{
162-
id: '4',
163-
text: 'masterpiece',
164-
chinese: '杰作',
165-
english: 'masterpiece',
166-
category: '质量',
167-
subCategory: '通用'
168-
}
169-
];
135+
// 加载失败时使用空数组
136+
promptLibrary.value = [];
170137
}
171138
};
172139

0 commit comments

Comments
 (0)