@@ -47,7 +47,7 @@ export const useBookStore = defineStore('book', {
|
||||
},
|
||||
getters: {
|
||||
bookProgress: (state): BookProgress | undefined => {
|
||||
if (state.catalog.length == 0) return
|
||||
if (state.catalog.length === 0) return
|
||||
const { chapterIndex, chapterPos, name, author } = state.readingBook
|
||||
const title = state.catalog[chapterIndex]?.title
|
||||
if (!title) return
|
||||
@@ -63,13 +63,12 @@ export const useBookStore = defineStore('book', {
|
||||
theme: state => {
|
||||
return state.config.theme
|
||||
},
|
||||
isNight: state => state.config.theme == 6,
|
||||
isNight: state => state.config.theme === 6,
|
||||
},
|
||||
actions: {
|
||||
/** 从后端加载书架书籍,优先返回内存缓存 */
|
||||
async loadBookShelf(): Promise<Book[]> {
|
||||
const fetchBookshellf_promise = API.getBookShelf().then(resp => {
|
||||
console.log('API.getBookShelf数据返回')
|
||||
const { isSuccess, data, errorMsg } = resp.data
|
||||
if (isSuccess === true) {
|
||||
if (
|
||||
@@ -91,16 +90,13 @@ export const useBookStore = defineStore('book', {
|
||||
}
|
||||
ElMessage.error(errorMsg ?? '后端返回格式错误!')
|
||||
}
|
||||
console.log('书架数据已更新')
|
||||
return this.shelf
|
||||
})
|
||||
|
||||
if (this.shelf.length > 0) {
|
||||
// bookshelf data fetched before:do not await
|
||||
console.log('返回缓存书架数据')
|
||||
return this.shelf
|
||||
} else {
|
||||
console.log('从阅读后端获取书架数据...')
|
||||
return await fetchBookshellf_promise
|
||||
}
|
||||
},
|
||||
@@ -126,7 +122,6 @@ export const useBookStore = defineStore('book', {
|
||||
ElMessage.info(`书籍${name}: 章节目录已更新`)
|
||||
}
|
||||
this.catalog = data
|
||||
console.log(`书籍${name}: 章节目录已更新`)
|
||||
return this.catalog
|
||||
})
|
||||
if (
|
||||
@@ -134,10 +129,8 @@ export const useBookStore = defineStore('book', {
|
||||
this.catalog.length > 0 &&
|
||||
this.catalog.length - 1 >= chapterIndex
|
||||
) {
|
||||
console.log(`返回书籍《${name}》 缓存的章节目录`)
|
||||
return this.catalog
|
||||
} else {
|
||||
console.log(`从阅读后端获取书籍《${name}》 章节目录数据...`)
|
||||
return await fetchChapterList_promise
|
||||
}
|
||||
},
|
||||
@@ -155,14 +148,8 @@ export const useBookStore = defineStore('book', {
|
||||
if (webReadConfigLoadedDate === undefined) {
|
||||
const _config = await API.getReadConfig()
|
||||
webReadConfigLoadedDate = new Date()
|
||||
console.log(
|
||||
`${this.$id}.loadWebConfig: ${webReadConfigLoadedDate.toLocaleString()}成功加载阅读配置`,
|
||||
)
|
||||
return this.setConfig(_config)
|
||||
}
|
||||
console.log(
|
||||
`${this.$id}.loadWebConfig: 已于${webReadConfigLoadedDate.toLocaleString()}成功加载`,
|
||||
)
|
||||
},
|
||||
setConfig(config?: webReadConfig) {
|
||||
this.config = Object.assign({}, this.config, config)
|
||||
|
||||
Reference in New Issue
Block a user