root commited on
Commit
fbe6540
·
1 Parent(s): a7fab52

UI: 手册置顶、AI 规范前置、素材只显示清洗后版本、移除批次导出

Browse files
fanqie/dist/index.html CHANGED
@@ -8,7 +8,7 @@
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
- <script type="module" crossorigin src="/assets/index-C6qtt_22.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-B0JKZHmZ.css">
13
  </head>
14
  <body>
 
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
+ <script type="module" crossorigin src="/assets/index-D2be1U5S.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-B0JKZHmZ.css">
13
  </head>
14
  <body>
public/assets/{index-C6qtt_22.js → index-D2be1U5S.js} RENAMED
The diff for this file is too large to render. See raw diff
 
public/index.html CHANGED
@@ -8,7 +8,7 @@
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
- <script type="module" crossorigin src="/assets/index-C6qtt_22.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-B0JKZHmZ.css">
13
  </head>
14
  <body>
 
8
  <title>小说写作台</title>
9
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='12' fill='%23b8432f'/%3E%3Ctext x='32' y='44' font-size='34' text-anchor='middle' fill='%23fff' font-family='serif'%3E%E6%96%87%3C/text%3E%3C/svg%3E" />
10
  <script>try{var t=localStorage.getItem('xs_theme');if(t==='night')document.documentElement.dataset.theme='night'}catch(e){}</script>
11
+ <script type="module" crossorigin src="/assets/index-D2be1U5S.js"></script>
12
  <link rel="stylesheet" crossorigin href="/assets/index-B0JKZHmZ.css">
13
  </head>
14
  <body>
ui-src/src/App.tsx CHANGED
@@ -62,10 +62,10 @@ function LockScreen({ onOpen }: { onOpen: () => void }) {
62
  }
63
 
64
  const ROOMS = [
 
65
  { id: 'shelf', match: ['', 'shelf', 'book'], label: '书房', icon: BookOpen },
66
  { id: 'library', match: ['library'], label: '素材馆', icon: Library },
67
  { id: 'sources', match: ['sources'], label: '采集', icon: Radio },
68
- { id: 'guide', match: ['guide'], label: '手册', icon: Compass },
69
  ]
70
 
71
  function Shell({ onLock }: { onLock: () => void }) {
@@ -78,7 +78,7 @@ function Shell({ onLock }: { onLock: () => void }) {
78
  meta?.setAttribute('content', night ? '#1a1917' : '#f3efe6')
79
  }, [night])
80
  const head = parts[0] || ''
81
- const room = ROOMS.find(r => r.match.includes(head)) || ROOMS[0]
82
  useEffect(() => {
83
  const titles: Record<string, string> = { shelf: '书房', library: '素材馆', sources: '素材采集', guide: '写作手册' }
84
  if (room.id !== 'shelf' || head !== 'book') document.title = `${titles[room.id]} · 小说写作台`
 
62
  }
63
 
64
  const ROOMS = [
65
+ { id: 'guide', match: ['guide'], label: '手册', icon: Compass },
66
  { id: 'shelf', match: ['', 'shelf', 'book'], label: '书房', icon: BookOpen },
67
  { id: 'library', match: ['library'], label: '素材馆', icon: Library },
68
  { id: 'sources', match: ['sources'], label: '采集', icon: Radio },
 
69
  ]
70
 
71
  function Shell({ onLock }: { onLock: () => void }) {
 
78
  meta?.setAttribute('content', night ? '#1a1917' : '#f3efe6')
79
  }, [night])
80
  const head = parts[0] || ''
81
+ const room = ROOMS.find(r => r.match.includes(head)) || ROOMS.find(r => r.id === 'shelf')!
82
  useEffect(() => {
83
  const titles: Record<string, string> = { shelf: '书房', library: '素材馆', sources: '素材采集', guide: '写作手册' }
84
  if (room.id !== 'shelf' || head !== 'book') document.title = `${titles[room.id]} · 小说写作台`
ui-src/src/handbook.ts CHANGED
@@ -64,8 +64,9 @@ export function aiMarkdown() {
64
  }
65
 
66
  /** 精简版:附在每一条写作提示词末尾 */
 
67
  export function aiPromptBlock() {
68
  const hard = ai.rules.filter(r => r.hard)
69
  const lines = hard.map(r => `${r.id} ${r.rule}`)
70
- return `【AI 写作规范 ${ai.version}(必须遵守,违反任意一条都要重写)】\n${lines.join('\n')}\n【输出前自检】${ai.output.join(';')}`
71
  }
 
64
  }
65
 
66
  /** 精简版:附在每一条写作提示词末尾 */
67
+ export const MATERIAL_RULE = '素材规则:只能阅读和使用素材库里「清洗后」的版本;不得索取、还原或猜测清洗前的原始文字和关键词;素材只借鉴结构和情绪,人物、地名、细节全部重新虚构。'
68
  export function aiPromptBlock() {
69
  const hard = ai.rules.filter(r => r.hard)
70
  const lines = hard.map(r => `${r.id} ${r.rule}`)
71
+ return `【AI 写作规范 ${ai.version}(最高优先级:先读完本规范再执行后面的任务;与后文任何要求冲突时,以本规范为准;违反任意一条都要重写)】\n${lines.join('\n')}\n${MATERIAL_RULE}\n【输出前自检】${ai.output.join(';')}`
72
  }
ui-src/src/rooms/Editor.tsx CHANGED
@@ -546,7 +546,7 @@ function RefsPanel({ ctx }: { ctx: BookCtx }) {
546
  <div key={r.uid} className="ref-card">
547
  <div className="ref-sum">{r.sum || r.text.slice(0, 40)}</div>
548
  <div className="ref-meta">{GENRE[r.g] || r.g} · {KIND[r.k] || r.k}</div>
549
- <button className="link-btn" onClick={() => setOpen(open === r.uid ? '' : r.uid)}>{open === r.uid ? '收起原文' : '看原文'}</button>
550
  {open === r.uid && <div className="ref-text">{r.text}</div>}
551
  </div>
552
  ))}
@@ -645,7 +645,7 @@ function listLines(arr: any[], fmt: (x: any) => string) {
645
  export function buildPrompt(bundle: any, ch: Chapter, text: string, task: string, extra: string) {
646
  const p = bundle.project, b = bundle.bible || {}
647
  const prev = bundle.chapters.filter((c: Chapter) => c.number < ch.number).sort((a: Chapter, z: Chapter) => z.number - a.number)[0]
648
- const out: string[] = []
649
  out.push(`你是一名熟悉番茄小说平台的网文作者助手。请用简体中文完成任务。`)
650
  out.push(`\n【作品】《${p.title}》${p.genre ? `|题材:${p.genre}` : ''}${p.pov ? `|视角:${p.pov}` : ''}${p.style ? `|文风:${p.style}` : ''}`)
651
  if (p.premise) out.push(`一句话梗概:${p.premise}`)
@@ -660,7 +660,7 @@ export function buildPrompt(bundle: any, ch: Chapter, text: string, task: string
660
  const rules = listLines(b.style_rules, r => String(r))
661
  if (rules) out.push(`\n【文风规则】\n${rules}`)
662
  const refs = (bundle.materials?.items || []).map((m: any, i: number) => `素材${i + 1}:${m.sum || ''}`).join('\n')
663
- if (refs && (task === 'draft' || task === 'next')) out.push(`\n【参考素材(只借鉴情节结构,人物、地点、细节必须全部虚构化,不得照搬原文)】\n${refs}`)
664
  out.push(`\n【当前章节】第${ch.number}章 ${ch.title || ''}${ch.volume ? `(${ch.volume})` : ''}`)
665
  if (prev?.previous_summary) out.push(`前情提要:${prev.previous_summary}`)
666
  if (ch.goal) out.push(`本章目标:${ch.goal}`)
@@ -673,7 +673,6 @@ export function buildPrompt(bundle: any, ch: Chapter, text: string, task: string
673
  if (task === 'polish') out.push(`\n【待润色正文】\n${body}\n\n【任务】在不改变情节和人物关系的前提下润色:删去冗余、拆分过长段落、让对白更自然、细节更具体。直接输出润色后的全文。`)
674
  if (task === 'review') out.push(`\n【本章正文】\n${body}\n\n【任务】对照作品圣经做连续性审读,逐条列出:人设前后不一致、时间线矛盾、人物知道了不该知道的事、伏笔遗漏、逻辑漏洞。每条注明原文位置和修改建议。`)
675
  if (task === 'next') out.push(`\n【本章结尾】\n……${body.slice(-1200)}\n\n【任务】为第${ch.number + 1}章写章纲:本章目标、3 个场景(每个场景写清冲突和结果)、章末钩子。`)
676
- out.push(`\n${aiPromptBlock()}`)
677
  if (extra.trim()) out.push(`\n【补充要求】${extra.trim()}`)
678
  return out.join('\n')
679
  }
 
546
  <div key={r.uid} className="ref-card">
547
  <div className="ref-sum">{r.sum || r.text.slice(0, 40)}</div>
548
  <div className="ref-meta">{GENRE[r.g] || r.g} · {KIND[r.k] || r.k}</div>
549
+ <button className="link-btn" onClick={() => setOpen(open === r.uid ? '' : r.uid)}>{open === r.uid ? '收起正文' : '看清洗后正文'}</button>
550
  {open === r.uid && <div className="ref-text">{r.text}</div>}
551
  </div>
552
  ))}
 
645
  export function buildPrompt(bundle: any, ch: Chapter, text: string, task: string, extra: string) {
646
  const p = bundle.project, b = bundle.bible || {}
647
  const prev = bundle.chapters.filter((c: Chapter) => c.number < ch.number).sort((a: Chapter, z: Chapter) => z.number - a.number)[0]
648
+ const out: string[] = [aiPromptBlock(), '']
649
  out.push(`你是一名熟悉番茄小说平台的网文作者助手。请用简体中文完成任务。`)
650
  out.push(`\n【作品】《${p.title}》${p.genre ? `|题材:${p.genre}` : ''}${p.pov ? `|视角:${p.pov}` : ''}${p.style ? `|文风:${p.style}` : ''}`)
651
  if (p.premise) out.push(`一句话梗概:${p.premise}`)
 
660
  const rules = listLines(b.style_rules, r => String(r))
661
  if (rules) out.push(`\n【文风规则】\n${rules}`)
662
  const refs = (bundle.materials?.items || []).map((m: any, i: number) => `素材${i + 1}:${m.sum || ''}`).join('\n')
663
+ if (refs && (task === 'draft' || task === 'next')) out.push(`\n【参考素材(均为清洗后版本,只借鉴情节结构,人物、地点、细节必须全部虚构化,不得照搬)】\n${refs}`)
664
  out.push(`\n【当前章节】第${ch.number}章 ${ch.title || ''}${ch.volume ? `(${ch.volume})` : ''}`)
665
  if (prev?.previous_summary) out.push(`前情提要:${prev.previous_summary}`)
666
  if (ch.goal) out.push(`本章目标:${ch.goal}`)
 
673
  if (task === 'polish') out.push(`\n【待润色正文】\n${body}\n\n【任务】在不改变情节和人物关系的前提下润色:删去冗余、拆分过长段落、让对白更自然、细节更具体。直接输出润色后的全文。`)
674
  if (task === 'review') out.push(`\n【本章正文】\n${body}\n\n【任务】对照作品圣经做连续性审读,逐条列出:人设前后不一致、时间线矛盾、人物知道了不该知道的事、伏笔遗漏、逻辑漏洞。每条注明原文位置和修改建议。`)
675
  if (task === 'next') out.push(`\n【本章结尾】\n……${body.slice(-1200)}\n\n【任务】为第${ch.number + 1}章写章纲:本章目标、3 个场景(每个场景写清冲突和结果)、章末钩子。`)
 
676
  if (extra.trim()) out.push(`\n【补充要求】${extra.trim()}`)
677
  return out.join('\n')
678
  }
ui-src/src/rooms/Library.tsx CHANGED
@@ -1,26 +1,26 @@
1
  import React, { useEffect, useMemo, useState } from 'react'
2
  import { aiPromptBlock } from '../handbook'
3
  import {
4
- Search, SlidersHorizontal, ShoppingBasket, Shuffle, BookmarkPlus, Copy, Download, Sparkles, RefreshCw, ArrowLeft, Check, X, Trash2,
5
- Layers, Archive, FileText, Plus, Quote, Library as LibIcon,
6
  } from 'lucide-react'
7
- import { download, Material, materialsApi, projectsApi, Project, get } from '../api'
8
  import { copyText, cx, fmtDate, fmtNum, go, GENRE, KIND, DECISION, ROLE, useAsync, useBasket, useDebounced, writeBasket, readBasket } from '../lib'
9
  import { Drawer, Empty, ErrorNote, Loading, Modal, Pager, Segmented, Spinner, Stars, Tabs, Tag, useToast } from '../ui'
10
  import { toRef } from './Bible'
11
 
12
- type LTab = 'materials' | 'motifs' | 'compose' | 'batches'
13
  const kindRole = (k?: string) => ({ story: 'main', plot: 'twist', emotion: 'emotion', quote: 'hook', qa: 'detail' } as any)[k || ''] || 'main'
14
 
15
  export function basketAdd(m: any, role?: string) {
16
  const cur = readBasket()
17
  if (cur.some(x => x.uid === m.uid)) return false
18
- writeBasket([...cur, { ...m, edits: undefined, role: role || kindRole(m.k) }])
19
  return true
20
  }
21
 
22
  export default function LibraryRoom({ tab, arg }: { tab: string; arg: string }) {
23
- const t = (['materials', 'motifs', 'compose', 'batches'].includes(tab) ? tab : 'materials') as LTab
24
  const [basket] = useBasket()
25
  const [basketOpen, setBasketOpen] = useState(false)
26
  const [openUid, setOpenUid] = useState<string>('')
@@ -33,6 +33,7 @@ export default function LibraryRoom({ tab, arg }: { tab: string; arg: string })
33
  <div>
34
  <div className="eyebrow"><LibIcon size={14} />素材馆</div>
35
  <h1 className="room-title serif">从真实故事里找灵感</h1>
 
36
  </div>
37
  <button className={cx('basket-btn', basket.length > 0 && 'has')} onClick={() => setBasketOpen(true)}>
38
  <ShoppingBasket size={17} />素材篮{basket.length > 0 && <b>{basket.length}</b>}
@@ -42,13 +43,11 @@ export default function LibraryRoom({ tab, arg }: { tab: string; arg: string })
42
  { id: 'materials', label: '素材' },
43
  { id: 'motifs', label: '母题' },
44
  { id: 'compose', label: '组稿' },
45
- { id: 'batches', label: '批次导出' },
46
  ]} />
47
  <div className="room-body">
48
  {t === 'materials' && <MaterialsTab onOpen={setOpenUid} />}
49
  {t === 'motifs' && <MotifsTab id={arg} onOpen={setOpenUid} />}
50
  {t === 'compose' && <ComposeTab onOpen={setOpenUid} />}
51
- {t === 'batches' && <BatchesTab />}
52
  </div>
53
  <MaterialDrawer uid={openUid} onClose={closeItem} />
54
  <BasketDrawer open={basketOpen} onClose={() => setBasketOpen(false)} onOpen={uid => { setBasketOpen(false); setOpenUid(uid) }} />
@@ -93,7 +92,7 @@ function MaterialsTab({ onOpen }: { onOpen: (uid: string) => void }) {
93
  </div>
94
  <label className="search-row">
95
  <Search size={15} />
96
- <input className="input bare" value={w} onChange={e => setW(e.target.value)} placeholder={mode === 'search' ? '写一句想法,例如:婆婆偷偷改了遗嘱' : '摘要或原文里的关键词'} />
97
  {w && <button className="icon-btn sm" onClick={() => setW('')}><X size={13} /></button>}
98
  </label>
99
  {mode === 'search' && <p className="muted small-note">联想搜索会自动识别母题,并按相关程度排序。</p>}
@@ -116,7 +115,7 @@ function MaterialsTab({ onOpen }: { onOpen: (uid: string) => void }) {
116
  </FilterGroup>
117
  <FilterGroup label="其他">
118
  <label className="check"><input type="checkbox" checked={carded} onChange={e => setCarded(e.target.checked)} />只看有拆解卡的</label>
119
- <label className="check"><input type="checkbox" checked={short} onChange={e => setShort(e.target.checked)} />原文 800 字以内</label>
120
  </FilterGroup>
121
  </>}
122
  {mode === 'search' && (
@@ -206,10 +205,9 @@ function MaterialDrawer({ uid, onClose }: { uid: string; onClose: () => void })
206
  const [err, setErr] = useState('')
207
  const [basket] = useBasket()
208
  const [pickOpen, setPickOpen] = useState(false)
209
- const [showEdits, setShowEdits] = useState(false)
210
  useEffect(() => {
211
  if (!uid) return
212
- setItem(null); setErr(''); setShowEdits(false)
213
  materialsApi.item(uid).then(setItem, e => setErr(e.message))
214
  }, [uid])
215
  const inBasket = basket.some(x => x.uid === uid)
@@ -217,7 +215,7 @@ function MaterialDrawer({ uid, onClose }: { uid: string; onClose: () => void })
217
  return (
218
  <Drawer open={!!uid} onClose={onClose} width={680} title={item ? <span className="row gap-s"><Tag>{GENRE[item.g] || item.g}</Tag><Tag>{KIND[item.k] || item.k}</Tag>{item.q ? <Stars n={item.q} /> : null}</span> : '素材'}
219
  footer={item && <>
220
- <button className="btn ghost" onClick={async () => { await copyText(item.text); toast('原文已复制', 'ok') }}><Copy size={14} />复制原文</button>
221
  <button className="btn ghost" disabled={inBasket} onClick={() => { basketAdd(item); toast('已放进素材篮', 'ok') }}>{inBasket ? <><Check size={14} />已在素材篮</> : <><ShoppingBasket size={14} />放进素材篮</>}</button>
222
  <button className="btn primary" onClick={() => setPickOpen(true)}><BookmarkPlus size={14} />设为作品参考</button>
223
  </>}>
@@ -244,13 +242,9 @@ function MaterialDrawer({ uid, onClose }: { uid: string; onClose: () => void })
244
  )}
245
 
246
  <section className="md-text">
247
- <div className="row between"><h4>原文</h4><span className="muted">{item.text.length} 字</span></div>
248
  <div className="reader-text">{item.text}</div>
249
- {item.edits?.length ? <>
250
- <button className="link-btn" onClick={() => setShowEdits(v => !v)}>{showEdits ? '收起' : '查看'}清洗时的 {item.edits.length} 处改动</button>
251
- {showEdits && <div className="edits">{item.why && <p className="muted">{item.why}</p>}{item.edits.map(([a, b], i) => <div key={i} className="edit-row"><del>{a}</del><span>→</span><ins>{b}</ins></div>)}</div>}
252
- </> : null}
253
- <p className="muted small-note">素材只用来借鉴结构和情绪。写进小说时,人名、地名、职业和细节都要换成你自己的。</p>
254
  </section>
255
  </div>
256
  )}
@@ -512,7 +506,7 @@ function ComposeTab({ onOpen }: { onOpen: (uid: string) => void }) {
512
  }
513
 
514
  function composePrompt(idea: string, res: any, picks: Record<string, any>) {
515
- const out: string[] = []
516
  out.push('你是一名熟悉番茄小说平台的网文作者。请根据下面的创意和参考素材,设计一个原创故事。')
517
  if (idea.trim()) out.push(`\n【创意】${idea.trim()}`)
518
  if (res.motifs?.length) out.push(`【母题】${res.motifs.map((m: any) => m.t).join('、')}`)
@@ -528,55 +522,5 @@ function composePrompt(idea: string, res: any, picks: Record<string, any>) {
528
  out.push(`- ${ROLE[r].t}:${bits.join('|')}`)
529
  }
530
  out.push('\n【任务】\n1. 给出书名 3 个、一句话梗概。\n2. 主角和主要人物卡(姓名、身份、想要、害怕、秘密),全部为成年人。\n3. 开篇第一段(300 字内抛出冲突)。\n4. 全书大纲:按「开篇钩子 → 困境加码 → 主角行动 → 反转 → 高潮 → 收尾」写。\n5. 埋 3 条伏笔并说明回收位置。')
531
- out.push(`\n${aiPromptBlock()}`)
532
  return out.join('\n')
533
  }
534
-
535
- /* ================= 批次 ================= */
536
- function BatchesTab() {
537
- const toast = useToast()
538
- const man = useAsync(() => get<any>('/fanqie/api/batches/manifest'), [])
539
- const [page, setPage] = useState(1)
540
- const [q, setQ] = useState('')
541
- const [busy, setBusy] = useState('')
542
- const dl = async (url: string, name: string) => {
543
- setBusy(name)
544
- try { await download(url, name) } catch (e: any) { toast(e.message, 'err') } finally { setBusy('') }
545
- }
546
- if (man.error) return <ErrorNote error={man.error} onRetry={man.reload} />
547
- if (!man.data) return <Loading />
548
- const d = man.data
549
- const list: any[] = d.batches || []
550
- const n = Number(q)
551
- const filtered = q ? list.filter(b => b.number === n || b.first_uid?.includes(q) || b.last_uid?.includes(q)) : list
552
- const size = 40
553
- return (
554
- <div className="batches">
555
- <div className="sheet batch-intro">
556
- <div className="bi-text">
557
- <h2 className="sheet-title serif"><Archive size={17} />把清洗好的素材分批导出</h2>
558
- <p className="page-sub">共 {fmtNum(d.source?.total_items)} 条可用素材({d.source?.selection}),每批 {d.batch_size} 条,共 {fmtNum(d.total_batches)} 批。可以逐批交给 AI 做二次加工。</p>
559
- <p className="muted small-note">数据更新于 {fmtDate(d.source?.mtime)}</p>
560
- </div>
561
- <div className="bi-actions">
562
- <button className="btn primary" onClick={() => dl('/fanqie/api/batches/all.zip', 'xiaoshuo-material-batches.zip')} disabled={!!busy}><Download size={14} />{busy === 'xiaoshuo-material-batches.zip' ? '正在打包…' : '下载全部(zip)'}</button>
563
- <button className="btn ghost" onClick={() => dl('/fanqie/api/batches/prompt', 'batch_prompt.md')} disabled={!!busy}><FileText size={14} />下载处理提示词</button>
564
- </div>
565
- </div>
566
- <div className="row gap">
567
- <label className="search-row grow"><Search size={15} /><input className="input bare" value={q} onChange={e => { setQ(e.target.value.trim()); setPage(1) }} placeholder="输入批次号或素材编号" /></label>
568
- </div>
569
- <div className="batch-table">
570
- {filtered.slice((page - 1) * size, page * size).map(b => (
571
- <div key={b.id} className="batch-row">
572
- <span className="br-n">第 {b.number} 批</span>
573
- <span className="br-range muted">第 {b.start}–{b.end} 条 · {b.count} 条</span>
574
- <span className="br-uid muted">{b.first_uid} … {b.last_uid}</span>
575
- <button className="btn small ghost push" onClick={() => dl(`/fanqie/api/batches/${b.filename}`, b.filename)} disabled={!!busy}>{busy === b.filename ? <Spinner size={12} /> : <Download size={13} />}下载</button>
576
- </div>
577
- ))}
578
- </div>
579
- <Pager page={page} total={filtered.length} size={size} onChange={setPage} />
580
- </div>
581
- )
582
- }
 
1
  import React, { useEffect, useMemo, useState } from 'react'
2
  import { aiPromptBlock } from '../handbook'
3
  import {
4
+ Search, SlidersHorizontal, ShoppingBasket, Shuffle, BookmarkPlus, Copy, Sparkles, RefreshCw, ArrowLeft, Check, X, Trash2,
5
+ Layers, Plus, Quote, Library as LibIcon,
6
  } from 'lucide-react'
7
+ import { Material, materialsApi, projectsApi, Project } from '../api'
8
  import { copyText, cx, fmtDate, fmtNum, go, GENRE, KIND, DECISION, ROLE, useAsync, useBasket, useDebounced, writeBasket, readBasket } from '../lib'
9
  import { Drawer, Empty, ErrorNote, Loading, Modal, Pager, Segmented, Spinner, Stars, Tabs, Tag, useToast } from '../ui'
10
  import { toRef } from './Bible'
11
 
12
+ type LTab = 'materials' | 'motifs' | 'compose'
13
  const kindRole = (k?: string) => ({ story: 'main', plot: 'twist', emotion: 'emotion', quote: 'hook', qa: 'detail' } as any)[k || ''] || 'main'
14
 
15
  export function basketAdd(m: any, role?: string) {
16
  const cur = readBasket()
17
  if (cur.some(x => x.uid === m.uid)) return false
18
+ writeBasket([...cur, { ...m, edits: undefined, why: undefined, role: role || kindRole(m.k) }])
19
  return true
20
  }
21
 
22
  export default function LibraryRoom({ tab, arg }: { tab: string; arg: string }) {
23
+ const t = (['materials', 'motifs', 'compose'].includes(tab) ? tab : 'materials') as LTab
24
  const [basket] = useBasket()
25
  const [basketOpen, setBasketOpen] = useState(false)
26
  const [openUid, setOpenUid] = useState<string>('')
 
33
  <div>
34
  <div className="eyebrow"><LibIcon size={14} />素材馆</div>
35
  <h1 className="room-title serif">从真实故事里找灵感</h1>
36
+ <p className="muted small-note lib-rule">素材馆只提供清洗后的素材。阅读素材、交给 AI 时都只能用清洗后的版本。</p>
37
  </div>
38
  <button className={cx('basket-btn', basket.length > 0 && 'has')} onClick={() => setBasketOpen(true)}>
39
  <ShoppingBasket size={17} />素材篮{basket.length > 0 && <b>{basket.length}</b>}
 
43
  { id: 'materials', label: '素材' },
44
  { id: 'motifs', label: '母题' },
45
  { id: 'compose', label: '组稿' },
 
46
  ]} />
47
  <div className="room-body">
48
  {t === 'materials' && <MaterialsTab onOpen={setOpenUid} />}
49
  {t === 'motifs' && <MotifsTab id={arg} onOpen={setOpenUid} />}
50
  {t === 'compose' && <ComposeTab onOpen={setOpenUid} />}
 
51
  </div>
52
  <MaterialDrawer uid={openUid} onClose={closeItem} />
53
  <BasketDrawer open={basketOpen} onClose={() => setBasketOpen(false)} onOpen={uid => { setBasketOpen(false); setOpenUid(uid) }} />
 
92
  </div>
93
  <label className="search-row">
94
  <Search size={15} />
95
+ <input className="input bare" value={w} onChange={e => setW(e.target.value)} placeholder={mode === 'search' ? '写一句想法,例如:婆婆偷偷改了遗嘱' : '摘要或正文里的关键词'} />
96
  {w && <button className="icon-btn sm" onClick={() => setW('')}><X size={13} /></button>}
97
  </label>
98
  {mode === 'search' && <p className="muted small-note">联想搜索会自动识别母题,并按相关程度排序。</p>}
 
115
  </FilterGroup>
116
  <FilterGroup label="其他">
117
  <label className="check"><input type="checkbox" checked={carded} onChange={e => setCarded(e.target.checked)} />只看有拆解卡的</label>
118
+ <label className="check"><input type="checkbox" checked={short} onChange={e => setShort(e.target.checked)} />正文 800 字以内</label>
119
  </FilterGroup>
120
  </>}
121
  {mode === 'search' && (
 
205
  const [err, setErr] = useState('')
206
  const [basket] = useBasket()
207
  const [pickOpen, setPickOpen] = useState(false)
 
208
  useEffect(() => {
209
  if (!uid) return
210
+ setItem(null); setErr('')
211
  materialsApi.item(uid).then(setItem, e => setErr(e.message))
212
  }, [uid])
213
  const inBasket = basket.some(x => x.uid === uid)
 
215
  return (
216
  <Drawer open={!!uid} onClose={onClose} width={680} title={item ? <span className="row gap-s"><Tag>{GENRE[item.g] || item.g}</Tag><Tag>{KIND[item.k] || item.k}</Tag>{item.q ? <Stars n={item.q} /> : null}</span> : '素材'}
217
  footer={item && <>
218
+ <button className="btn ghost" onClick={async () => { await copyText(item.text); toast('清洗后正文已复制', 'ok') }}><Copy size={14} />复制正文</button>
219
  <button className="btn ghost" disabled={inBasket} onClick={() => { basketAdd(item); toast('已放进素材篮', 'ok') }}>{inBasket ? <><Check size={14} />已在素材篮</> : <><ShoppingBasket size={14} />放进素材篮</>}</button>
220
  <button className="btn primary" onClick={() => setPickOpen(true)}><BookmarkPlus size={14} />设为作品参考</button>
221
  </>}>
 
242
  )}
243
 
244
  <section className="md-text">
245
+ <div className="row between"><h4>清洗后正文</h4><span className="muted">{item.text.length} 字</span></div>
246
  <div className="reader-text">{item.text}</div>
247
+ <p className="muted small-note">这里显示的是清洗后的版本。阅读素材、交给 AI 时都只能用清洗后的素材,不看也不还原清洗前的文字和关键词。素材只用来借鉴结构和情绪,写进小说时,人名、地名、职业和细节都要换成你自己的。</p>
 
 
 
 
248
  </section>
249
  </div>
250
  )}
 
506
  }
507
 
508
  function composePrompt(idea: string, res: any, picks: Record<string, any>) {
509
+ const out: string[] = [aiPromptBlock(), '']
510
  out.push('你是一名熟悉番茄小说平台的网文作者。请根据下面的创意和参考素材,设计一个原创故事。')
511
  if (idea.trim()) out.push(`\n【创意】${idea.trim()}`)
512
  if (res.motifs?.length) out.push(`【母题】${res.motifs.map((m: any) => m.t).join('、')}`)
 
522
  out.push(`- ${ROLE[r].t}:${bits.join('|')}`)
523
  }
524
  out.push('\n【任务】\n1. 给出书名 3 个、一句话梗概。\n2. 主角和主要人物卡(姓名、身份、想要、害怕、秘密),全部为成年人。\n3. 开篇第一段(300 字内抛出冲突)。\n4. 全书大纲:按「开篇钩子 → 困境加码 → 主角行动 → 反转 → 高潮 → 收尾」写。\n5. 埋 3 条伏笔并说明回收位置。')
 
525
  return out.join('\n')
526
  }