|
@@ -53,6 +53,18 @@ function outlineChapterFromDb(dbChapter: any) {
|
|
|
// ============ 存储类 ============
|
|
// ============ 存储类 ============
|
|
|
|
|
|
|
|
export class BookStore {
|
|
export class BookStore {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 安全解析JSON
|
|
|
|
|
+ */
|
|
|
|
|
+ private safeParseJson(jsonStr: string | null): any[] {
|
|
|
|
|
+ if (!jsonStr) return [];
|
|
|
|
|
+ try {
|
|
|
|
|
+ return JSON.parse(jsonStr);
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 从数据库章节记录构建树形结构的outline
|
|
* 从数据库章节记录构建树形结构的outline
|
|
|
*/
|
|
*/
|
|
@@ -73,7 +85,7 @@ export class BookStore {
|
|
|
number: c.number,
|
|
number: c.number,
|
|
|
title: c.title,
|
|
title: c.title,
|
|
|
summary: c.summary || '',
|
|
summary: c.summary || '',
|
|
|
- keyPoints: c.keyPoints ? JSON.parse(c.keyPoints) : [],
|
|
|
|
|
|
|
+ keyPoints: this.safeParseJson(c.keyPoints),
|
|
|
estimatedWords: c.estimatedWords,
|
|
estimatedWords: c.estimatedWords,
|
|
|
sections: []
|
|
sections: []
|
|
|
});
|
|
});
|
|
@@ -82,7 +94,7 @@ export class BookStore {
|
|
|
number: c.number,
|
|
number: c.number,
|
|
|
title: c.title,
|
|
title: c.title,
|
|
|
summary: c.summary || '',
|
|
summary: c.summary || '',
|
|
|
- keyPoints: c.keyPoints ? JSON.parse(c.keyPoints) : [],
|
|
|
|
|
|
|
+ keyPoints: this.safeParseJson(c.keyPoints),
|
|
|
estimatedWords: c.estimatedWords,
|
|
estimatedWords: c.estimatedWords,
|
|
|
subsections: []
|
|
subsections: []
|
|
|
});
|
|
});
|
|
@@ -104,7 +116,7 @@ export class BookStore {
|
|
|
number: c.number,
|
|
number: c.number,
|
|
|
title: c.title,
|
|
title: c.title,
|
|
|
summary: c.summary || '',
|
|
summary: c.summary || '',
|
|
|
- keyPoints: c.keyPoints ? JSON.parse(c.keyPoints) : [],
|
|
|
|
|
|
|
+ keyPoints: this.safeParseJson(c.keyPoints),
|
|
|
estimatedWords: c.estimatedWords
|
|
estimatedWords: c.estimatedWords
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -173,7 +185,12 @@ export class BookStore {
|
|
|
if (!book) return null;
|
|
if (!book) return null;
|
|
|
|
|
|
|
|
// 构建树形结构的outline(从数据库章节记录构建)
|
|
// 构建树形结构的outline(从数据库章节记录构建)
|
|
|
- const outline = this.buildOutlineFromChapters(book.chapters);
|
|
|
|
|
|
|
+ let outline: BookOutline | null = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ outline = this.buildOutlineFromChapters(book.chapters);
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('[BookStore] buildOutlineFromChapters 失败:', error);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
let result = this.toBook(book);
|
|
let result = this.toBook(book);
|
|
|
|
|
|