From b26d0433bca08c91027bb8c461f97fdc59b4daf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Thu, 27 Jun 2024 15:23:09 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E5=88=87=E6=8D=A2=E4=B8=8A=E4=B8=80=E7=AB=A0?= =?UTF-8?q?=E5=92=8C=E4=B8=8B=E4=B8=80=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/utils/CopyFile.ets | 21 ------- .../src/main/ets/common/utils/FileHandler.ets | 59 +++++++++++++++++++ entry/src/main/ets/common/utils/readFile.ets | 39 ------------ .../main/ets/pages/view/Reader/ReaderPage.ets | 37 ++++++++---- .../ets/pages/view/bookShelf/IndexShelf.ets | 37 ++++++------ ...{ReaderFile.ets => ReaderChaptersItem.ets} | 0 entry/src/main/ets/storage/bookListData.ets | 10 ---- 7 files changed, 104 insertions(+), 99 deletions(-) delete mode 100644 entry/src/main/ets/common/utils/CopyFile.ets create mode 100644 entry/src/main/ets/common/utils/FileHandler.ets delete mode 100644 entry/src/main/ets/common/utils/readFile.ets rename entry/src/main/ets/storage/{ReaderFile.ets => ReaderChaptersItem.ets} (100%) diff --git a/entry/src/main/ets/common/utils/CopyFile.ets b/entry/src/main/ets/common/utils/CopyFile.ets deleted file mode 100644 index 09c44c33..00000000 --- a/entry/src/main/ets/common/utils/CopyFile.ets +++ /dev/null @@ -1,21 +0,0 @@ -import fs from '@ohos.file.fs'; -import { BusinessError } from '@ohos.base'; -import { common } from '@kit.AbilityKit'; - -let context = getContext(this) as common.UIAbilityContext; -let filePath = context.filesDir + '/desTest.txt'; - -// 将picker选择的文件复制到沙箱路径 -export function CopyFile(srcUrl: string): void { - let dstPath = filePath; - console.log("dstPath:" + dstPath) - console.log("srcUrl:" + srcUrl) - - let file = fs.openSync(srcUrl, fs.OpenMode.READ_WRITE); - - fs.copyFile(file.fd, dstPath, 0).then(() => { - console.info("copy file succeed"); - }).catch((err: BusinessError) => { - console.error("copy file failed with error message: " + err.message + ", error code: " + err.code); - }); -} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/FileHandler.ets b/entry/src/main/ets/common/utils/FileHandler.ets new file mode 100644 index 00000000..51bcdae7 --- /dev/null +++ b/entry/src/main/ets/common/utils/FileHandler.ets @@ -0,0 +1,59 @@ +import { BusinessError } from '@ohos.base'; +import fs, { Options } from '@ohos.file.fs'; +import { common } from '@kit.AbilityKit'; +import { chaptersItem } from 'ets/storage/ReaderChaptersItem'; +import promptAction from '@ohos.promptAction'; + +let context = getContext(this) as common.UIAbilityContext; +let filePath = context.filesDir; + +let dstPath = filePath + '/desTest' // 暂时替代 + +let options: Options = { + encoding: 'utf-8' +}; + +export class FileHandler { + static async CopyFile(srcUrl?: string) { + let file = fs.openSync(srcUrl, fs.OpenMode.READ_WRITE); + // let dstPath = filePath + '/' + file.name; // file.name:《幽影之冰》.txt + await fs.copyFile(file.fd, dstPath, 0).then(() => { + promptAction.showToast({ + message: '导入沙箱成功', + duration: 2000 + }) + console.info("copy file success"); + }).catch((err: BusinessError) => { + promptAction.showToast({ + message: '导入失败', + duration: 2000 + }) + console.error("copy file failed with error message: " + err.message + ", error code: " + err.code); + }); + } + + static async readFile(readFileUrl?: string) { + let chapterNumber = 0 + const chapters: chaptersItem[] = []; + console.info('readFileUrl:' + readFileUrl) + const regex = /===第(.*?)章 (.*?)===/g; + await fs.readLines(dstPath, options).then((readerIterator: fs.ReaderIterator) => { + for (let it = readerIterator.next();!it.done; it = readerIterator.next()) { + const match = regex.exec(it.value); + if (match) { + const chapterTitleNumber = match[1]; // 书源内部章节 + const chapterTitle = match[2]; + chapterNumber++ + chapters.push(new chaptersItem(chapterNumber, chapterTitle, chapterTitleNumber, '')) + } else { + if (chapters.length > 0) { + chapters[chapters.length - 1].content += it.value + } + } + } + }).catch((err: BusinessError) => { + console.error("readLines failed with error message: " + err.message + ", error code: " + err.code); + }); + return chapters + } +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/readFile.ets b/entry/src/main/ets/common/utils/readFile.ets deleted file mode 100644 index bff4cb70..00000000 --- a/entry/src/main/ets/common/utils/readFile.ets +++ /dev/null @@ -1,39 +0,0 @@ -import { BusinessError } from '@ohos.base'; -import fs, { Options } from '@ohos.file.fs'; -import { common } from '@kit.AbilityKit'; -import { chaptersItem } from 'ets/storage/ReaderFile'; - -let context = getContext(this) as common.UIAbilityContext; -let filePath = context.filesDir + '/desTest.txt'; - -let options: Options = { - encoding: 'utf-8' -}; - -let chapterNumber = 0 -const chapters: chaptersItem[] = []; - -export class TxtFileHandler { - static async readFile(readFileUrl?: string) { - console.info('filePath:' + filePath) - const regex = /===第(.*?)章 (.*?)===/g; - await fs.readLines(filePath, options).then((readerIterator: fs.ReaderIterator) => { - for (let it = readerIterator.next();!it.done; it = readerIterator.next()) { - const match = regex.exec(it.value); - if (match) { - const chapterTitleNumber = match[1]; // 书源内部章节 - const chapterTitle = match[2]; - chapterNumber++ - chapters.push(new chaptersItem(chapterNumber, chapterTitle, chapterTitleNumber, '')) - } else { - if (chapters.length > 0) { - chapters[chapters.length - 1].content += it.value - } - } - } - }).catch((err: BusinessError) => { - console.error("readLines failed with error message: " + err.message + ", error code: " + err.code); - }); - return chapters - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index 9d4ab47b..ae91f8a9 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -2,13 +2,13 @@ import battery from 'ets/componets/common/battery'; import Dialog from 'ets/componets/common/Dialog'; import { router } from '@kit.ArkUI'; import sourceView from './sourceView'; -import { TxtFileHandler } from 'ets/common/utils/readFile'; +import { FileHandler } from 'ets/common/utils/FileHandler'; import { AddDownloadDialog } from 'ets/componets/Reader/AddDownloadDialog'; import { NetworkInput } from 'ets/componets/Reader/NetworkInput'; import { MusicPlayer } from 'ets/componets/MusicPlayer'; import purificationView from './purificationView'; -import { chaptersItem } from 'ets/storage/ReaderFile'; +import { chaptersItem } from 'ets/storage/ReaderChaptersItem'; @Entry @Component @@ -20,6 +20,8 @@ struct ReaderPage { @State isShowListen: boolean = false @State StartText: string = "1" @State EndText: string = "2" + @State CurrentChapters: number = 0 + @State TotalChapters: number = 0 controller: TextInputController = new TextInputController() // 网址导入Dialog dialogController: CustomDialogController = new CustomDialogController({ @@ -49,7 +51,8 @@ struct ReaderPage { async onPageShow() { let temp = router.getParams() // console.log('router' + JSON.stringify(temp)) - this.txtFile = await TxtFileHandler.readFile() //txt小说 + this.txtFile = await FileHandler.readFile() //txt小说 + this.TotalChapters = this.txtFile.length } @Builder @@ -80,7 +83,7 @@ struct ReaderPage { .onClick(() => { router.back() }) - Text(`第${this.txtFile[0]?.chapterTitleNumber}章 ${this.txtFile[0]?.title}`) + Text(`第${this.txtFile[this.CurrentChapters]?.chapterTitleNumber}章 ${this.txtFile[this.CurrentChapters]?.title}`) Blank(1) Row({ space: 16 }) { Image($r("app.media.refresh")) @@ -145,7 +148,7 @@ struct ReaderPage { Scroll(this.scroller) { Column() { Row() { - Text(this.txtFile[0]?.title) + Text(this.txtFile[this.CurrentChapters]?.title) .lineHeight(20) .font({ size: 12, @@ -161,7 +164,7 @@ struct ReaderPage { }) .width("100%") - Text(this.txtFile[0]?.content) + Text(this.txtFile[this.CurrentChapters]?.content) .lineHeight(20) .font({ size: 12, @@ -170,8 +173,8 @@ struct ReaderPage { .fontColor("rgba(0, 0, 0, 0.88)") } .padding({ - left:24, - right:24 + left: 24, + right: 24 }) } // .scrollable(ScrollDirection.Horizontal) @@ -268,12 +271,22 @@ struct ReaderPage { .justifyContent(FlexAlign.SpaceBetween) .width("100%") - Row() { - Text("上一章") + Row({ space: 16 }) { + Text("上一章").onClick(() => { + if (this.CurrentChapters > 0) { + this.CurrentChapters-- + } + }) + Blank(1) - Progress({ value: 50 }).width("50%") + Progress({ value: this.CurrentChapters, total: this.TotalChapters - 1 }).layoutWeight(1) Blank(1) - Text("下一章") + + Text("下一章").onClick(() => { + if (this.CurrentChapters < this.TotalChapters - 1) { + this.CurrentChapters++ + } + }) } .padding({ left: 24, diff --git a/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets b/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets index d15502e0..e263300b 100644 --- a/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets +++ b/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets @@ -12,8 +12,7 @@ import groupTypeComponent from '../../../componets/group/GroupType' import ShelfBookList from './Shelf/ShelfBookList' import picker from '@ohos.file.picker' -import { CopyFile } from 'ets/common/utils/CopyFile' -import { ColumnModifier } from '../../../common/utils/ComponetModifier' +import { FileHandler } from 'ets/common/utils/FileHandler' import RefreshComponent from '../../../componets/common/RefreshComponent' @Component @@ -68,6 +67,8 @@ export default struct IndexShelf { cornerRadius: 8, offset: { dx: 0, dy: 0 } }) + tabsController: TabsController = new TabsController(); + private scrollController: Scroller = new Scroller(); onAccept() { console.info('确定') @@ -99,31 +100,32 @@ export default struct IndexShelf { bottom: 16 }) } - private scrollController: Scroller = new Scroller(); - tabsController: TabsController = new TabsController(); + build() { - Column(){ + Column() { Flex({ - justifyContent:FlexAlign.SpaceBetween, + justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.End - }){ - Row(){ - List({scroller:this.scrollController}){ - ListItem(){ + }) { + Row() { + List({ scroller: this.scrollController }) { + ListItem() { BookMark({ title: '小说', index: 0, currentIndex: this.currentIndex }).onClick(() => { this.currentIndex = 0 this.tabsController.changeIndex(0) console.log(this.currentIndex + '') }) } - ListItem(){ + + ListItem() { BookMark({ title: '漫画', index: 1, currentIndex: this.currentIndex }).onClick(() => { this.currentIndex = 1 this.tabsController.changeIndex(1) console.log(this.currentIndex + '') }) } - ListItem(){ + + ListItem() { BookMark({ title: '有声书', index: 2, currentIndex: this.currentIndex }).onClick(() => { this.currentIndex = 2 this.tabsController.changeIndex(2) @@ -137,7 +139,7 @@ export default struct IndexShelf { .listDirection(Axis.Horizontal) } - Row(){ + Row() { Flex() { } .width(0) @@ -216,9 +218,9 @@ export default struct IndexShelf { blurStyle: BlurStyle.COMPONENT_ULTRA_THIN, }) } - }.margin({bottom:12}) + }.margin({ bottom: 12 }) } - .padding({top:this.topRectHeight === 0 ? 30 : this.topRectHeight,left:20,right:20}) + .padding({ top: this.topRectHeight === 0 ? 30 : this.topRectHeight, left: 20, right: 20 }) Tabs({ barPosition: BarPosition.Start, @@ -366,7 +368,7 @@ export default struct IndexShelf { } .padding({ left: 10, right: 10 }) } - .margin({bottom:110 + (this.topRectHeight === 0 ? 10 : this.topRectHeight)}) + .margin({ bottom: 110 + (this.topRectHeight === 0 ? 10 : this.topRectHeight) }) .align(Alignment.TopStart) .scrollBar(BarState.Off) } @@ -486,7 +488,8 @@ export default struct IndexShelf { await documentPicker.select(documentSelectOptions).then((documentSelectResult: Array) => { filePath = documentSelectResult[0]; }) - CopyFile(filePath) + FileHandler.CopyFile(filePath) + this.isShowImport = false break case 1: // 云盘导入 diff --git a/entry/src/main/ets/storage/ReaderFile.ets b/entry/src/main/ets/storage/ReaderChaptersItem.ets similarity index 100% rename from entry/src/main/ets/storage/ReaderFile.ets rename to entry/src/main/ets/storage/ReaderChaptersItem.ets diff --git a/entry/src/main/ets/storage/bookListData.ets b/entry/src/main/ets/storage/bookListData.ets index c063db1d..15de0d53 100644 --- a/entry/src/main/ets/storage/bookListData.ets +++ b/entry/src/main/ets/storage/bookListData.ets @@ -8,16 +8,6 @@ let KEY = '' const novelListData:BookList[] = [ new BookList('1','仙人消失之后','会说话的肘子·未读过1','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') ,new BookList('2','仙人消失之后','会说话的肘子·未读过2','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('3','仙人消失之后','会说话的肘子·未读过3','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('4','仙人消失之后','会说话的肘子·未读过4','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('5','仙人消失之后','会说话的肘子·未读过5','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('6','仙人消失之后','会说话的肘子·未读过6','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('7','仙人消失之后','会说话的肘子·未读过7','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('8','仙人消失之后','会说话的肘子·未读过8','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('9','仙人消失之后','会说话的肘子·未读过9','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('10','仙人消失之后','会说话的肘子·未读过10','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','玄幻') - ,new BookList('11','仙人消失之后','会说话的肘子·未读过10','更新至·第340章 镇压',$r('app.media.cover_list'),'玄幻') - ] const soundListData:BookList[] = [ From 0ae7c8c32cbd3ddfcb94c8210fdfa842e0fa6a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Sun, 30 Jun 2024 00:39:30 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=B9=A6=E7=B1=8D?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=90=8E=EF=BC=8C=E6=89=93=E5=BC=80=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E4=B9=A6=E7=B1=8D=E7=9A=84=E6=B2=99=E7=AE=B1=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/common/utils/FileHandler.ets | 12 +- .../dataList}/ReaderChaptersItem.ets | 0 .../main/ets/pages/view/BookDetailPage.ets | 144 +++++++++++++----- .../main/ets/pages/view/Reader/ReaderPage.ets | 9 +- .../ets/pages/view/bookShelf/BookInfo.ets | 8 +- 5 files changed, 114 insertions(+), 59 deletions(-) rename entry/src/main/ets/{storage => componets/dataList}/ReaderChaptersItem.ets (100%) diff --git a/entry/src/main/ets/common/utils/FileHandler.ets b/entry/src/main/ets/common/utils/FileHandler.ets index 82c918f3..b5fabdda 100644 --- a/entry/src/main/ets/common/utils/FileHandler.ets +++ b/entry/src/main/ets/common/utils/FileHandler.ets @@ -1,7 +1,7 @@ import { BusinessError } from '@ohos.base'; import fs, { Options } from '@ohos.file.fs'; import { common } from '@kit.AbilityKit'; -import { chaptersItem } from 'ets/storage/ReaderChaptersItem'; +import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem'; import promptAction from '@ohos.promptAction'; import { BookList } from '../../componets/dataList/bookList'; import { addShelfBook } from '../../storage/bookListData'; @@ -10,18 +10,16 @@ import { showMessage } from '../../componets/common/promptShow'; let context = getContext(this) as common.UIAbilityContext; let filePath = context.filesDir; -let dstPath = filePath + '/desTest' // 暂时替代 - let options: Options = { encoding: 'utf-8' }; export class FileHandler { - static async CopyFile(srcUrl?: string) { + static async CopyFile(srcUrl: string) { let file = fs.openSync(srcUrl, fs.OpenMode.READ_WRITE); let dstPath = filePath + '/' + file.name; // file.name:《幽影之冰》.txt - showMessage('添加到书架成功') addShelfBook(0,new BookList('',file.name,'会说话的肘子·未读过1','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','未分组',dstPath)) + showMessage('添加到书架成功') await fs.copyFile(file.fd, dstPath, 0).then(() => { promptAction.showToast({ message: '导入沙箱成功', @@ -37,12 +35,12 @@ export class FileHandler { }); } - static async readFile(readFileUrl?: string) { + static async readFile(readFileUrl: string) { let chapterNumber = 0 const chapters: chaptersItem[] = []; console.info('readFileUrl:' + readFileUrl) const regex = /===第(.*?)章 (.*?)===/g; - await fs.readLines(dstPath, options).then((readerIterator: fs.ReaderIterator) => { + await fs.readLines(readFileUrl, options).then((readerIterator: fs.ReaderIterator) => { for (let it = readerIterator.next();!it.done; it = readerIterator.next()) { const match = regex.exec(it.value); if (match) { diff --git a/entry/src/main/ets/storage/ReaderChaptersItem.ets b/entry/src/main/ets/componets/dataList/ReaderChaptersItem.ets similarity index 100% rename from entry/src/main/ets/storage/ReaderChaptersItem.ets rename to entry/src/main/ets/componets/dataList/ReaderChaptersItem.ets diff --git a/entry/src/main/ets/pages/view/BookDetailPage.ets b/entry/src/main/ets/pages/view/BookDetailPage.ets index 87c45f4b..f42f135e 100644 --- a/entry/src/main/ets/pages/view/BookDetailPage.ets +++ b/entry/src/main/ets/pages/view/BookDetailPage.ets @@ -1,32 +1,38 @@ import CommonConstants from '../../common/constants/CommonConstants' import ReadRecordItem from '../../componets/bookDetail/ReadRecordItem' import TagIndex from '../../componets/bookDetail/TagIndex' -import { router, Router, SwipeRefresher } from '@kit.ArkUI' +import { router, SwipeRefresher } from '@kit.ArkUI' import NoteIndex from '../../componets/bookDetail/note/NoteIndex' +import { BookList } from 'ets/componets/dataList/bookList' /** * 标题图片样式 */ -@Extend(Image) function titleImageStyle(){ +@Extend(Image) +function titleImageStyle() { .fillColor(Color.White) .width(CommonConstants.TITLE_IMG_SIZE) .height(CommonConstants.TITLE_IMG_SIZE) } + /** * 分割线样式 */ -@Extend(Divider) function recordDividerStyle() { +@Extend(Divider) +function recordDividerStyle() { .vertical(true) .width(0.5) .height(24) .color('#40ffffff') } + /** * 加入书架dialog */ @CustomDialog struct AddBookShelfDialog { controller?: CustomDialogController; + build() { Row() { Image($r('app.media.ic_public_confirm')) @@ -47,10 +53,16 @@ struct AddBookShelfDialog { } .height(56) .width(CommonConstants.FULL_WIDTH) - .padding({left: 20, right: 20, top: 16, bottom: 16}) + .padding({ + left: 20, + right: 20, + top: 16, + bottom: 16 + }) .backgroundColor('#333333') } } + @Entry @Component struct BookDetailPage { @@ -58,15 +70,21 @@ struct BookDetailPage { @State currentIndex: number = 0; // 是否加入书架 @State isAddBookShelf: boolean = false; - onPageShow(): void { - console.log(JSON.stringify(router.getParams())) - } + @State bookData: BookList = router.getParams() as BookList // 加入书架dialog dialogController: CustomDialogController = new CustomDialogController({ builder: AddBookShelfDialog(), cornerRadius: 8, - offset: {dx: 0, dy: -100} + offset: { dx: 0, dy: -100 } }) + + onPageShow(): void { + console.log('router BookDetailPage:' + JSON.stringify(router.getParams())) + if (router.getParams() as BookList) { + this.bookData = router.getParams() as BookList + } + } + // 加入书架函数 addBookShelf() { this.dialogController.open(); @@ -77,15 +95,17 @@ struct BookDetailPage { }, 1000); clearTimeout(timeoutID); } + /** * Panel */ - @Builder catalogPanel() { + @Builder + catalogPanel() { Column() { - Search({placeholder: '搜索目录'}) + Search({ placeholder: '搜索目录' }) .height(34) - .padding({top: 8, bottom: 8}) - Tabs({barPosition: BarPosition.Start}) { + .padding({ top: 8, bottom: 8 }) + Tabs({ barPosition: BarPosition.Start }) { TabContent() { Column() { SwipeRefresher({ @@ -95,6 +115,7 @@ struct BookDetailPage { } } .tabBar(this.catalogTab(0, '目录', 548)) + TabContent() { Column() { SwipeRefresher({ @@ -104,6 +125,7 @@ struct BookDetailPage { } } .tabBar(this.catalogTab(1, '书源', 24)) + TabContent() { NoteIndex() } @@ -113,9 +135,15 @@ struct BookDetailPage { .onChange((index: number) => { this.currentIndex = index; }) - Row({space: 20}) { - Button(this.isAddBookShelf ? '已加书架' :'加入书架') - .padding({left: 32, right: 32, top: 8, bottom: 8}) + + Row({ space: 20 }) { + Button(this.isAddBookShelf ? '已加书架' : '加入书架') + .padding({ + left: 32, + right: 32, + top: 8, + bottom: 8 + }) .width(150) .height(40) .borderRadius(200) @@ -125,36 +153,41 @@ struct BookDetailPage { this.addBookShelf(); }) Button('立即阅读') - .padding({left: 32, right: 32, top: 8, bottom: 8}) + .padding({ + left: 32, + right: 32, + top: 8, + bottom: 8 + }) .width(150) .height(40) .borderRadius(200) .backgroundColor('#FF6600') .fontColor('#FFFFFF') - .onClick(()=>{ + .onClick(() => { // 跳转到阅读器 router.pushUrl({ url: 'pages/view/Reader/ReaderPage', - params: { - bookUrl:"/data/local/tmp" - } + params: this.bookData }) }) } - .padding({top: 12, bottom: 12}) + .padding({ top: 12, bottom: 12 }) .justifyContent(FlexAlign.Center) .width(CommonConstants.FULL_WIDTH) .height(64) } - .padding({left: 20, right: 20, bottom: 12}) + .padding({ left: 20, right: 20, bottom: 12 }) .width(CommonConstants.FULL_WIDTH) .height(CommonConstants.FULL_HEIGHT) .borderRadius(16) } + /** * tab页签 */ - @Builder catalogTab(index: number, name: string, count: number) { + @Builder + catalogTab(index: number, name: string, count: number) { Column() { Row() { Text(name) @@ -168,6 +201,7 @@ struct BookDetailPage { .fontColor(this.currentIndex === index ? '#e0000000' : '#73000000') .fontWeight(500) } + Divider() .width(10) .strokeWidth(3) @@ -175,10 +209,11 @@ struct BookDetailPage { .color('#FF6600') .opacity(this.currentIndex === index ? 1 : 0) } - .padding({top: 8, bottom: 8}) + .padding({ top: 8, bottom: 8 }) .width(59) .height(40) } + build() { Column() { // todo 状态栏 @@ -187,13 +222,14 @@ struct BookDetailPage { } .width(CommonConstants.FULL_WIDTH) .height(40) + // 标题栏 Row() { // 返回与标题 - Row({space: 12}) { + Row({ space: 12 }) { Image($r("app.media.ic_public_return_left")) .titleImageStyle() - .onClick(()=>{ + .onClick(() => { router.back() }) Text('书籍详情') @@ -201,9 +237,10 @@ struct BookDetailPage { .fontSize(16) } .height(24) + Blank() // 右侧功能 - Row({space: 24}) { + Row({ space: 24 }) { Image($r('app.media.ic_public_edit')) .titleImageStyle() .onClick(() => { @@ -218,17 +255,23 @@ struct BookDetailPage { } .height(24) } - .padding({left: 20, right: 20, top: 12, bottom: 12}) + .padding({ + left: 20, + right: 20, + top: 12, + bottom: 12 + }) .height(36) .width(CommonConstants.FULL_WIDTH) + // 小说标题 - Row({space: CommonConstants.SPACE_20}) { + Row({ space: CommonConstants.SPACE_20 }) { Image($r('app.media.cover_list')) .width(CommonConstants.NOVEL_IMG_WIDTH) .height(CommonConstants.NOVEL_IMG_HEIGHT) .borderRadius(5) - Column({space: 8}) { - Text('大奉打更人') + Column({ space: 8 }) { + Text(this.bookData.title) .fontColor(Color.White) .fontSize(20) Blank() @@ -243,38 +286,51 @@ struct BookDetailPage { .fillColor('#FFF') .opacity(0.45) } - Row({space: 8}) { - TagIndex({tag: '幻想修仙'}) - TagIndex({tag: '完本'}) - TagIndex({tag: '300万字'}) + + Row({ space: 8 }) { + TagIndex({ tag: '幻想修仙' }) + TagIndex({ tag: '完本' }) + TagIndex({ tag: '300万字' }) } } .height(CommonConstants.NOVEL_IMG_HEIGHT) .alignItems(HorizontalAlign.Start) } - .padding({left: 20, right: 20, top: 12, bottom: 12}) + .padding({ + left: 20, + right: 20, + top: 12, + bottom: 12 + }) .width(CommonConstants.FULL_WIDTH) .height(116) + // 阅读记录 Row() { Row() { ReadRecordItem() Divider() .recordDividerStyle() - ReadRecordItem({count: 16, unit: '天', placeText: '阅读天数'}) + ReadRecordItem({ count: 16, unit: '天', placeText: '阅读天数' }) Divider() .recordDividerStyle() - ReadRecordItem({count: 3, unit: '次', placeText: 'N刷次数'}) + ReadRecordItem({ count: 3, unit: '次', placeText: 'N刷次数' }) } .borderRadius(12) - .padding({top: 16, bottom: 16}) + .padding({ top: 16, bottom: 16 }) .height(60) .width(CommonConstants.FULL_WIDTH) .backgroundColor('#14ffffff') } - .padding({left: 20, right: 20, top: 12, bottom: 12}) + .padding({ + left: 20, + right: 20, + top: 12, + bottom: 12 + }) .width(CommonConstants.FULL_WIDTH) .height(88) + // 书籍简介 Flex() { Text('《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + @@ -286,7 +342,12 @@ struct BookDetailPage { .fontWeight(400) .lineHeight(22) } - .padding({left: 20, right: 20, top: 12, bottom: 12}) + .padding({ + left: 20, + right: 20, + top: 12, + bottom: 12 + }) .width(CommonConstants.FULL_WIDTH) .bindSheet($$this.isShow, this.catalogPanel(), { detents: [SheetSize.MEDIUM, SheetSize.LARGE, 200], @@ -295,6 +356,7 @@ struct BookDetailPage { dragBar: true, enableOutsideInteractive: true, }) + // 章节目录Panel /*Panel(this.isValue) { Column() { diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index ae91f8a9..4503bffe 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -8,7 +8,8 @@ import { NetworkInput } from 'ets/componets/Reader/NetworkInput'; import { MusicPlayer } from 'ets/componets/MusicPlayer'; import purificationView from './purificationView'; -import { chaptersItem } from 'ets/storage/ReaderChaptersItem'; +import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem'; +import { BookList } from 'ets/componets/dataList/bookList' @Entry @Component @@ -49,9 +50,9 @@ struct ReaderPage { @State txtFile: chaptersItem[] = []; async onPageShow() { - let temp = router.getParams() - // console.log('router' + JSON.stringify(temp)) - this.txtFile = await FileHandler.readFile() //txt小说 + let temp = router.getParams() as BookList + console.log('router ReaderPage:' + temp.fileLink) + this.txtFile = await FileHandler.readFile(temp.fileLink) //txt小说 this.TotalChapters = this.txtFile.length } diff --git a/entry/src/main/ets/pages/view/bookShelf/BookInfo.ets b/entry/src/main/ets/pages/view/bookShelf/BookInfo.ets index c86ff99b..2ab3a621 100644 --- a/entry/src/main/ets/pages/view/bookShelf/BookInfo.ets +++ b/entry/src/main/ets/pages/view/bookShelf/BookInfo.ets @@ -99,13 +99,7 @@ export default struct BookInfo{ .onClick(()=>{ router.pushUrl({ url: 'pages/view/BookDetailPage', - params: { - bookId: '1', - bookName: '大奉打更人', - bookAuthor: '卖报小郎君', - bookImage: $r('app.media.cover_list'), - bookDescribe: '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' - } + params: this.bookData }) }) } From 24b7453d345ff716451729723be1845537ab44aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Mon, 1 Jul 2024 13:54:01 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=20-=20=E5=AD=97?= =?UTF-8?q?=E4=BD=93=E5=A4=A7=E5=B0=8F=E8=B0=83=E8=8A=82=EF=BC=8C=E8=A1=8C?= =?UTF-8?q?=E9=AB=98=E8=B0=83=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/common/utils/FileHandler.ets | 15 +- .../main/ets/pages/view/Reader/ReaderPage.ets | 242 ++++++++++++------ 2 files changed, 169 insertions(+), 88 deletions(-) diff --git a/entry/src/main/ets/common/utils/FileHandler.ets b/entry/src/main/ets/common/utils/FileHandler.ets index b5fabdda..53084d6a 100644 --- a/entry/src/main/ets/common/utils/FileHandler.ets +++ b/entry/src/main/ets/common/utils/FileHandler.ets @@ -2,7 +2,6 @@ import { BusinessError } from '@ohos.base'; import fs, { Options } from '@ohos.file.fs'; import { common } from '@kit.AbilityKit'; import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem'; -import promptAction from '@ohos.promptAction'; import { BookList } from '../../componets/dataList/bookList'; import { addShelfBook } from '../../storage/bookListData'; import { showMessage } from '../../componets/common/promptShow'; @@ -15,22 +14,16 @@ let options: Options = { }; export class FileHandler { - static async CopyFile(srcUrl: string) { + static CopyFile(srcUrl: string) { let file = fs.openSync(srcUrl, fs.OpenMode.READ_WRITE); let dstPath = filePath + '/' + file.name; // file.name:《幽影之冰》.txt addShelfBook(0,new BookList('',file.name,'会说话的肘子·未读过1','更新至·第340章 镇压',$r('app.media.cover_list'),'测试作者','未分组',dstPath)) showMessage('添加到书架成功') - await fs.copyFile(file.fd, dstPath, 0).then(() => { - promptAction.showToast({ - message: '导入沙箱成功', - duration: 2000 - }) + fs.copyFile(file.fd, dstPath, 0).then(() => { + showMessage('导入沙箱成功') console.info("copy file success"); }).catch((err: BusinessError) => { - promptAction.showToast({ - message: '导入失败', - duration: 2000 - }) + showMessage('导入失败') console.error("copy file failed with error message: " + err.message + ", error code: " + err.code); }); } diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index 4503bffe..4b2c7742 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -9,7 +9,7 @@ import { NetworkInput } from 'ets/componets/Reader/NetworkInput'; import { MusicPlayer } from 'ets/componets/MusicPlayer'; import purificationView from './purificationView'; import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem'; -import { BookList } from 'ets/componets/dataList/bookList' +import { BookList } from 'ets/componets/dataList/bookList'; @Entry @Component @@ -19,10 +19,15 @@ struct ReaderPage { @State isShowSetting: boolean = true @State isShowDownload: boolean = false @State isShowListen: boolean = false - @State StartText: string = "1" - @State EndText: string = "2" + @State isShowContentSetting: boolean = false + @State StartText: string = "1" // 下载-缓存开始章节 + @State EndText: string = "2" // 下载-缓存结束章节 @State CurrentChapters: number = 0 @State TotalChapters: number = 0 + @State CurrentLuminance: number = 0 // 亮度 + @State CurrentFontSize: number = 20 // 字号 + @State LineHeight: string = "" + @State ParagraphSpacing: number = 0 controller: TextInputController = new TextInputController() // 网址导入Dialog dialogController: CustomDialogController = new CustomDialogController({ @@ -166,9 +171,9 @@ struct ReaderPage { .width("100%") Text(this.txtFile[this.CurrentChapters]?.content) - .lineHeight(20) + .lineHeight(this.LineHeight) .font({ - size: 12, + size: this.CurrentFontSize, weight: 400 }) .fontColor("rgba(0, 0, 0, 0.88)") @@ -205,49 +210,26 @@ struct ReaderPage { if (this.isShowSetting) { Column({ space: 20 }) { Divider() - Row() { - Button({ type: ButtonType.Normal }) { - Row({ - space: 4 - }) { - Image($r("app.media.change_source_icon")).width(16).height(16) - Text("换源").fontColor($r('app.string.color_black_65')) - .font({ - size: 14, - weight: 400 - }) - } - } - .borderRadius(8) - .height(40) - .width("45%") - .backgroundColor("rgba(0, 0, 0, 0.06)") - .bindSheet($$this.isShowSource, this.sourceView(), { - height: '95%', - showClose: false, - dragBar: false, - maskColor: 'rgba(0,0,0,0.6)', - onDisappear: () => { - console.log('隐藏') - } - }) - .onClick(() => { - this.isShowSource = true - }) - - Button({ type: ButtonType.Normal }) { - Row({ - space: 4 - }) { - Image($r("app.media.purify_icon")).width(16).height(16) - Text("净化").fontColor($r('app.string.color_black_65')) - .font({ - size: 14, - weight: 400 - }) + if (!this.isShowContentSetting) { + Row() { + Button({ type: ButtonType.Normal }) { + Row({ + space: 4 + }) { + Image($r("app.media.change_source_icon")).width(16).height(16) + Text("换源").fontColor($r('app.string.color_black_65')) + .font({ + size: 14, + weight: 400 + }) + } } - .bindSheet($$this.isShowPurification, this.purificationView(), { - height: '40%', + .borderRadius(8) + .height(40) + .width("45%") + .backgroundColor("rgba(0, 0, 0, 0.06)") + .bindSheet($$this.isShowSource, this.sourceView(), { + height: '95%', showClose: false, dragBar: false, maskColor: 'rgba(0,0,0,0.6)', @@ -256,45 +238,148 @@ struct ReaderPage { } }) .onClick(() => { - this.isShowPurification = true + this.isShowSource = true }) - } - .borderRadius(8) - .height(40) - .width("45%") - .backgroundColor("rgba(0, 0, 0, 0.06)") - } - .padding({ - top: 12, - left: 24, - right: 24 - }) - .justifyContent(FlexAlign.SpaceBetween) - .width("100%") - Row({ space: 16 }) { - Text("上一章").onClick(() => { - if (this.CurrentChapters > 0) { - this.CurrentChapters-- + Button({ type: ButtonType.Normal }) { + Row({ + space: 4 + }) { + Image($r("app.media.purify_icon")).width(16).height(16) + Text("净化").fontColor($r('app.string.color_black_65')) + .font({ + size: 14, + weight: 400 + }) + } + .bindSheet($$this.isShowPurification, this.purificationView(), { + height: '40%', + showClose: false, + dragBar: false, + maskColor: 'rgba(0,0,0,0.6)', + onDisappear: () => { + console.log('隐藏') + } + }) + .onClick(() => { + this.isShowPurification = true + }) } + .borderRadius(8) + .height(40) + .width("45%") + .backgroundColor("rgba(0, 0, 0, 0.06)") + } + .padding({ + top: 12, + left: 24, + right: 24 }) + .justifyContent(FlexAlign.SpaceBetween) + .width("100%") - Blank(1) - Progress({ value: this.CurrentChapters, total: this.TotalChapters - 1 }).layoutWeight(1) - Blank(1) + Row({ space: 16 }) { + Text("上一章").onClick(() => { + if (this.CurrentChapters > 0) { + this.CurrentChapters-- + } + }) - Text("下一章").onClick(() => { - if (this.CurrentChapters < this.TotalChapters - 1) { - this.CurrentChapters++ + Slider({ + value: this.CurrentChapters, + max: this.TotalChapters - 1, + min: 0, + step: 1, + style: SliderStyle.InSet + }) + .selectedColor('rgba(0, 0, 0, 0.04)') + .blockSize({ width: 30, height: 30 }) + .layoutWeight(1) + .onChange((value) => { + this.CurrentChapters = value + }) + + Text("下一章").onClick(() => { + if (this.CurrentChapters < this.TotalChapters - 1) { + this.CurrentChapters++ + } + }) + } + .padding({ + left: 24, + right: 24 + }) + .width("100%") + } else { + Column({ space: 24 }) { + Row({ space: 16 }) { + Text('亮度') + Slider({ + value: this.CurrentLuminance, + max: 100, + min: 0, + step: 1, + style: SliderStyle.InSet + }) + .selectedColor('rgba(0, 0, 0, 0.04)') + .blockSize({ width: 30, height: 30 }) + .layoutWeight(1) + .onChange((value) => { + this.CurrentLuminance = value + }) + Row() { + Text('跟随系统') + } } + + Row({ space: 16 }) { + Text('字号') + Slider({ + value: this.CurrentFontSize, + max: 100, + min: 10, + step: 1, + style: SliderStyle.InSet + }) + .selectedColor('rgba(0, 0, 0, 0.04)') + .blockSize({ width: 30, height: 30 }) + .layoutWeight(1) + .onChange((value) => { + this.CurrentFontSize = value + }) + Row() { + Button('字体') + } + } + + Row({ space: 16 }) { + Text('排版') + Button('紧凑') + .onClick(() => { + this.LineHeight = "160%" + this.ParagraphSpacing = -4 + }) + Button('适中') + .onClick(() => { + this.LineHeight = "180%" + this.ParagraphSpacing = -2 + }) + Button('宽松') + .onClick(() => { + this.LineHeight = "200%" + this.ParagraphSpacing = 0 + }) + Row() { + Button('更多') + } + } + } + .padding({ + left: 20, + right: 20 }) - } - .padding({ - left: 24, - right: 24 - }) - .width("100%") + } Grid() { GridItem() { Column() { @@ -329,6 +414,9 @@ struct ReaderPage { Image($r("app.media.my_center_set_icon")).width(24) Text("设置") } + .onClick(() => { + this.isShowContentSetting = !this.isShowContentSetting + }) } } .padding({ From 7c758ed9b67c174818a510be6ee8e461157ad404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Mon, 1 Jul 2024 15:03:27 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=E6=AE=B5?= =?UTF-8?q?=E8=90=BD=E9=97=B4=E8=B7=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/view/Reader/ReaderPage.ets | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index 4b2c7742..bc03602e 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -5,6 +5,7 @@ import sourceView from './sourceView'; import { FileHandler } from 'ets/common/utils/FileHandler'; import { AddDownloadDialog } from 'ets/componets/Reader/AddDownloadDialog'; import { NetworkInput } from 'ets/componets/Reader/NetworkInput'; +import { LengthMetrics } from '@ohos.arkui.node'; import { MusicPlayer } from 'ets/componets/MusicPlayer'; import purificationView from './purificationView'; @@ -26,7 +27,7 @@ struct ReaderPage { @State TotalChapters: number = 0 @State CurrentLuminance: number = 0 // 亮度 @State CurrentFontSize: number = 20 // 字号 - @State LineHeight: string = "" + @State LineHeight: string = "180%" @State ParagraphSpacing: number = 0 controller: TextInputController = new TextInputController() // 网址导入Dialog @@ -173,10 +174,12 @@ struct ReaderPage { Text(this.txtFile[this.CurrentChapters]?.content) .lineHeight(this.LineHeight) .font({ - size: this.CurrentFontSize, + size: this.CurrentFontSize, // 用px感觉太小了,用vp算了 weight: 400 }) + .lineSpacing(LengthMetrics.vp(this.CurrentFontSize + this.ParagraphSpacing)) .fontColor("rgba(0, 0, 0, 0.88)") + .width("100%") } .padding({ left: 24, @@ -336,8 +339,8 @@ struct ReaderPage { Text('字号') Slider({ value: this.CurrentFontSize, - max: 100, - min: 10, + max: 30, + min: 12, step: 1, style: SliderStyle.InSet }) From e9ea8012dc564d7c95a6afcef61da38a5b615293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Mon, 1 Jul 2024 16:26:28 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=8A=BD=E7=A6=BB=E9=98=85=E8=AF=BB?= =?UTF-8?q?=E5=99=A8=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/componets/MusicPlayer.ets | 236 +++++++++++------- .../view/Reader/DownloadSettingDialog.ets | 165 ++++++++++++ .../main/ets/pages/view/Reader/ReaderPage.ets | 210 +--------------- 3 files changed, 317 insertions(+), 294 deletions(-) create mode 100644 entry/src/main/ets/pages/view/Reader/DownloadSettingDialog.ets diff --git a/entry/src/main/ets/componets/MusicPlayer.ets b/entry/src/main/ets/componets/MusicPlayer.ets index ce8767ce..02b6f796 100644 --- a/entry/src/main/ets/componets/MusicPlayer.ets +++ b/entry/src/main/ets/componets/MusicPlayer.ets @@ -8,8 +8,11 @@ let seekTime: number = 15000 @Component export struct MusicPlayer { + @StorageLink('bottomRectHeight') bottomRectHeight: number = 0 + @StorageLink('topRectHeight') topRectHeight: number = 0 @StorageLink('WindowWidth') WindowWidth: number = 0 @Prop WidthMinus: number = 0 + @Link isShowListen: boolean @State hasInit: boolean = false; @State isMusicPlaying: boolean = false; // 音乐播放状态 @State MusicPlayingTime: number = 0 // 音乐目前播放时间 @@ -56,128 +59,173 @@ export struct MusicPlayer { } build() { - Column({ space: 24 }) { + Column() { Row() { - Stack() { - Flex() { - Text(`${this.formatMilliseconds(this.MusicPlayingTime)}/${this.formatMilliseconds(this.MusicDuration)}`) - .font({ - size: 10, - weight: 400 - }) - } - .margin({ - // 需要在模拟器查看 - left: (this.WindowWidth - this.WidthMinus) * this.MusicPlayingTime / this.MusicDuration + Image($r("app.media.direction_down")).width(24) + .onClick(() => { + this.isShowListen = false }) - .borderRadius(33) - .width(70) - .zIndex(2) - .backgroundColor('#FFFFFF') - .padding({ - top: 4, - bottom: 4, - left: 8, - right: 8 + Blank(1) + Text("大奉打更人") + .lineHeight(24) + .fontColor("#FFFFFF") + .font({ + size: 16, + weight: 500 }) + Blank(1) + Image($r("app.media.more")).width(24) + } + .height(48) + .width("100%") - Line().width("100%").height(2).backgroundColor('#FFFFFF') + + Blank(1) + Column() { + Row() { + Text("第1章 牢狱之灾") + } + + Row() { + Text("卖报小郎君") + Button("搜作者") + } + + Row() { + Text("许七安幽幽醒来,嗅到了空气中潮湿的腐臭") } - .alignContent(Alignment.Start) - .width("100%") } - Flex({ - direction: FlexDirection.Row, - justifyContent: FlexAlign.SpaceBetween, - alignItems: ItemAlign.Center - }) { - Image($r("app.media.Backward")) - .width(24) - .onClick(() => { - avPlayer.seek(this.MusicPlayingTime - seekTime < 0 ? 0 : this.MusicPlayingTime - seekTime, - media.SeekMode.SEEK_PREV_SYNC) - }) - Image($r("app.media.Previous")) - .width(24) - .onClick(() => { - }) - Image($r(this.isMusicPlaying ? "app.media.stop" : "app.media.music_play")) - .fillColor(Color.White) - .width(80) - .onClick(async () => { - if (this.isMusicPlaying) { - avPlayer.pause() - avPlayer.off('timeUpdate') - } else { - avPlayer.play() - this.timeUpdateCallback() + Column({ space: 24 }) { + Row() { + Stack() { + Flex() { + Text(`${this.formatMilliseconds(this.MusicPlayingTime)}/${this.formatMilliseconds(this.MusicDuration)}`) + .font({ + size: 10, + weight: 400 + }) } - }) + .margin({ + // 需要在模拟器查看 + left: (this.WindowWidth - this.WidthMinus) * this.MusicPlayingTime / this.MusicDuration + }) + .borderRadius(33) + .width(70) + .zIndex(2) + .backgroundColor('#FFFFFF') + .padding({ + top: 4, + bottom: 4, + left: 8, + right: 8 + }) - Image($r("app.media.next")) - .width(24) - .onClick(() => { - }) - Image($r("app.media.forward")) - .width(24) - .onClick(() => { - avPlayer.seek(this.MusicPlayingTime + seekTime, media.SeekMode.SEEK_NEXT_SYNC) - }) - } - .width("100%") + Line().width("100%").height(2).backgroundColor('#FFFFFF') + } + .alignContent(Alignment.Start) + .width("100%") + } - Flex({ - direction: FlexDirection.Row, - justifyContent: FlexAlign.SpaceBetween, - alignItems: ItemAlign.Center - }) { - Column() { - Image($r("app.media.appointment_time")) + Flex({ + direction: FlexDirection.Row, + justifyContent: FlexAlign.SpaceBetween, + alignItems: ItemAlign.Center + }) { + Image($r("app.media.Backward")) .width(24) .onClick(() => { + avPlayer.seek(this.MusicPlayingTime - seekTime < 0 ? 0 : this.MusicPlayingTime - seekTime, + media.SeekMode.SEEK_PREV_SYNC) }) - Text("定时") - } - - Column() { - Image($r("app.media.speed")) + Image($r("app.media.Previous")) .width(24) .onClick(() => { - }) - Text("语速") - }.bindSheet($$this.isShowSpeed, this.SpeedDialog(), { - height: 326, - showClose: false, - dragBar: false, - blurStyle: BlurStyle.COMPONENT_ULTRA_THIN, - }) - - Column() { - Image($r("app.media.add_bookshelf")) + Image($r(this.isMusicPlaying ? "app.media.stop" : "app.media.music_play")) .fillColor(Color.White) .width(80) - .onClick(() => { - + .onClick(async () => { + if (this.isMusicPlaying) { + avPlayer.pause() + avPlayer.off('timeUpdate') + } else { + avPlayer.play() + this.timeUpdateCallback() + } }) - Text("加书架") - } - Column() { - Image($r("app.media.directory")) + Image($r("app.media.next")) + .width(24) + .onClick(() => { + }) + Image($r("app.media.forward")) .width(24) .onClick(() => { + avPlayer.seek(this.MusicPlayingTime + seekTime, media.SeekMode.SEEK_NEXT_SYNC) }) - Text("目录") } - } - .width("100%") + .width("100%") - Row() { + Flex({ + direction: FlexDirection.Row, + justifyContent: FlexAlign.SpaceBetween, + alignItems: ItemAlign.Center + }) { + Column() { + Image($r("app.media.appointment_time")) + .width(24) + .onClick(() => { + }) + Text("定时") + } + + Column() { + Image($r("app.media.speed")) + .width(24) + .onClick(() => { + }) + Text("语速") + }.bindSheet($$this.isShowSpeed, this.SpeedDialog(), { + height: 326, + showClose: false, + dragBar: false, + blurStyle: BlurStyle.COMPONENT_ULTRA_THIN, + }) + + Column() { + Image($r("app.media.add_bookshelf")) + .fillColor(Color.White) + .width(80) + .onClick(() => { + + }) + Text("加书架") + } + + Column() { + Image($r("app.media.directory")) + .width(24) + .onClick(() => { + }) + Text("目录") + } + } + .width("100%") + + Row() { + + } } } + .height("100%") + .padding({ + top: this.topRectHeight, + bottom: this.bottomRectHeight, + left: 24, + right: 24 + }) } setCallback(avPlayer: media.AVPlayer) { diff --git a/entry/src/main/ets/pages/view/Reader/DownloadSettingDialog.ets b/entry/src/main/ets/pages/view/Reader/DownloadSettingDialog.ets new file mode 100644 index 00000000..8b99e2e5 --- /dev/null +++ b/entry/src/main/ets/pages/view/Reader/DownloadSettingDialog.ets @@ -0,0 +1,165 @@ +import { AddDownloadDialog } from 'ets/componets/Reader/AddDownloadDialog'; + +@Component +export default struct DownloadSettingDialog{ + @Link isShowDownload: boolean// 下载-缓存结束章节 + @Link isShowSetting: boolean// 下载-缓存结束章节 + // 加入下载列表Dialog + DownloadDialogController: CustomDialogController = new CustomDialogController({ + builder: AddDownloadDialog(), + cornerRadius: 8, + offset: { dx: 0, dy: -100 } + }) + @State StartText: string = "1" // 下载-缓存开始章节 + @State EndText: string = "2" // 下载-缓存结束章节 + controller: TextInputController = new TextInputController() + + build() { + Column() { + Grid() { + GridItem() { + Row() { + Text("缓存后50章") + Blank(1) + Checkbox() + } + .width("100%") + } + + GridItem() { + Row() { + Text("缓存后面全部章节") + Blank(1) + Checkbox() + } + .width("100%") + } + + GridItem() { + Row() { + Text("缓存全部") + Blank(1) + Checkbox() + } + .width("100%") + } + + GridItem() { + Row() { + Text("自定义缓存") + Blank(1) + Checkbox() + } + .width("100%") + } + + GridItem() { + Row({ space: 16 }) { + TextInput({ text: this.StartText, controller: this.controller }) + .type(InputType.Number) + .width(107) + .height(38) + .borderRadius(8) + .fontSize(20) + .fontWeight(400) + .lineHeight(22) + .textAlign(TextAlign.Center) + .backgroundColor("white") + .border({ + width: 1, + color: "gray" + }) + .onChange((value: string) => { + this.StartText = value + }) + + Text("至") + + TextInput({ text: this.EndText, controller: this.controller }) + .type(InputType.Number) + .width(107) + .height(38) + .borderRadius(8) + .fontSize(20) + .fontWeight(400) + .lineHeight(22) + .textAlign(TextAlign.Center) + .backgroundColor("white") + .border({ + width: 1, + color: "gray" + }) + .onChange((value: string) => { + this.EndText = value + }) + } + .width("100%") + } + } + .padding({ + top: 16 + }) + .height("80%") + .columnsTemplate("1fr") + .rowsTemplate("1fr 1fr 1fr 1fr 1fr") + + Blank(1) + Grid() { + GridItem() { + Button() { + Text("取消") + .lineHeight(24) + .fontColor($r('app.string.ThemeColor')) + .font({ + size: 16, + weight: 500 + }) + } + .width("80%") + .height(40) + .backgroundColor($r('app.string.BackgroundThemeColor')) + } + + GridItem() { + Button() { + Text("确定") + .fontColor("white") + .lineHeight(24) + .font({ + size: 16, + weight: 500 + }) + } + .width("80%") + .height(40) + .backgroundColor($r('app.string.ThemeColor')) + .onClick(() => { + this.isShowDownload = false + this.isShowSetting = false + this.DownloadDialogController.open() + setTimeout(() => { + this.DownloadDialogController.close() + }, 1000) + }) + } + } + .height(64) + .columnsTemplate("1fr 1fr") + .rowsTemplate("1fr") + .width("100%") + .onClick(() => { + this.isShowDownload = false + }) + .padding({ + top: 12, + bottom: 12 + }) + } + .height(500) + .padding({ + left: 20, + right: 20 + }) + } +} + diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index bc03602e..805b4571 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -3,10 +3,9 @@ import Dialog from 'ets/componets/common/Dialog'; import { router } from '@kit.ArkUI'; import sourceView from './sourceView'; import { FileHandler } from 'ets/common/utils/FileHandler'; -import { AddDownloadDialog } from 'ets/componets/Reader/AddDownloadDialog'; import { NetworkInput } from 'ets/componets/Reader/NetworkInput'; import { LengthMetrics } from '@ohos.arkui.node'; - +import DownloadSettingDialog from './DownloadSettingDialog'; import { MusicPlayer } from 'ets/componets/MusicPlayer'; import purificationView from './purificationView'; import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem'; @@ -28,7 +27,7 @@ struct ReaderPage { @State CurrentLuminance: number = 0 // 亮度 @State CurrentFontSize: number = 20 // 字号 @State LineHeight: string = "180%" - @State ParagraphSpacing: number = 0 + @State ParagraphSpacing: number = -2 controller: TextInputController = new TextInputController() // 网址导入Dialog dialogController: CustomDialogController = new CustomDialogController({ @@ -44,12 +43,6 @@ struct ReaderPage { gridCount: 4, offset: { dx: 0, dy: -300 } }) - // 加入下载列表Dialog - DownloadDialogController: CustomDialogController = new CustomDialogController({ - builder: AddDownloadDialog(), - cornerRadius: 8, - offset: { dx: 0, dy: -100 } - }) scroller: Scroller = new Scroller() @State isShowSource: boolean = false @State isShowPurification: boolean = false @@ -103,8 +96,8 @@ struct ReaderPage { .onClick(() => { this.isShowDownload = true }) - .bindSheet($$this.isShowDownload, this.ExportSettingDialog(), { - height: 326, + .bindSheet($$this.isShowDownload, this.DownloadDialog(), { + height: 500, showClose: false, dragBar: false, blurStyle: BlurStyle.COMPONENT_ULTRA_THIN, @@ -482,201 +475,18 @@ struct ReaderPage { @Builder BookListen() { - Column() { - Row() { - Image($r("app.media.direction_down")).width(24) - .onClick(() => { - this.isShowListen = false - }) - Blank(1) - Text("大奉打更人") - .lineHeight(24) - .fontColor("#FFFFFF") - .font({ - size: 16, - weight: 500 - }) - Blank(1) - Image($r("app.media.more")).width(24) - } - .height(48) + MusicPlayer({ WidthMinus: 118, isShowListen: this.isShowListen }) .width("100%") - - - Blank(1) - Column() { - Row() { - Text("第1章 牢狱之灾") - } - - Row() { - Text("卖报小郎君") - Button("搜作者") - } - - Row() { - Text("许七安幽幽醒来,嗅到了空气中潮湿的腐臭") - } - } - - MusicPlayer({ WidthMinus: 118 }) - } - .width("100%") - .height("100%") - .padding({ - top: this.topRectHeight, - bottom: this.bottomRectHeight, - left: 24, - right: 24 - }) + .height("100%") } @Builder - ExportSettingDialog() { + DownloadDialog() { Column() { - Grid() { - GridItem() { - Row() { - Text("缓存后50章") - Blank(1) - Checkbox() - } - .width("100%") - } - - GridItem() { - Row() { - Text("缓存后面全部章节") - Blank(1) - Checkbox() - } - .width("100%") - } - - GridItem() { - Row() { - Text("缓存全部") - Blank(1) - Checkbox() - } - .width("100%") - } - - GridItem() { - Row() { - Text("自定义缓存") - Blank(1) - Checkbox() - } - .width("100%") - } - - GridItem() { - Row({ space: 16 }) { - TextInput({ text: this.StartText, controller: this.controller }) - .type(InputType.Number) - .width(107) - .height(38) - .borderRadius(8) - .fontSize(20) - .fontWeight(400) - .lineHeight(22) - .textAlign(TextAlign.Center) - .backgroundColor("white") - .border({ - width: 1, - color: "gray" - }) - .onChange((value: string) => { - this.StartText = value - }) - - Text("至") - - TextInput({ text: this.EndText, controller: this.controller }) - .type(InputType.Number) - .width(107) - .height(38) - .borderRadius(8) - .fontSize(20) - .fontWeight(400) - .lineHeight(22) - .textAlign(TextAlign.Center) - .backgroundColor("white") - .border({ - width: 1, - color: "gray" - }) - .onChange((value: string) => { - this.EndText = value - }) - } - .width("100%") - } - } - .padding({ - top: 16 - }) - .height("80%") - .columnsTemplate("1fr") - .rowsTemplate("1fr 1fr 1fr 1fr 1fr") - - Blank(1) - Grid() { - GridItem() { - Button() { - Text("取消") - .lineHeight(24) - .fontColor($r('app.string.ThemeColor')) - .font({ - size: 16, - weight: 500 - }) - } - .width("80%") - .height(40) - .backgroundColor($r('app.string.BackgroundThemeColor')) - } - - GridItem() { - Button() { - Text("确定") - .fontColor("white") - .lineHeight(24) - .font({ - size: 16, - weight: 500 - }) - } - .width("80%") - .height(40) - .backgroundColor($r('app.string.ThemeColor')) - .onClick(() => { - this.isShowDownload = false - this.isShowSetting = false - this.DownloadDialogController.open() - setTimeout(() => { - this.DownloadDialogController.close() - }, 1000) - }) - } - } - .height(64) - .columnsTemplate("1fr 1fr") - .rowsTemplate("1fr") - .width("100%") - .onClick(() => { - this.isShowDownload = false - }) - .padding({ - top: 12, - bottom: 12 + DownloadSettingDialog({ + isShowDownload: this.isShowDownload, + isShowSetting: this.isShowSetting, }) } - .height("100%") - .padding({ - left: 20, - right: 20 - }) } } From 0ff029ec77fc21b947cd90ad04ec2e1b955224a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Mon, 1 Jul 2024 16:31:32 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/pages/view/Reader/ReaderPage.ets | 68 +++++++++---------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index 805b4571..c3798fc3 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -20,33 +20,16 @@ struct ReaderPage { @State isShowDownload: boolean = false @State isShowListen: boolean = false @State isShowContentSetting: boolean = false - @State StartText: string = "1" // 下载-缓存开始章节 - @State EndText: string = "2" // 下载-缓存结束章节 @State CurrentChapters: number = 0 @State TotalChapters: number = 0 @State CurrentLuminance: number = 0 // 亮度 @State CurrentFontSize: number = 20 // 字号 @State LineHeight: string = "180%" @State ParagraphSpacing: number = -2 - controller: TextInputController = new TextInputController() - // 网址导入Dialog - dialogController: CustomDialogController = new CustomDialogController({ - builder: Dialog({ - title: '加入书架', - CancelString: "暂不加入", - ConfirmString: "加入书架", - child: () => { - this.DialogString() - }, - }), - cornerRadius: 16, - gridCount: 4, - offset: { dx: 0, dy: -300 } - }) - scroller: Scroller = new Scroller() @State isShowSource: boolean = false @State isShowPurification: boolean = false @State txtFile: chaptersItem[] = []; + scroller: Scroller = new Scroller() async onPageShow() { let temp = router.getParams() as BookList @@ -55,23 +38,6 @@ struct ReaderPage { this.TotalChapters = this.txtFile.length } - @Builder - DialogString() { - Row() { - Text("喜欢就加入书架吧") - .lineHeight(22) - .font({ - size: 14, - weight: 400 - }) - .fontColor($r("app.string.color_black_45")) - } - .margin({ - top: 12, - bottom: 16 - }) - } - build() { Stack() { // 阅读器-上方弹框 @@ -468,6 +434,38 @@ struct ReaderPage { } } + @Builder + DialogString() { + Row() { + Text("喜欢就加入书架吧") + .lineHeight(22) + .font({ + size: 14, + weight: 400 + }) + .fontColor($r("app.string.color_black_45")) + } + .margin({ + top: 12, + bottom: 16 + }) + } + + // 网址导入Dialog + dialogController: CustomDialogController = new CustomDialogController({ + builder: Dialog({ + title: '加入书架', + CancelString: "暂不加入", + ConfirmString: "加入书架", + child: () => { + this.DialogString() + }, + }), + cornerRadius: 16, + gridCount: 4, + offset: { dx: 0, dy: -300 } + }) + onBackPress() { this.dialogController.open(); return true From bf8fbabe6d6547388a9c1182b1fc2723ad402812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=94=E4=B8=89=E7=9A=84=E9=9D=93=E4=BB=94?= Date: Mon, 1 Jul 2024 19:29:57 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E9=98=85=E8=AF=BB=E5=99=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/ets/pages/view/Reader/ReaderPage.ets | 592 +++++++++--------- 1 file changed, 296 insertions(+), 296 deletions(-) diff --git a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets index c3798fc3..37d5c723 100644 --- a/entry/src/main/ets/pages/view/Reader/ReaderPage.ets +++ b/entry/src/main/ets/pages/view/Reader/ReaderPage.ets @@ -40,158 +40,121 @@ struct ReaderPage { build() { Stack() { - // 阅读器-上方弹框 - if (this.isShowSetting) { - Column() { - Row({ space: 8 }) { - Image($r("app.media.ic_public_return_left")) - .width(24) - .onClick(() => { - router.back() - }) - Text(`第${this.txtFile[this.CurrentChapters]?.chapterTitleNumber}章 ${this.txtFile[this.CurrentChapters]?.title}`) - Blank(1) - Row({ space: 16 }) { - Image($r("app.media.refresh")) - .width(24) - .onClick(() => { - - }) - Image($r("app.media.down")) - .width(24) - .onClick(() => { - this.isShowDownload = true - }) - .bindSheet($$this.isShowDownload, this.DownloadDialog(), { - height: 500, - showClose: false, - dragBar: false, - blurStyle: BlurStyle.COMPONENT_ULTRA_THIN, - onDisappear: () => { - // this.clickBookType = '' - } - }) - Image($r("app.media.more")) + Column() { + if (this.isShowSetting) { + // 阅读器-上方弹框 + Column() { + Row({ space: 8 }) { + Image($r("app.media.ic_public_return_left")) .width(24) .onClick(() => { - + router.back() }) - } - } - .padding({ - top: 12, - left: 20, - right: 20, - bottom: 12 - }) - .width("100%") - - Row() { - NetworkInput() - } - .padding({ - top: 8, - left: 20, - right: 20, - bottom: 12 - }) - .width("100%") + Text(`第${this.txtFile[this.CurrentChapters]?.chapterTitleNumber}章 ${this.txtFile[this.CurrentChapters]?.title}`) + Blank(1) + Row({ space: 16 }) { + Image($r("app.media.refresh")) + .width(24) + .onClick(() => { - Divider() - } - .zIndex(2) - .backgroundColor("white") - .transition(TransitionEffect.move(TransitionEdge.TOP).animation({ duration: 500 })) - } + }) + Image($r("app.media.down")) + .width(24) + .onClick(() => { + this.isShowDownload = true + }) + .bindSheet($$this.isShowDownload, this.DownloadDialog(), { + height: 500, + showClose: false, + dragBar: false, + blurStyle: BlurStyle.COMPONENT_ULTRA_THIN, + onDisappear: () => { + // this.clickBookType = '' + } + }) + Image($r("app.media.more")) + .width(24) + .onClick(() => { - // 阅读器-小说内容 - Column() { - Row() { - } - .width("100%") - .height(40) + }) + } + } + .padding({ + top: 12, + left: 20, + right: 20, + bottom: 12 + }) + .width("100%") - Scroll(this.scroller) { - Column() { Row() { - Text(this.txtFile[this.CurrentChapters]?.title) - .lineHeight(20) - .font({ - size: 12, - weight: 400 - }) - .fontColor("rgba(0, 0, 0, 0.88)") + NetworkInput() } .padding({ - top: 16, - bottom: 16, - left: 24, - right: 24 + top: 8, + left: 20, + right: 20, + bottom: 12 }) .width("100%") - Text(this.txtFile[this.CurrentChapters]?.content) - .lineHeight(this.LineHeight) - .font({ - size: this.CurrentFontSize, // 用px感觉太小了,用vp算了 - weight: 400 - }) - .lineSpacing(LengthMetrics.vp(this.CurrentFontSize + this.ParagraphSpacing)) - .fontColor("rgba(0, 0, 0, 0.88)") - .width("100%") + Divider() } - .padding({ - left: 24, - right: 24 - }) - } - // .scrollable(ScrollDirection.Horizontal) - .layoutWeight(1) + .backgroundColor("white") + .transition(TransitionEffect.move(TransitionEdge.TOP).animation({ duration: 500 })) - - Blank(1) - Stack() { - Row({ space: 4 }) { - Text("1/14 0.1%") - Blank(1) - TextClock({ timeZoneOffset: -8 }) - .format('hh:mm') - .fontSize(12) - .fontWeight(400) - battery() - } - .padding({ - top: 16, - bottom: 16, - left: 24, - right: 24 - }) - .width("100%") + Blank(1) + .onClick(() => { + this.isShowSetting = false + }) // 阅读器-下方弹框 - if (this.isShowSetting) { - Column({ space: 20 }) { - Divider() - if (!this.isShowContentSetting) { - Row() { - Button({ type: ButtonType.Normal }) { - Row({ - space: 4 - }) { - Image($r("app.media.change_source_icon")).width(16).height(16) - Text("换源").fontColor($r('app.string.color_black_65')) - .font({ - size: 14, - weight: 400 - }) - } + Column({ space: 20 }) { + Divider() + if (!this.isShowContentSetting) { + Row() { + Button({ type: ButtonType.Normal }) { + Row({ + space: 4 + }) { + Image($r("app.media.change_source_icon")).width(16).height(16) + Text("换源").fontColor($r('app.string.color_black_65')) + .font({ + size: 14, + weight: 400 + }) } - .borderRadius(8) - .height(40) - .width("45%") - .backgroundColor("rgba(0, 0, 0, 0.06)") - .bindSheet($$this.isShowSource, this.sourceView(), { - height: '95%', + } + .borderRadius(8) + .height(40) + .width("45%") + .backgroundColor("rgba(0, 0, 0, 0.06)") + .bindSheet($$this.isShowSource, this.sourceView(), { + height: '95%', + showClose: false, + dragBar: false, + maskColor: 'rgba(0,0,0,0.6)', + onDisappear: () => { + console.log('隐藏') + } + }) + .onClick(() => { + this.isShowSource = true + }) + + Button({ type: ButtonType.Normal }) { + Row({ + space: 4 + }) { + Image($r("app.media.purify_icon")).width(16).height(16) + Text("净化").fontColor($r('app.string.color_black_65')) + .font({ + size: 14, + weight: 400 + }) + } + .bindSheet($$this.isShowPurification, this.purificationView(), { + height: '40%', showClose: false, dragBar: false, maskColor: 'rgba(0,0,0,0.6)', @@ -200,56 +163,61 @@ struct ReaderPage { } }) .onClick(() => { - this.isShowSource = true + this.isShowPurification = true }) + } + .borderRadius(8) + .height(40) + .width("45%") + .backgroundColor("rgba(0, 0, 0, 0.06)") + } + .padding({ + top: 12, + left: 24, + right: 24 + }) + .justifyContent(FlexAlign.SpaceBetween) + .width("100%") - Button({ type: ButtonType.Normal }) { - Row({ - space: 4 - }) { - Image($r("app.media.purify_icon")).width(16).height(16) - Text("净化").fontColor($r('app.string.color_black_65')) - .font({ - size: 14, - weight: 400 - }) - } - .bindSheet($$this.isShowPurification, this.purificationView(), { - height: '40%', - showClose: false, - dragBar: false, - maskColor: 'rgba(0,0,0,0.6)', - onDisappear: () => { - console.log('隐藏') - } - }) - .onClick(() => { - this.isShowPurification = true - }) + Row({ space: 16 }) { + Text("上一章").onClick(() => { + if (this.CurrentChapters > 0) { + this.CurrentChapters-- } - .borderRadius(8) - .height(40) - .width("45%") - .backgroundColor("rgba(0, 0, 0, 0.06)") - } - .padding({ - top: 12, - left: 24, - right: 24 }) - .justifyContent(FlexAlign.SpaceBetween) - .width("100%") - Row({ space: 16 }) { - Text("上一章").onClick(() => { - if (this.CurrentChapters > 0) { - this.CurrentChapters-- - } + Slider({ + value: this.CurrentChapters, + max: this.TotalChapters - 1, + min: 0, + step: 1, + style: SliderStyle.InSet + }) + .selectedColor('rgba(0, 0, 0, 0.04)') + .blockSize({ width: 30, height: 30 }) + .layoutWeight(1) + .onChange((value) => { + this.CurrentChapters = value }) + Text("下一章").onClick(() => { + if (this.CurrentChapters < this.TotalChapters - 1) { + this.CurrentChapters++ + } + }) + } + .padding({ + left: 24, + right: 24 + }) + .width("100%") + } else { + Column({ space: 24 }) { + Row({ space: 16 }) { + Text('亮度') Slider({ - value: this.CurrentChapters, - max: this.TotalChapters - 1, + value: this.CurrentLuminance, + max: 100, min: 0, step: 1, style: SliderStyle.InSet @@ -258,157 +226,189 @@ struct ReaderPage { .blockSize({ width: 30, height: 30 }) .layoutWeight(1) .onChange((value) => { - this.CurrentChapters = value + this.CurrentLuminance = value }) + Row() { + Text('跟随系统') + } + } - Text("下一章").onClick(() => { - if (this.CurrentChapters < this.TotalChapters - 1) { - this.CurrentChapters++ - } + Row({ space: 16 }) { + Text('字号') + Slider({ + value: this.CurrentFontSize, + max: 30, + min: 12, + step: 1, + style: SliderStyle.InSet }) - } - .padding({ - left: 24, - right: 24 - }) - .width("100%") - } else { - Column({ space: 24 }) { - Row({ space: 16 }) { - Text('亮度') - Slider({ - value: this.CurrentLuminance, - max: 100, - min: 0, - step: 1, - style: SliderStyle.InSet + .selectedColor('rgba(0, 0, 0, 0.04)') + .blockSize({ width: 30, height: 30 }) + .layoutWeight(1) + .onChange((value) => { + this.CurrentFontSize = value }) - .selectedColor('rgba(0, 0, 0, 0.04)') - .blockSize({ width: 30, height: 30 }) - .layoutWeight(1) - .onChange((value) => { - this.CurrentLuminance = value - }) - Row() { - Text('跟随系统') - } + Row() { + Button('字体') } + } - Row({ space: 16 }) { - Text('字号') - Slider({ - value: this.CurrentFontSize, - max: 30, - min: 12, - step: 1, - style: SliderStyle.InSet + Row({ space: 16 }) { + Text('排版') + Button('紧凑') + .onClick(() => { + this.LineHeight = "160%" + this.ParagraphSpacing = -4 }) - .selectedColor('rgba(0, 0, 0, 0.04)') - .blockSize({ width: 30, height: 30 }) - .layoutWeight(1) - .onChange((value) => { - this.CurrentFontSize = value - }) - Row() { - Button('字体') - } + Button('适中') + .onClick(() => { + this.LineHeight = "180%" + this.ParagraphSpacing = -2 + }) + Button('宽松') + .onClick(() => { + this.LineHeight = "200%" + this.ParagraphSpacing = 0 + }) + Row() { + Button('更多') } + } + } + .padding({ + left: 20, + right: 20 + }) - Row({ space: 16 }) { - Text('排版') - Button('紧凑') - .onClick(() => { - this.LineHeight = "160%" - this.ParagraphSpacing = -4 - }) - Button('适中') - .onClick(() => { - this.LineHeight = "180%" - this.ParagraphSpacing = -2 - }) - Button('宽松') - .onClick(() => { - this.LineHeight = "200%" - this.ParagraphSpacing = 0 - }) - Row() { - Button('更多') - } - } + } + Grid() { + GridItem() { + Column() { + Image($r("app.media.ic_public_return_left")).width(24) + Text("目录") } - .padding({ - left: 20, - right: 20 - }) + } + GridItem() { + Column() { + Image($r("app.media.listen")).width(24) + Text("听书") + } } - Grid() { - GridItem() { - Column() { - Image($r("app.media.ic_public_return_left")).width(24) - Text("目录") - } + .bindContentCover($$this.isShowListen, this.BookListen(), { + modalTransition: ModalTransition.DEFAULT, + backgroundColor: "rgba(51, 106, 128, 0.75)" + }) + .onClick(() => { + this.isShowListen = true + }) + + GridItem() { + Column() { + Image($r("app.media.night_icon")).width(24) + Text("夜间") } + } - GridItem() { - Column() { - Image($r("app.media.listen")).width(24) - Text("听书") - } + GridItem() { + Column() { + Image($r("app.media.my_center_set_icon")).width(24) + Text("设置") } - .bindContentCover($$this.isShowListen, this.BookListen(), { - modalTransition: ModalTransition.DEFAULT, - backgroundColor: "rgba(51, 106, 128, 0.75)" - }) .onClick(() => { - this.isShowListen = true + this.isShowContentSetting = !this.isShowContentSetting }) + } + } + .padding({ + left: 24, + right: 24 + }) + .columnsTemplate("1fr 1fr 1fr 1fr") + .width("100%") + .height(60) + } + .backgroundColor("white") + .transition(TransitionEffect.move(TransitionEdge.BOTTOM).animation({ duration: 500 })) + } + } + .width("100%") + .height("100%") + .zIndex(2) + .enabled(this.isShowSetting) - GridItem() { - Column() { - Image($r("app.media.night_icon")).width(24) - Text("夜间") - } - } + // 阅读器-小说内容 + Column() { + Row() { + } + .width("100%") + .height(40) - GridItem() { - Column() { - Image($r("app.media.my_center_set_icon")).width(24) - Text("设置") - } - .onClick(() => { - this.isShowContentSetting = !this.isShowContentSetting - }) - } - } - .padding({ - left: 24, - right: 24 - }) - .columnsTemplate("1fr 1fr 1fr 1fr") - .width("100%") - .height(60) + Scroll(this.scroller) { + Column() { + Row() { + Text(this.txtFile[this.CurrentChapters]?.title) + .lineHeight(20) + .font({ + size: 12, + weight: 400 + }) + .fontColor("rgba(0, 0, 0, 0.88)") } - .backgroundColor("white") - .transition(TransitionEffect.move(TransitionEdge.BOTTOM).animation({ duration: 500 })) - // .zIndex(2) - .onClick(() => { - // 这里必须有onclick,不然点击弹窗会消失,走下面的onclick逻辑 + .padding({ + top: 16, + bottom: 16, + left: 24, + right: 24 }) + .width("100%") + + Text(this.txtFile[this.CurrentChapters]?.content) + .lineHeight(this.LineHeight) + .font({ + size: this.CurrentFontSize, // 用px感觉太小了,用vp算了 + weight: 400 + }) + .lineSpacing(LengthMetrics.vp(this.CurrentFontSize + this.ParagraphSpacing)) + .fontColor("rgba(0, 0, 0, 0.88)") + .width("100%") } + .padding({ + left: 24, + right: 24 + }) + } + .layoutWeight(1) + + + Blank(1) + Row({ space: 4 }) { + Text("1/14 0.1%") + Blank(1) + TextClock({ timeZoneOffset: -8 }) + .format('hh:mm') + .fontSize(12) + .fontWeight(400) + battery() } - .alignContent(Alignment.Bottom) + .padding({ + top: 16, + bottom: 16, + left: 24, + right: 24 + }) + .width("100%") + } .height("100%") .onClick(() => { - this.isShowSetting = !this.isShowSetting + this.isShowSetting = true }) } .padding({ top: this.topRectHeight, bottom: this.bottomRectHeight }) - .alignContent(Alignment.TopStart) .height('100%') .width('100%') }