Skip to content

Commit 26999f7

Browse files
committed
修复卡片名与字段title之间不同步等bug
1 parent 0870488 commit 26999f7

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

backend/app/bootstrap/init_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ def init_workflows(db: Session):
481481
"nodes": [
482482
{"id": "read_stage", "type": "Card.Read", "params": {"target": "$self", "type_name": "阶段大纲"}, "position": {"x": 40, "y": 80}},
483483
{"id": "foreach_chapter_outline", "type": "List.ForEach", "params": {"listPath": "$.content.chapter_outline_list"}, "position": {"x": 460, "y": 80}},
484-
{"id": "upsert_outline", "type": "Card.UpsertChildByTitle", "params": {"cardType": "章节大纲", "title": "第{item.chapter_number}章 {item.title}", "useItemAsContent": True}, "position": {"x": 460, "y": 260}},
485-
{"id": "upsert_chapter", "type": "Card.UpsertChildByTitle", "params": {"cardType": "章节正文", "title": "第{item.chapter_number}章 {item.title}", "contentTemplate": {"volume_number": "{$.content.volume_number}", "stage_number": "{$.content.stage_number}", "chapter_number": "{item.chapter_number}", "title": "{item.title}", "entity_list": {"$toNameList": "item.entity_list"}, "content": ""}}, "position": {"x": 880, "y": 260}},
484+
{"id": "upsert_outline", "type": "Card.UpsertChildByTitle", "params": {"cardType": "章节大纲", "title": "{item.title}", "useItemAsContent": True}, "position": {"x": 460, "y": 260}},
485+
{"id": "upsert_chapter", "type": "Card.UpsertChildByTitle", "params": {"cardType": "章节正文", "title": "{item.title}", "contentTemplate": {"volume_number": "{$.content.volume_number}", "stage_number": "{$.content.stage_number}", "chapter_number": "{item.chapter_number}", "title": "{item.title}", "entity_list": {"$toNameList": "item.entity_list"}, "content": ""}}, "position": {"x": 880, "y": 260}},
486486
{"id": "clear_outline", "type": "Card.ModifyContent", "params": {"setPath": "$.content.chapter_outline_list", "setValue": []}, "position": {"x": 1300, "y": 170}}
487487
],
488488
"edges": [

frontend/src/renderer/src/components/cards/GenericCardEditor.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,18 @@ async function handleSave() {
517517
if (activeContentEditor.value && contentEditorRef.value) {
518518
try {
519519
isSaving.value = true
520+
// 在保存正文前先截取当前模板与旧值,避免保存正文时触发的 card 更新把本地模板重置为旧值
521+
const templateBeforeSave = localAiContextTemplate.value
522+
const prevTemplateOnCard = props.card.ai_context_template || ''
523+
520524
// 将当前标题传递给内容编辑器,由内容编辑器统一负责保存 title 与正文内容
521525
const savedContent = await contentEditorRef.value.handleSave(titleProxy.value)
522526
523527
// 如有上下文模板变更,单独保存 ai_context_template(不覆盖正文内容)
524-
if (localAiContextTemplate.value !== props.card.ai_context_template) {
528+
if (templateBeforeSave !== prevTemplateOnCard) {
525529
try {
526530
await cardStore.modifyCard(props.card.id, {
527-
ai_context_template: localAiContextTemplate.value,
531+
ai_context_template: templateBeforeSave,
528532
} as any)
529533
} catch {}
530534
}
@@ -537,15 +541,15 @@ async function handleSave() {
537541
projectId: projectStore.currentProject.id,
538542
title: titleProxy.value,
539543
content: savedContent,
540-
ai_context_template: localAiContextTemplate.value,
544+
ai_context_template: templateBeforeSave,
541545
})
542546
}
543547
} catch (e) {
544548
console.error('Failed to add version:', e)
545549
}
546550
547551
contentEditorDirty.value = false
548-
originalAiContextTemplate.value = localAiContextTemplate.value
552+
originalAiContextTemplate.value = templateBeforeSave
549553
lastSavedAt.value = new Date().toLocaleTimeString()
550554
ElMessage.success('保存成功')
551555
} catch (e) {

frontend/src/renderer/src/views/Editor.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,18 @@ async function renameCard(cardId: number, oldTitle: string) {
10451045
})
10461046
const newTitle = String(value).trim()
10471047
if (newTitle === oldTitle) return
1048-
await cardStore.modifyCard(cardId, { title: newTitle })
1048+
// 默认仅更新外壳 card.title
1049+
const card = (cards.value || []).find((c: any) => c.id === cardId) as any
1050+
const payload: any = { title: newTitle }
1051+
1052+
// 仅对章节大纲 / 章节正文做「标题字段与卡片名」的绑定优化
1053+
const typeName = card?.card_type?.name || ''
1054+
if ((typeName === '章节大纲' || typeName === '章节正文') && card?.content) {
1055+
const content: any = { ...(card.content as any) }
1056+
content.title = newTitle
1057+
payload.content = content
1058+
}
1059+
await cardStore.modifyCard(cardId, payload)
10491060
ElMessage.success('已重命名')
10501061
} catch {
10511062
// 用户取消或失败

0 commit comments

Comments
 (0)