Skip to content

Commit 461c2f1

Browse files
committed
添加预设提示功能,集成PresetPromptModal组件以增强用户交互体验。更新AITestDialog和VectorizeModal组件,支持选择预设提示并自动填充输入框。更新国际化文本以反映新功能,确保多语言支持的准确性和一致性。
1 parent ada5cd4 commit 461c2f1

6 files changed

Lines changed: 1637 additions & 421 deletions

File tree

src/components/AITestDialog.tsx

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Markdown from "markdown-to-jsx";
1515
// 引入SyntaxHighlighter的两种版本
1616
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
1717
import { Light as LightSyntaxHighlighter } from "react-syntax-highlighter";
18+
// 导入预设提示弹窗组件
19+
import PresetPromptModal from "./PresetPromptModal";
1820

1921
// 导入Prism的样式
2022
import {
@@ -1129,6 +1131,9 @@ export default function AITestDialog({
11291131
useState(false);
11301132
const [requirementContext, setRequirementContext] = useState("");
11311133

1134+
// 添加预设提示弹窗状态
1135+
const [showPresetPrompts, setShowPresetPrompts] = useState(false);
1136+
11321137
// 自动滚动到当前AI回复的开头位置
11331138
const scrollToCurrentResponse = useCallback(() => {
11341139
if (currentRoundRef.current) {
@@ -2698,6 +2703,11 @@ ${aiResponse}
26982703
}
26992704
};
27002705

2706+
// 处理选择预设提示
2707+
const handleSelectPrompt = (prompt: string) => {
2708+
setCustomInput(prompt);
2709+
};
2710+
27012711
return (
27022712
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
27032713
<div className="bg-white dark:bg-gray-800 w-full h-full flex flex-col">
@@ -2839,7 +2849,6 @@ ${aiResponse}
28392849
)}
28402850
</div>
28412851

2842-
{/* 底部输入区域 - ChatGPT风格 */}
28432852
<div className="p-3 sm:p-4 border-t border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800">
28442853
<div className="max-w-3xl mx-auto">
28452854
<form onSubmit={handleCustomInputSubmit} className="relative">
@@ -2873,29 +2882,53 @@ ${aiResponse}
28732882

28742883
<div className="absolute right-2 bottom-2 sm:bottom-2.5 flex space-x-1">
28752884
{!isTesting && !isComplete && (
2876-
<button
2877-
type="button"
2878-
onClick={() => setShowOptions(!showOptions)}
2879-
className="p-1.5 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300 rounded-md hover:bg-gray-100 dark:hover:bg-gray-600"
2880-
title={
2881-
t("vectorReport.aiDialog.optionsTitle") || "显示建议问题"
2882-
}
2883-
>
2884-
<svg
2885-
xmlns="http://www.w3.org/2000/svg"
2886-
className="h-5 w-5"
2887-
fill="none"
2888-
viewBox="0 0 24 24"
2889-
stroke="currentColor"
2885+
<>
2886+
<button
2887+
type="button"
2888+
onClick={() => setShowPresetPrompts(true)}
2889+
className="p-1.5 text-blue-600 hover:text-blue-700 dark:text-blue-500 dark:hover:text-blue-400 rounded-md hover:bg-gray-100 dark:hover:bg-gray-600"
2890+
title={t("presetPrompts.button") || "提示"}
28902891
>
2891-
<path
2892-
strokeLinecap="round"
2893-
strokeLinejoin="round"
2894-
strokeWidth={2}
2895-
d="M8 12h.01M12 12h.01M16 12h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
2896-
/>
2897-
</svg>
2898-
</button>
2892+
<svg
2893+
xmlns="http://www.w3.org/2000/svg"
2894+
className="h-5 w-5"
2895+
fill="none"
2896+
viewBox="0 0 24 24"
2897+
stroke="currentColor"
2898+
>
2899+
<path
2900+
strokeLinecap="round"
2901+
strokeLinejoin="round"
2902+
strokeWidth={2}
2903+
d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"
2904+
/>
2905+
</svg>
2906+
</button>
2907+
<button
2908+
type="button"
2909+
onClick={() => setShowOptions(!showOptions)}
2910+
className="p-1.5 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300 rounded-md hover:bg-gray-100 dark:hover:bg-gray-600"
2911+
title={
2912+
t("vectorReport.aiDialog.optionsTitle") ||
2913+
"显示建议问题"
2914+
}
2915+
>
2916+
<svg
2917+
xmlns="http://www.w3.org/2000/svg"
2918+
className="h-5 w-5"
2919+
fill="none"
2920+
viewBox="0 0 24 24"
2921+
stroke="currentColor"
2922+
>
2923+
<path
2924+
strokeLinecap="round"
2925+
strokeLinejoin="round"
2926+
strokeWidth={2}
2927+
d="M8 12h.01M12 12h.01M16 12h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
2928+
/>
2929+
</svg>
2930+
</button>
2931+
</>
28992932
)}
29002933

29012934
<button
@@ -2998,6 +3031,13 @@ ${aiResponse}
29983031
/>
29993032
)}
30003033
</div>
3034+
3035+
{/* 添加预设提示弹窗 */}
3036+
<PresetPromptModal
3037+
isOpen={showPresetPrompts}
3038+
onClose={() => setShowPresetPrompts(false)}
3039+
onSelectPrompt={handleSelectPrompt}
3040+
/>
30013041
</div>
30023042
);
30033043
}

src/components/LocaleProvider.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const preloadedTranslationsPromise: Record<Locale, Promise<any>> = {
2020
// 创建翻译上下文
2121
type TranslationsContextType = {
2222
t: (key: string, params?: Record<string, string>) => string;
23+
tObject: (key: string) => any;
2324
locale: Locale;
2425
setLocale: (locale: Locale) => void;
2526
};
@@ -51,6 +52,22 @@ function getNestedTranslation(obj: any, path: string): string {
5152
return typeof result === "string" ? result : path;
5253
}
5354

55+
// 获取对象类型的翻译
56+
function getNestedObject(obj: any, path: string): any {
57+
const keys = path.split(".");
58+
let result = obj;
59+
60+
for (const key of keys) {
61+
if (result && typeof result === "object" && key in result) {
62+
result = result[key];
63+
} else {
64+
return null; // 如果找不到翻译对象,返回null
65+
}
66+
}
67+
68+
return result;
69+
}
70+
5471
// 替换参数
5572
function replaceParams(text: string, params?: Record<string, string>): string {
5673
if (!params) return text;
@@ -117,13 +134,19 @@ export function LocaleProvider({ children }: { children: ReactNode }) {
117134
return replaceParams(translation, params);
118135
};
119136

137+
// 对象翻译函数
138+
const tObject = (key: string): any => {
139+
if (!translations) return null;
140+
return getNestedObject(translations, key);
141+
};
142+
120143
// 如果是第一次加载且没有翻译数据,显示一个最小的加载状态
121144
if (!initialLoadComplete && loading) {
122145
return null; // 或者返回一个简单的加载指示器
123146
}
124147

125148
return (
126-
<TranslationsContext.Provider value={{ t, locale, setLocale }}>
149+
<TranslationsContext.Provider value={{ t, tObject, locale, setLocale }}>
127150
{children}
128151
</TranslationsContext.Provider>
129152
);

0 commit comments

Comments
 (0)