Spaces:
Running
Running
Surf commited on
Commit ·
d62591f
1
Parent(s): a4a0104
保存正文版本后自动执行基础检查
Browse files49 unmodified lines5051525354555649 unmodified linesasync function openChapter(id){try{const d=await api('/projects/'+current.project_id+'/chapters/'+id);currentChapter=d.chapter;versions=d.versions||[];renderChapters();renderChapterEditor()}catch(e){msg('chapter-status',e.message,true)}}function renderChapterEditor(){if(!currentChapter){$('chapter-editor').innerHTML='<div class="notice">先选择或新建章节。</div>';return}$('chapter-editor').innerHTML=`<div class="panel"><div class="grid"><div class="field"><label>章节标题</label><input id="c-title" value="${esc(currentChapter.title)}"></div><div class="field"><label>所属卷</label><input id="c-volume" value="${esc(currentChapter.volume)}"></div><div class="field full"><label>本章目标</label><textarea id="c-goal">${esc(currentChapter.goal)}</textarea></div><div class="field full"><label>章纲</label><textarea id="c-outline">${esc(currentChapter.outline)}</textarea></div><div class="field full"><label>场景卡 JSON 数组</label><textarea class="json" id="c-scenes">${esc(JSON.stringify(currentChapter.scenes||[],null,2))}</textarea></div><div class="field full"><label>上一章摘要</label><textarea id="c-prev">${esc(currentChapter.previous_summary)}</textarea></div></div><div class="actions"><button class="btn primary" id="save-chapter">保存章纲与场景卡</button><button class="btn" id="run-check">基础连续性检查</button><span id="chapter-save-status" class="status"></span></div><div id="check-result"></div></div><div class="panel"><h3>正文版本</h3><div class="notice">推荐顺序:先由 Surf 生成章纲和场景卡,再由 Surf 生成正文并通过下方接口保存版本。</div><div class="field"><label>正文</label><textarea id="c-text" style="min-height:360px" placeholder="Surf 生成或你修改后的正文"></textarea></div><div class="grid"><div class="field"><label>本版本摘要</label><textarea id="c-summary"></textarea></div><div class="field"><label>修改说明</label><textarea id="c-notes"></textarea></div></div><div class="actions"><button class="btn green" id="save-version">保存为新版本</button><span id="version-status" class="status"></span></div><div><b>历史版本</b><div id="versions" class="version-list"></div></div><div class="grid"><div class="field"><label>对比版本 A</label><select id="compare-a"></select></div><div class="field"><label>对比版本 B</label><select id="compare-b"></select></div></div><div class="actions"><button class="btn" id="compare-version">比较版本</button></div><pre id="compare-result" style="white-space:pre-wrap;color:#cbd3e8;max-height:400px;overflow:auto"></pre></div>`;renderVersions();$('save-chapter').onclick=saveChapter;$('save-version').onclick=saveVersion;$('run-check').onclick=runCheck;$('compare-version').onclick=compareVersions}async function saveChapter(){try{let scenes;try{scenes=JSON.parse($('c-scenes').value||'[]')}catch(_){throw Error('场景卡 JSON 格式错误')}currentChapter=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id,{method:'PATCH',body:JSON.stringify({title:$('c-title').value,volume:$('c-volume').value,goal:$('c-goal').value,outline:$('c-outline').value,scenes,previous_summary:$('c-prev').value})});chapters=await api('/projects/'+current.project_id+'/chapters');renderChapters();msg('chapter-save-status','章节数据已保存到 R2')}catch(e){msg('chapter-save-status',e.message,true)}}async function saveVersion(){try{const v=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/versions',{method:'POST',body:JSON.stringify({text:$('c-text').value,summary:$('c-summary').value,notes:$('c-notes').value,created_by:'surf'})});versions=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/versions');currentChapter=(await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id)).chapter;renderVersions();msg('version-status','新版本已保存到 R2:'+v.version_id);chapters=await api('/projects/'+current.project_id+'/chapters');renderChapters()}catch(e){msg('version-status',e.message,true)}}function renderVersions(){const opts=versions.map(v=>`<option value="${v.version_id}">${new Date(v.created_at).toLocaleString()} · ${v.kind} · ${v.word_count}字</option>`).join('');$('versions').innerHTML=versions.length?versions.map(v=>`<button class="version-chip ${currentChapter.current_version_id===v.version_id?'active':''}" data-vid="${v.version_id}">${new Date(v.created_at).toLocaleString()} · ${v.word_count}字</button>`).join(''):'<span class="muted">还没有正文版本</span>';$('compare-a').innerHTML=opts;$('compare-b').innerHTML=opts;document.querySelectorAll('[data-vid]').forEach(b=>b.onclick=()=>loadVersion(b.dataset.vid))}async function loadVersion(id){const v=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/versions/'+id);$('c-text').value=v.text||'';$('c-summary').value=v.summary||'';$('c-notes').value=v.notes||''}async function compareVersions(){try{const a=$('compare-a').value,b=$('compare-b').value;if(!a||!b)return;const d=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/compare?a='+a+'&b='+b);$('compare-result').textContent='【版本 A】\n'+d.a.text+'\n\n【版本 B】\n'+d.b.text}catch(e){$('compare-result').textContent=e.message}}49 unmodified lines5051525354555649 unmodified linesasync function openChapter(id){try{const d=await api('/projects/'+current.project_id+'/chapters/'+id);currentChapter=d.chapter;versions=d.versions||[];renderChapters();renderChapterEditor()}catch(e){msg('chapter-status',e.message,true)}}function renderChapterEditor(){if(!currentChapter){$('chapter-editor').innerHTML='<div class="notice">先选择或新建章节。</div>';return}$('chapter-editor').innerHTML=`<div class="panel"><div class="grid"><div class="field"><label>章节标题</label><input id="c-title" value="${esc(currentChapter.title)}"></div><div class="field"><label>所属卷</label><input id="c-volume" value="${esc(currentChapter.volume)}"></div><div class="field full"><label>本章目标</label><textarea id="c-goal">${esc(currentChapter.goal)}</textarea></div><div class="field full"><label>章纲</label><textarea id="c-outline">${esc(currentChapter.outline)}</textarea></div><div class="field full"><label>场景卡 JSON 数组</label><textarea class="json" id="c-scenes">${esc(JSON.stringify(currentChapter.scenes||[],null,2))}</textarea></div><div class="field full"><label>上一章摘要</label><textarea id="c-prev">${esc(currentChapter.previous_summary)}</textarea></div></div><div class="actions"><button class="btn primary" id="save-chapter">保存章纲与场景卡</button><button class="btn" id="run-check">基础连续性检查</button><span id="chapter-save-status" class="status"></span></div><div id="check-result"></div></div><div class="panel"><h3>正文版本</h3><div class="notice">推荐顺序:先由 Surf 生成章纲和场景卡,再由 Surf 生成正文并通过下方接口保存版本。</div><div class="field"><label>正文</label><textarea id="c-text" style="min-height:360px" placeholder="Surf 生成或你修改后的正文"></textarea></div><div class="grid"><div class="field"><label>本版本摘要</label><textarea id="c-summary"></textarea></div><div class="field"><label>修改说明</label><textarea id="c-notes"></textarea></div></div><div class="actions"><button class="btn green" id="save-version">保存为新版本</button><span id="version-status" class="status"></span></div><div><b>历史版本</b><div id="versions" class="version-list"></div></div><div class="grid"><div class="field"><label>对比版本 A</label><select id="compare-a"></select></div><div class="field"><label>对比版本 B</label><select id="compare-b"></select></div></div><div class="actions"><button class="btn" id="compare-version">比较版本</button></div><pre id="compare-result" style="white-space:pre-wrap;color:#cbd3e8;max-height:400px;overflow:auto"></pre></div>`;renderVersions();$('save-chapter').onclick=saveChapter;$('save-version').onclick=saveVersion;$('run-check').onclick=runCheck;$('compare-version').onclick=compareVersions}async function saveChapter(){try{let scenes;try{scenes=JSON.parse($('c-scenes').value||'[]')}catch(_){throw Error('场景卡 JSON 格式错误')}currentChapter=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id,{method:'PATCH',body:JSON.stringify({title:$('c-title').value,volume:$('c-volume').value,goal:$('c-goal').value,outline:$('c-outline').value,scenes,previous_summary:$('c-prev').value})});chapters=await api('/projects/'+current.project_id+'/chapters');renderChapters();msg('chapter-save-status','章节数据已保存到 R2')}catch(e){msg('chapter-save-status',e.message,true)}}async function saveVersion(){try{const v=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/versions',{method:'POST',body:JSON.stringify({text:$('c-text').value,summary:$('c-summary').value,notes:$('c-notes').value,created_by:'surf'})});versions=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/versions');currentChapter=(await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id)).chapter;renderVersions();msg('version-status','新版本已保存到 R2:'+v.version_id);chapters=await api('/projects/'+current.project_id+'/chapters');renderChapters();await runCheck()}catch(e){msg('version-status',e.message,true)}}function renderVersions(){const opts=versions.map(v=>`<option value="${v.version_id}">${new Date(v.created_at).toLocaleString()} · ${v.kind} · ${v.word_count}字</option>`).join('');$('versions').innerHTML=versions.length?versions.map(v=>`<button class="version-chip ${currentChapter.current_version_id===v.version_id?'active':''}" data-vid="${v.version_id}">${new Date(v.created_at).toLocaleString()} · ${v.word_count}字</button>`).join(''):'<span class="muted">还没有正文版本</span>';$('compare-a').innerHTML=opts;$('compare-b').innerHTML=opts;document.querySelectorAll('[data-vid]').forEach(b=>b.onclick=()=>loadVersion(b.dataset.vid))}async function loadVersion(id){const v=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/versions/'+id);$('c-text').value=v.text||'';$('c-summary').value=v.summary||'';$('c-notes').value=v.notes||''}async function compareVersions(){try{const a=$('compare-a').value,b=$('compare-b').value;if(!a||!b)return;const d=await api('/projects/'+current.project_id+'/chapters/'+currentChapter.chapter_id+'/compare?a='+a+'&b='+b);$('compare-result').textContent='【版本 A】\n'+d.a.text+'\n\n【版本 B】\n'+d.b.text}catch(e){$('compare-result').textContent=e.message}}
fanqie/workspace.html+1-1