Skip to content

Commit

Permalink
Dev/0.3.3 (#15)
Browse files Browse the repository at this point in the history
* fix: 修复报错后useProgress停止

* fix: 修复网文目录错误
  • Loading branch information
baicie authored Jan 9, 2024
1 parent 55d6894 commit ba0d06f
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 51 deletions.
12 changes: 11 additions & 1 deletion packages/client/modules/common-reader/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const item = computed(() => {
}
})
const height = computed(() => window.innerHeight)
function handleClickChapter(selectedKeys: string[], e: { node: EventDataNode }) {
if (selectedKeys.length) {
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -101,7 +103,15 @@ onBeforeMount(() => {
<Layout>
<LayoutSider :width="250" :style="{ overflow: 'auto', height: '100vh', position: 'fixed', left: 0, top: 0, bottom: 0 }">
<template v-if="state.navs.length">
<Tree :tree-data="state.navs as unknown as DataNode[]" block-node default-expand-all selectable :field-names="filedName" @select="handleClickChapter" />
<Tree
:tree-data="state.navs as unknown as DataNode[]"
block-node
default-expand-all
selectable
:field-names="filedName"
:height="height"
@select="handleClickChapter"
/>
</template>
</LayoutSider>
<LayoutContent :style="{ marginLeft: '250px', padding: '24px' }">
Expand Down
6 changes: 3 additions & 3 deletions packages/client/modules/common-reader/use-reader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { reactive, ref, toRaw } from 'vue'
import { reactive, ref, shallowReactive, toRaw } from 'vue'
import type { Book, MessageType, SearchOnlineResult } from '@b-reader/utils'
import { useAppStore } from '../../src/store/app'
import { getDataFromHtml } from '../../src/utils'
Expand All @@ -18,10 +18,10 @@ interface CommonReaderState {
export function useCommonReader() {
const { initApp: init, sendMessage } = useAppStore()
const scroller = ref()
const state = reactive<CommonReaderState>({
const state = shallowReactive<CommonReaderState>({
init: {},
navs: [],
contents: {},
contents: shallowReactive({}),
loading: false,
currentPath: '',
})
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"@b-reader/epub": "workspace:^",
"@b-reader/utils": "workspace:^",
"@vueuse/core": "^10.7.1",
"ant-design-vue": "^4.0.8",
"vue": "^3.4.5",
"ant-design-vue": "^4.1.0",
"vue": "^3.4.7",
"vue-i18n": "^9.8.0",
"vue-virtual-scroller": "2.0.0-beta.8"
},
Expand Down
44 changes: 33 additions & 11 deletions packages/extension/src/receive-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ async function receiveCommonReaderContent(book: MessageTypeOnlineContentReq['dat
scroll: book.scroll,
title: book.title,
})
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveCommonReaderNav(book: Book, config: BReaderContext, webview: Webview) {
Expand All @@ -132,11 +134,13 @@ async function receiveCommonReaderNav(book: Book, config: BReaderContext, webvie
}

await sendMessage(webview, 'reader:common:get_nav:res', navs)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveNav(bookId: string, config: BReaderContext, webview: Webview) {
Expand All @@ -145,11 +149,13 @@ async function receiveNav(bookId: string, config: BReaderContext, webview: Webvi
const { getValue } = useDatabase(config)
const cache = await getValue<Epub>(`${StoreKeys.cache}/${bookId}`)
await sendMessage(webview, 'snedNav', cache.nva)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveBook(book: BookConfig, config: BReaderContext) {
Expand All @@ -160,11 +166,13 @@ async function receiveBook(book: BookConfig, config: BReaderContext) {
const { getValue } = useDatabase(config)
const res = await getValue<Record<string, Book>>(StoreKeys.book)
await sendMessageToAll('bookself', 'bookInfor', res)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveBookInfor(config: BReaderContext, webview: Webview) {
Expand All @@ -173,22 +181,26 @@ async function receiveBookInfor(config: BReaderContext, webview: Webview) {
const { getValue } = useDatabase(config)
const res = await getValue<Record<string, Book>>(StoreKeys.book)
await sendMessage(webview, 'bookInfor', res)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function openWebview(data: string) {
try {
start('打开中...')
await commands.executeCommand(`b-reader.local.${data}`, data)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveOpenBook(bookId: string, config: BReaderContext) {
Expand All @@ -203,11 +215,13 @@ async function receiveOpenBook(bookId: string, config: BReaderContext) {
await commands.executeCommand(Commands.openCommonReader, bookinfo)
break
}
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

// 获取章节内容
Expand All @@ -219,23 +233,27 @@ async function receiveContent(data: MessageTypeGetContent['data'], config: BRead
const chapter = await bookInstance.getContent()
await sendMessage(webview, 'sendContent', chapter)
// cache
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveOnlieSearch(data: string, config: BReaderContext, webview: Webview) {
try {
start('搜索中...')
const res = await search(config.biquge!, data)
await sendMessage(webview, 'online:search:res', res)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveOnlineReadReq(data: SearchOnlineResult, config: BReaderContext) {
Expand All @@ -250,11 +268,13 @@ async function receiveOnlineReadReq(data: SearchOnlineResult, config: BReaderCon

const _book = await writeBookInfor(book, config, false)
await commands.executeCommand(Commands.openCommonReader, _book)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}

async function receiveOnlineAddBookshelfReq(data: SearchOnlineResult, config: BReaderContext) {
Expand All @@ -271,9 +291,11 @@ async function receiveOnlineAddBookshelfReq(data: SearchOnlineResult, config: BR
const { getValue } = useDatabase(config)
const res = await getValue<Record<string, Book>>(StoreKeys.book)
await sendMessageToAll('bookself', 'bookInfor', res)
stop()
}
catch (error) {
berror(error)
}
finally {
stop()
}
}
Loading

0 comments on commit ba0d06f

Please sign in to comment.