feat(write): 在应用模板时增加内容覆盖提示

- 在用户选择模板时,如果当前编辑内容不为空且与所选模板内容不同,弹出确认框提示用户
- 确认框包含标题、内容覆盖提示、继续和取消按钮
- 用户点击继续按钮后,将所选模板内容覆盖当前编辑内容
- 优化了模板应用逻辑,避免不必要的提示
This commit is contained in:
zstar 2025-06-12 14:38:51 +08:00
parent d888c4a8d1
commit 7365ce8c8b
4 changed files with 179 additions and 5 deletions

View File

@ -540,6 +540,79 @@ This auto-tag feature enhances retrieval by adding another layer of domain-speci
tavilyApiKeyMessage: 'Please enter your Tavily API Key',
tavilyApiKeyHelp: 'How to get it?',
},
write: {
writeDocument: 'Document Writing',
writePlaceholder: 'Please enter the document content...',
save: 'Export as Word',
templateList: 'Template List',
defaultTemplate: 'Project Proposal',
technicalDoc: 'Academic Paper',
meetingMinutes: 'Meeting Minutes',
select: 'Select',
aiAssistant: 'AI Assistant',
askAI: 'Enter your question',
edit: 'Edit Mode',
split: 'Split View',
preview: 'Preview Mode',
previewPlaceholder: 'Please enter the document content...',
saveCurrentAsTemplate: 'Save current content as template',
delete: 'Delete',
customTemplateMarker: 'Custom Template',
confirmDeleteTemplate: 'Confirm delete this template?',
cancel: 'Cancel',
confirm: 'Confirm',
saveAsCustomTemplateTitle: 'Save as Custom Template',
templateNameLabel: 'Template Name',
templateContentPreviewLabel: 'Template Content Preview',
templateNameMessage: 'Template name is required',
templateNamePlaceholder: 'Enter template name',
saveTemplate: 'Save',
templateDeletedSuccess: 'Template deleted successfully',
templateDeletedFailed: 'Failed to delete template',
templateSavedSuccess: 'Template saved successfully',
templateSavedFailed: 'Failed to save template',
// Template Sections
defaultTemplateTitle: 'Proposal Document Title',
introduction: '1. Introduction',
mainContent: '2. Main Content',
conclusion: '3. Conclusion',
technicalDocTitle: 'Academic Paper',
overview: '1. Abstract',
requirements: '2. Research Background',
architecture: '3. Research Methodology',
implementation: '4. Experimental Results',
testing: '5. Discussion and Analysis',
deployment: '6. Conclusion',
maintenance: '7. References',
meetingMinutesTitle: 'Meeting Minutes',
date: 'Date',
participants: 'Participants',
agenda: 'Agenda',
discussions: 'Discussion Content',
decisions: 'Decisions Made',
actionItems: 'Action Items',
nextMeeting: 'Next Meeting',
noTemplatesAvailable: 'No templates available',
confirmOperationTitle: 'Confirm Operation',
confirmOverwriteContent:
'This operation will overwrite the current content. Continue?',
continue: 'Continue',
// Model Configuration
modelConfigurationTitle: 'Model Configuration',
knowledgeBaseLabel: 'Knowledge Base',
knowledgeBasePlaceholder: 'Select a knowledge base',
similarityThresholdLabel: 'Similarity Threshold',
keywordSimilarityWeightLabel: 'Keyword Similarity Weight',
modelTemperatureLabel: 'Model Temperature',
fetchKnowledgeBaseFailed: 'Failed to fetch knowledge base list',
defaultKnowledgeBase: 'Default Knowledge Base',
noKnowledgeBaseFound: 'No knowledge base found',
technicalDocsKnowledgeBase: 'Technical Documents Knowledge Base',
aiRequestFailedError: 'AI request failed',
},
setting: {
profile: 'Profile',
profileDescription: 'Update your photo and personal details here.',

View File

@ -521,6 +521,78 @@ export default {
tavilyApiKeyMessage: '請輸入你的 Tavily API Key',
tavilyApiKeyHelp: '如何獲取?',
},
write: {
writeDocument: '文件撰寫',
writePlaceholder: '請輸入文件內容...',
save: '匯出為 Word',
templateList: '模板清單',
defaultTemplate: '項目申請書',
technicalDoc: '學術論文',
meetingMinutes: '會議紀要',
select: '選擇',
aiAssistant: 'AI 助手',
askAI: '輸入您的問題',
edit: '編輯模式',
split: '分屏模式',
preview: '預覽模式',
previewPlaceholder: '請輸入文件內容...',
saveCurrentAsTemplate: '將當前內容保存為模板',
delete: '刪除',
customTemplateMarker: '自訂模板',
confirmDeleteTemplate: '確認刪除模板?',
cancel: '取消',
confirm: '確認',
saveAsCustomTemplateTitle: '保存為自訂模板',
templateNameLabel: '模板名稱',
templateContentPreviewLabel: '模板內容預覽',
templateNameMessage: '模板名稱為必填項',
templateNamePlaceholder: '請輸入模板名稱',
saveTemplate: '保存',
templateDeletedSuccess: '模板刪除成功',
templateDeletedFailed: '模板刪除失敗',
templateSavedSuccess: '模板保存成功',
templateSavedFailed: '模板保存失敗',
// 模板相關
defaultTemplateTitle: '申請書文件標題',
introduction: '1. 引言',
mainContent: '2. 主要內容',
conclusion: '3. 結論',
technicalDocTitle: '學術論文',
overview: '1. 摘要',
requirements: '2. 研究背景',
architecture: '3. 研究方法',
implementation: '4. 實驗結果',
testing: '5. 討論分析',
deployment: '6. 結論',
maintenance: '7. 參考文獻',
meetingMinutesTitle: '會議紀要',
date: '日期',
participants: '與會人員',
agenda: '議程',
discussions: '討論內容',
decisions: '決議事項',
actionItems: '行動項目',
nextMeeting: '下次會議',
noTemplatesAvailable: '沒有可用模板',
confirmOperationTitle: '確認操作',
confirmOverwriteContent: '此操作將覆蓋當前編輯內容,是否繼續?',
continue: '繼續',
// 模型配置相關
modelConfigurationTitle: '模型配置',
knowledgeBaseLabel: '知識庫',
knowledgeBasePlaceholder: '選擇知識庫',
similarityThresholdLabel: '相似度閾值',
keywordSimilarityWeightLabel: '關鍵詞相似度權重',
modelTemperatureLabel: '模型溫度',
fetchKnowledgeBaseFailed: '獲取知識庫列表失敗',
defaultKnowledgeBase: '預設知識庫',
noKnowledgeBaseFound: '未找到知識庫',
technicalDocsKnowledgeBase: '技術文件知識庫',
aiRequestFailedError: '問答模型請求失敗',
},
setting: {
profile: '概述',
profileDescription: '在此更新您的照片和個人詳細信息。',

View File

@ -570,7 +570,7 @@ General实体和关系提取提示来自 GitHub - microsoft/graphrag基于
templateSavedSuccess: '模板保存成功',
templateSavedFailed: '模板保存失败',
// 模板标题和内容
// 模板相关
defaultTemplateTitle: '申报书文档标题',
introduction: '1. 引言',
mainContent: '2. 主要内容',
@ -592,6 +592,9 @@ General实体和关系提取提示来自 GitHub - microsoft/graphrag基于
actionItems: '行动项',
nextMeeting: '下次会议',
noTemplatesAvailable: "没有可用模板",
confirmOperationTitle: "确认操作",
confirmOverwriteContent: "此操作会覆盖当前编辑内容,是否继续?",
continue: "继续",
// 模型配置相关
modelConfigurationTitle: "模型配置",
knowledgeBaseLabel: "知识库",

View File

@ -283,10 +283,36 @@ const Write = () => {
// 当用户主动选择一个模板时,用模板内容覆盖当前编辑器内容
const handleTemplateSelect = (templateId: string) => {
setSelectedTemplate(templateId);
const item = templates.find((t) => t.id === templateId);
if (item) {
setContent(item.content); // 这会覆盖当前内容,并触发上面的 useEffect 保存为新的草稿
// 查找将要应用的模板
const itemToApply = templates.find((t) => t.id === templateId);
if (!itemToApply) return; // 如果找不到模板,则不执行任何操作
// 如果当前内容不为空,或者当前选择的模板不是即将应用的模板并且即将应用的内容与当前内容不同时,才显示提示框
if (
content.trim() !== '' &&
selectedTemplate !== templateId &&
content !== itemToApply.content
) {
Modal.confirm({
title: t('confirmOperationTitle', { defaultValue: '确认操作' }),
content: t('confirmOverwriteContent', {
defaultValue: '此操作会覆盖当前编辑内容,是否继续?',
}),
okText: t('continue', { defaultValue: '继续' }),
cancelText: t('cancel', { defaultValue: '取消' }),
onOk: () => {
setSelectedTemplate(templateId);
setContent(itemToApply.content); // 用户确认后,覆盖内容
},
onCancel: () => {
// 用户取消,不执行任何操作
// console.log('取消应用模板');
},
});
} else {
// 如果当前内容为空,或者选择的是同一个模板且内容未变,或者即将应用的内容与当前内容相同,则直接应用模板,不提示
setSelectedTemplate(templateId);
setContent(itemToApply.content);
}
};