From ce8e0080bd6cb150968c114a424f59afc93dd770 Mon Sep 17 00:00:00 2001 From: 2008 <59199830@qq.com> Date: Tue, 23 Jul 2024 23:18:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=B9=A6=E6=9E=B6?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=B9=A6=E6=9E=B6db=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E3=80=81=E7=9B=AE=E5=89=8D=E6=9A=82=E6=97=B6=E4=BB=85?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=9C=AC=E5=9C=B0=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重构书架页面,书架db操作、目前暂时仅支持本地导入 --- .../ets/common/constants/CommonConstants.ets | 1 + .../src/main/ets/common/utils/FileHandler.ets | 30 +- .../src/main/ets/common/utils/booksUtils.ets | 15 + .../ets/componets/head/IndexSearchType.ets | 2 - .../main/ets/database/AppDatabase/index.ets | 101 +++-- entry/src/main/ets/database/dao/BooksDao.ets | 155 ++++++++ .../main/ets/database/entities/BookGroups.ets | 29 ++ .../main/ets/database/entities/Bookmark.ets | 17 + .../src/main/ets/database/entities/Books.ets | 78 ++++ entry/src/main/ets/database/index.ets | 2 + .../src/main/ets/database/types/BooksType.ets | 13 + entry/src/main/ets/pages/Index.ets | 8 - .../main/ets/pages/view/BookDetailPage.ets | 16 +- .../ets/pages/view/bookShelf/IndexShelf.ets | 356 ++++-------------- .../bookShelf/components/BookBodyContent.ets | 196 ++++++++++ .../view/bookShelf/components/BookContent.ets | 82 ++++ .../components/BookContentRefresh.ets | 78 ++++ .../bookShelf/components/BookInfoGrids.ets | 135 +++++++ .../view/bookShelf/components/BookInfos.ets | 172 +++++++++ .../components/dialog/BookInfoDialogs.ets | 142 +++++++ .../ets/pages/view/bookShelf/novelPage.ets | 206 +++++----- entry/src/main/ets/storage/bookListData.ets | 1 + 22 files changed, 1376 insertions(+), 459 deletions(-) create mode 100644 entry/src/main/ets/common/utils/booksUtils.ets create mode 100644 entry/src/main/ets/database/dao/BooksDao.ets create mode 100644 entry/src/main/ets/database/entities/BookGroups.ets create mode 100644 entry/src/main/ets/database/entities/Bookmark.ets create mode 100644 entry/src/main/ets/database/entities/Books.ets create mode 100644 entry/src/main/ets/database/types/BooksType.ets create mode 100644 entry/src/main/ets/pages/view/bookShelf/components/BookBodyContent.ets create mode 100644 entry/src/main/ets/pages/view/bookShelf/components/BookContent.ets create mode 100644 entry/src/main/ets/pages/view/bookShelf/components/BookContentRefresh.ets create mode 100644 entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets create mode 100644 entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets create mode 100644 entry/src/main/ets/pages/view/bookShelf/components/dialog/BookInfoDialogs.ets diff --git a/entry/src/main/ets/common/constants/CommonConstants.ets b/entry/src/main/ets/common/constants/CommonConstants.ets index 6aefd748..d45f867e 100644 --- a/entry/src/main/ets/common/constants/CommonConstants.ets +++ b/entry/src/main/ets/common/constants/CommonConstants.ets @@ -232,6 +232,7 @@ export default class CommonConstants { static readonly GROUP_LIST_DATA:string = 'GROUP_LIST_DATA' static readonly SHELF_LIST_DATA:string = 'SHELF_LIST_DATA' static readonly HAS_EXPLORE_URL:string = 'HAS_EXPLORE_URL' + static readonly BOOK_IS_BOOK_REFRESHING:string = 'BOOK_IS_BOOK_REFRESHING' // 订阅源分组数据 //分组是否初始化key static readonly RSS_SOURCES_GROUP_INIT:string = 'RSS_SOURCES_GROUP_INIT' diff --git a/entry/src/main/ets/common/utils/FileHandler.ets b/entry/src/main/ets/common/utils/FileHandler.ets index 6e11bf7d..07c9996d 100644 --- a/entry/src/main/ets/common/utils/FileHandler.ets +++ b/entry/src/main/ets/common/utils/FileHandler.ets @@ -2,11 +2,11 @@ import { BusinessError } from '@ohos.base'; import fs, { Options, WriteOptions } from '@ohos.file.fs'; import { common, Context } from '@kit.AbilityKit'; import { chaptersItem } from 'ets/componets/dataList/ReaderChaptersItem'; -import { BookList } from '../../componets/dataList/bookList'; -import { addShelfBook } from '../../storage/bookListData'; import { showMessage } from '../../componets/common/promptShow'; -import { fileIo, picker } from '@kit.CoreFileKit'; +import { picker } from '@kit.CoreFileKit'; import { util } from '@kit.ArkTS'; +import { Books } from '../../database/entities/Books'; +import booksUtil from './booksUtils'; let context = getContext(this) as common.UIAbilityContext; let filePath = context.filesDir; @@ -16,12 +16,28 @@ let options: Options = { }; export class FileHandler { - static CopyFile(srcUrl: string) { + static CopyFile(srcUrl: string, currentIndex:number) { 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)) + let book:Books = { + bookName: file.name, + bookUrl: dstPath, + author: '暂无', + bookGroup: 2, + latestChapterTime: 0, + totalChapterNum: 0, + durChapterIndex: 0, + durChapterPos: 0, + durChapterTime: 0, + canUpdate: false, + sort: 0, + originOrder: 0, + syncTime: 0, + bookType: currentIndex, + isTop: false, + isJoin: false + } + booksUtil.addBooks(book) showMessage('添加到书架成功') fs.copyFile(file.fd, dstPath, 0).then(() => { showMessage('导入沙箱成功') diff --git a/entry/src/main/ets/common/utils/booksUtils.ets b/entry/src/main/ets/common/utils/booksUtils.ets new file mode 100644 index 00000000..d6329a61 --- /dev/null +++ b/entry/src/main/ets/common/utils/booksUtils.ets @@ -0,0 +1,15 @@ +/** + * @author 2008 + * @datetime 2024/7/23 10:58 + * @className: booksUtils + */ +import BooksDao from '../../database/dao/BooksDao' +import { Books } from '../../database/entities/Books' + +class booksUtils{ + addBooks(books: Books){ + BooksDao.insert(books) + } +} +let booksUtil = new booksUtils(); +export default booksUtil as booksUtils; \ No newline at end of file diff --git a/entry/src/main/ets/componets/head/IndexSearchType.ets b/entry/src/main/ets/componets/head/IndexSearchType.ets index 7a0da761..b4c5a47c 100644 --- a/entry/src/main/ets/componets/head/IndexSearchType.ets +++ b/entry/src/main/ets/componets/head/IndexSearchType.ets @@ -3,9 +3,7 @@ export default struct IndexSearchType { @Prop title:string @Link searchValue:string @State isShown: boolean = false - @State THEME_NAME: string[] = ['最近阅读', '阅读排序', '更新排序', '手动排序'] - // @State THEME_NAMES: string[] = [] build() { if (this.THEME_NAME.includes(this.title)){ diff --git a/entry/src/main/ets/database/AppDatabase/index.ets b/entry/src/main/ets/database/AppDatabase/index.ets index dc17a4c7..1e3c8b81 100644 --- a/entry/src/main/ets/database/AppDatabase/index.ets +++ b/entry/src/main/ets/database/AppDatabase/index.ets @@ -8,53 +8,55 @@ export default { "entities": [ { "tableName": "books", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`bookUrl` TEXT NOT NULL DEFAULT '', `tocUrl` TEXT NOT NULL DEFAULT '', `origin` TEXT NOT NULL DEFAULT 'loc_book', `originName` TEXT NOT NULL DEFAULT '', `name` TEXT NOT NULL DEFAULT '', `author` TEXT NOT NULL DEFAULT '', `kind` TEXT, `customTag` TEXT, `coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `type` INTEGER NOT NULL DEFAULT 0, `group` INTEGER NOT NULL DEFAULT 0, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL DEFAULT 0, `lastCheckTime` INTEGER NOT NULL DEFAULT 0, `lastCheckCount` INTEGER NOT NULL DEFAULT 0, `totalChapterNum` INTEGER NOT NULL DEFAULT 0, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL DEFAULT 0, `durChapterPos` INTEGER NOT NULL DEFAULT 0, `durChapterTime` INTEGER NOT NULL DEFAULT 0, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL DEFAULT 1, `order` INTEGER NOT NULL DEFAULT 0, `originOrder` INTEGER NOT NULL DEFAULT 0, `variable` TEXT, `readConfig` TEXT, `syncTime` INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(`bookUrl`))", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` ( `id` INTEGER NOT NULL, `bookUrl` TEXT, `toUrl` TEXT, `origin` TEXT, `originName` TEXT, `bookName` TEXT NOT NULL, `author` TEXT, `cover` TEXT, `customTag` TEXT, `coverUrl` TEXT, `customCoverUrl` TEXT, `intro` TEXT, `customIntro` TEXT, `charset` TEXT, `bookGroup` INTEGER NOT NULL DEFAULT 0, `latestChapterTitle` TEXT, `latestChapterTime` INTEGER NOT NULL DEFAULT 0, `lastCheckTime` INTEGER NOT NULL DEFAULT 0, `lastCheckCount` INTEGER NOT NULL DEFAULT 0, `totalChapterNum` INTEGER NOT NULL DEFAULT 0, `durChapterTitle` TEXT, `durChapterIndex` INTEGER NOT NULL DEFAULT 0, `durChapterPos` INTEGER NOT NULL DEFAULT 0, `durChapterTime` INTEGER NOT NULL DEFAULT 0, `wordCount` TEXT, `canUpdate` INTEGER NOT NULL DEFAULT 1, `sort` INTEGER NOT NULL DEFAULT 0, `originOrder` INTEGER NOT NULL DEFAULT 0, `syncTime` INTEGER NOT NULL DEFAULT 0, `bookType` INTEGER NOT NULL DEFAULT 0, `isTop` INTEGER NOT NULL DEFAULT 0, `createTime` INTEGER NOT NULL DEFAULT 0,`updateTime` INTEGER NOT NULL DEFAULT 0,`isJoin` INTEGER NOT NULL DEFAULT 1,PRIMARY KEY ( `id` ))", "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER", + "notNull": true + }, { "fieldPath": "bookUrl", "columnName": "bookUrl", "affinity": "TEXT", - "notNull": true, - "defaultValue": "''" + "notNull": false }, { - "fieldPath": "tocUrl", - "columnName": "tocUrl", + "fieldPath": "toUrl", + "columnName": "toUrl", "affinity": "TEXT", - "notNull": true, - "defaultValue": "''" + "notNull": false }, { "fieldPath": "origin", "columnName": "origin", "affinity": "TEXT", - "notNull": true, - "defaultValue": "'loc_book'" + "notNull": false }, { "fieldPath": "originName", "columnName": "originName", "affinity": "TEXT", - "notNull": true, - "defaultValue": "''" + "notNull": false }, { - "fieldPath": "name", - "columnName": "name", + "fieldPath": "bookName", + "columnName": "bookName", "affinity": "TEXT", "notNull": true, - "defaultValue": "''" + "defaultValue":"" }, { "fieldPath": "author", "columnName": "author", "affinity": "TEXT", "notNull": true, - "defaultValue": "''" + "defaultValue": "" }, { - "fieldPath": "kind", - "columnName": "kind", + "fieldPath": "cover", + "columnName": "cover", "affinity": "TEXT", "notNull": false }, @@ -95,15 +97,8 @@ export default { "notNull": false }, { - "fieldPath": "type", - "columnName": "type", - "affinity": "INTEGER", - "notNull": true, - "defaultValue": "0" - }, - { - "fieldPath": "group", - "columnName": "group", + "fieldPath": "bookGroup", + "columnName": "bookGroup", "affinity": "INTEGER", "notNull": true, "defaultValue": "0" @@ -179,12 +174,13 @@ export default { "fieldPath": "canUpdate", "columnName": "canUpdate", "affinity": "INTEGER", + "boolean": true, "notNull": true, "defaultValue": "1" }, { - "fieldPath": "order", - "columnName": "order", + "fieldPath": "sort", + "columnName": "sort", "affinity": "INTEGER", "notNull": true, "defaultValue": "0" @@ -197,41 +193,64 @@ export default { "defaultValue": "0" }, { - "fieldPath": "variable", - "columnName": "variable", - "affinity": "TEXT", + "fieldPath": "syncTime", + "columnName": "syncTime", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "bookType", + "columnName": "bookType", + "affinity": "INTEGER", + "notNull": true, + "defaultValue": "0" + }, + { + "fieldPath": "isTop", + "columnName": "isTop", + "affinity": "isTop", + "boolean": true, + "notNull": true, + "defaultValue": "1" + }, + { + "fieldPath": "createTime", + "columnName": "createTime", + "affinity": "INTEGER", "notNull": false }, { - "fieldPath": "readConfig", - "columnName": "readConfig", - "affinity": "TEXT", + "fieldPath": "updateTime", + "columnName": "updateTime", + "affinity": "INTEGER", "notNull": false }, { - "fieldPath": "syncTime", - "columnName": "syncTime", + "fieldPath": "isJoin", + "columnName": "isJoin", "affinity": "INTEGER", + "boolean": true, "notNull": true, - "defaultValue": "0" + "defaultValue": "1" } ], "primaryKey": { "autoGenerate": false, "columnNames": [ - "bookUrl" + "id" ] }, "indices": [ { - "name": "index_books_name_author", + "name": "index_books_bookName_author", "unique": true, "columnNames": [ - "name", + "bookName", "author" ], "orders": [], - "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_books_name_author` ON `${TABLE_NAME}` (`name`, `author`)" + "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_books_bookName_author` ON `${TABLE_NAME}` (`bookName`, `author`)" } ], "foreignKeys": [] diff --git a/entry/src/main/ets/database/dao/BooksDao.ets b/entry/src/main/ets/database/dao/BooksDao.ets new file mode 100644 index 00000000..7c5e2a03 --- /dev/null +++ b/entry/src/main/ets/database/dao/BooksDao.ets @@ -0,0 +1,155 @@ +/** + * @author 2008 + * @datetime 2024/7/22 23:05 + * @className: BooksDao + * 订阅源 + */ +import DbUtil from '../../common/utils/DbUtil'; +import AppDatabaseUtil from '../AppDatabaseUtil'; +import { Books } from '../entities/Books'; +import { BooksTypeSearchParams } from '../types/BooksType'; +import { ColumnInfo } from '../types/ColumnInfo'; + +class BooksDao { + TABLE_NAME: string = 'books' + + // 创建books数据表 + async initBooksTable() { + try { + const createSql = AppDatabaseUtil.getCreateSql(this.TABLE_NAME); + if (!createSql) { + return + } + await DbUtil.createTable(createSql) + AppDatabaseUtil.existsTable(this.TABLE_NAME) + return + } catch (err) { + console.info('TagInfo', JSON.stringify(err)) + } + } + + async search(param?:BooksTypeSearchParams) { + let searchKey = param?.searchKey ?? ''; + let type = param?.type; + let bookGroup = param?.bookGroup; + try { + const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); + let sql = `SELECT * FROM ${this.TABLE_NAME}`; + // 动态添加 WHERE 子句 + let whereClause: string[] = []; + if (type !== undefined) { + whereClause.push(`bookType = ${type}`); + } + if (bookGroup !== undefined) { + whereClause.push(`bookGroup = ${bookGroup}`); + } + if (searchKey) { + whereClause.push(`( + bookName LIKE '%${searchKey}%' + author LIKE '%${searchKey}%' + originName LIKE '%${searchKey}%' + )`); + + } + // 如果有 where 子句,添加 WHERE 关键字 + if (whereClause.length > 0) { + sql += ` WHERE ${whereClause.join(' AND ')}`; + } + sql += ` + ORDER BY + id DESC +`; + const bookDbList = await DbUtil.querySqlForList(sql, column); + console.log("TagInfo", '书籍:' + bookDbList.length) + return bookDbList + } catch (err) { + console.log("TagInfo", JSON.stringify(err)) + return [] + } + } + + async batchInsert(books: Books[]) { + try { + for (let index = 0; index < books.length; index++) { + const book = books[index]; + await this.insert(book) + } + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + } + + async insert(books: Books) { + try { + const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); + if (books.id) { + const predicates = DbUtil.getPredicates(this.TABLE_NAME); + predicates.equalTo('id', books.id) + const count = await DbUtil.queryForCount(predicates, column) + if (count > 0) { + this.update(books) + return true + } + } + books.createTime = Date.now() + await DbUtil.insert(this.TABLE_NAME, books, column) + console.log('TagInfo', '创建成功') + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + } + + async update(books: Books) { + try { + const column: ColumnInfo[] = AppDatabaseUtil.getColumn(this.TABLE_NAME); + const predicates = DbUtil.getPredicates(this.TABLE_NAME); + predicates.equalTo('id', books.id) + const count = await DbUtil.queryForCount(predicates, column) + if (count === 0 && books instanceof Books) { + // books.createTime = Date.now() + this.insert(books) + return true + } + await DbUtil.update(predicates, books, column) + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + + } + + //批量删除订阅源历史记录 + async deleteBookList(books: Books[]) { + try { + for (let index = 0; index < books.length; index++) { + await this.deleteBook(books[index]?.id||0) + } + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + } + + //删除订阅源历史记录 + async deleteBook(bookId: number) { + try { + const predicates = DbUtil.getPredicates(this.TABLE_NAME); + predicates.equalTo('bookId', bookId) + await DbUtil.delete(predicates) + return true + } catch (err) { + console.log('TagInfo, Error, ', JSON.stringify(err)) + return false + } + } +} + + +const booksDao = new BooksDao() +export default booksDao as BooksDao \ No newline at end of file diff --git a/entry/src/main/ets/database/entities/BookGroups.ets b/entry/src/main/ets/database/entities/BookGroups.ets new file mode 100644 index 00000000..b55f0c49 --- /dev/null +++ b/entry/src/main/ets/database/entities/BookGroups.ets @@ -0,0 +1,29 @@ +/** + * @author 2008 + * @datetime 2024/7/22 22:39 + * @className: BookGroup + * 书籍分组 + */ +@Observed +export class BookGroups { + //分组Id + groupId:number = 0; + //分组名称 + groupName:string = ""; + //分组封面 + coverUrl?:string; + //分组描述 + groupDescribe:string = ""; + //排序 + order:number = 0; + //是否自动刷新 + enableRefresh:boolean = true; + //是否显示 + show:boolean = true; + //小说0/漫画1/有声2 + groupType:number = 0; + //创建时间 + createTime:number = 0; + //更新时间 + updateTime:number = 0; +} \ No newline at end of file diff --git a/entry/src/main/ets/database/entities/Bookmark.ets b/entry/src/main/ets/database/entities/Bookmark.ets new file mode 100644 index 00000000..eb2e69ab --- /dev/null +++ b/entry/src/main/ets/database/entities/Bookmark.ets @@ -0,0 +1,17 @@ +@Observed +export class Bookmark { + //书单Id + markId:number = 0; + //书单名称 + markName:string = ""; + //书单描述 + markDescribe:string = ""; + //备注 + markRemark:string = ""; + //书单添加的书籍Id分割请用, + markBooks?:string; + //推荐理由 + markRecommend:string = ""; + //创建时间 + createTime:number = 0; +} \ No newline at end of file diff --git a/entry/src/main/ets/database/entities/Books.ets b/entry/src/main/ets/database/entities/Books.ets new file mode 100644 index 00000000..89c773f8 --- /dev/null +++ b/entry/src/main/ets/database/entities/Books.ets @@ -0,0 +1,78 @@ +/** + * @author 2008 + * @datetime 2024/7/22 21:21 + * @className: Books + * 书籍 + */ + +@Observed +export class Books { + //书籍ID + id?:number; + //书籍存储路径 + bookUrl?:string + //目录页Url + toUrl?:string + // 书源URL + origin?:string + //书源名称 or 本地书籍文件名 + originName?:string + // 书籍名称(书源获取) 或则自定义书籍名称 + bookName:string = "" + // // 作者名称(书源获取) + author: string = "" + //分类信息(书源获取) + cover?:string + //分类信息 + customTag?:string + //封面Url(书源获取) + coverUrl?:string + //自定义封面Url + customCoverUrl?:string + //简介内容(书源获取) + intro?:string + //简介内容(用户修改) + customIntro?:string + //自定义字符集名称(仅适用于本地书籍) + charset?:string + //在导入的情况下或则未分组默认为2 未分组 + bookGroup:number = 2; + // 最新章节标题 + latestChapterTitle?:string + // 最新章节标题更新时间 + latestChapterTime:number = 0; + //最近一次更新书籍信息的时间 + lastCheckTime?:number + //最近一次发现新章节的数量 + lastCheckCount?:number + //书籍目录总数 + totalChapterNum:number = 0; + //当前章节名称 + durChapterTitle?:string + //当前章节索引 + durChapterIndex:number = 0 + //当前阅读的进度(首行字符的索引位置) + durChapterPos:number = 0 + //最近一次阅读书籍的时间(打开正文的时间) + durChapterTime:number = 0 + //字数 + wordCount?:string + //刷新书架时更新书籍信息 + canUpdate:boolean = true + //排序 + sort:number = 0 + //书源排序 + originOrder:number = 0 + //同步时间 + syncTime:number = 0 + //小说0/漫画1/有声2 + bookType:number = 0 + //是否置顶 + isTop:boolean = false + //创建时间 + createTime?:number = 0 + //更新时间 + updateTime?:number = 0 + //是否加入书架 + isJoin:boolean = false +} \ No newline at end of file diff --git a/entry/src/main/ets/database/index.ets b/entry/src/main/ets/database/index.ets index 3cfd75c1..73fe8306 100644 --- a/entry/src/main/ets/database/index.ets +++ b/entry/src/main/ets/database/index.ets @@ -1,3 +1,4 @@ +import BooksDao from './dao/BooksDao' import BookSourceDao from './dao/BookSourceDao' import rssSourcesHistoryDao from './dao/RssSourcesHistoryDao' import SubscriptionDao from './dao/SubscriptionDao' @@ -7,6 +8,7 @@ class DataBase { await BookSourceDao.initBookSourceTable() await rssSourcesHistoryDao.initRssSourcesHistoryTable() await SubscriptionDao.initSubscriptionTable() + await BooksDao.initBooksTable() } } diff --git a/entry/src/main/ets/database/types/BooksType.ets b/entry/src/main/ets/database/types/BooksType.ets new file mode 100644 index 00000000..186bd389 --- /dev/null +++ b/entry/src/main/ets/database/types/BooksType.ets @@ -0,0 +1,13 @@ +/** + * @author 2008 + * @datetime 2024/7/23 11:02 + * @className: BooksType + */ +export interface BooksTypeSearchParams { + // 搜索关键词书源名称/书籍名称/author + searchKey?: string, + // 源类型 0 小说;1 漫画;2 有声书; + type?: number, + //分组 + bookGroup: number +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index ee13e50d..a193b88b 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -60,14 +60,6 @@ struct Main { new NavItem(3, $r('app.media.MINE_theme'),$r('app.media.MINE_line'), '我的') ] - // @State scrollType:MainScrollBar[] = [ - // new MainScrollBar(false,new Scroller()), - // new MainScrollBar(false,new Scroller()), - // new MainScrollBar(false,new Scroller()), - // new MainScrollBar(false,new Scroller()), - // new MainScrollBar(false,new Scroller()) - // ] - build() { Column() { Tabs({ diff --git a/entry/src/main/ets/pages/view/BookDetailPage.ets b/entry/src/main/ets/pages/view/BookDetailPage.ets index 3f8c9367..6af86dd5 100644 --- a/entry/src/main/ets/pages/view/BookDetailPage.ets +++ b/entry/src/main/ets/pages/view/BookDetailPage.ets @@ -3,10 +3,10 @@ import ReadRecordItem from '../../componets/bookDetail/ReadRecordItem' import TagIndex from '../../componets/bookDetail/TagIndex' import { router, SwipeRefresher } from '@kit.ArkUI' import NoteIndex from '../../componets/bookDetail/note/NoteIndex' -import { BookList } from 'ets/componets/dataList/bookList' import { chaptersItem } from '../../componets/dataList/ReaderChaptersItem' import { FileHandler } from '../../common/utils/FileHandler' import ChaptersDataSource from '../../common/LazyIDataSource/ChaptersDataSource' +import { Books } from '../../database/entities/Books' /** * 标题图片样式 @@ -73,7 +73,7 @@ struct BookDetailPage { @State currentIndex: number = 0; // 是否加入书架 @State isAddBookShelf: boolean = false; - @State bookData: BookList = router.getParams() as BookList + @State bookData: Books = router.getParams() as Books // 加入书架dialog dialogController: CustomDialogController = new CustomDialogController({ builder: AddBookShelfDialog(), @@ -85,10 +85,10 @@ struct BookDetailPage { onPageShow() { this.isShow = true console.log('router BookDetailPage:' + JSON.stringify(router.getParams())) - if (router.getParams() as BookList) { - this.bookData = router.getParams() as BookList + if (router.getParams() as Books) { + this.bookData = router.getParams() as Books setTimeout(async () => { - let temp = await FileHandler.readFile(this.bookData.fileLink) //txt小说 + let temp = await FileHandler.readFile(this.bookData?.bookUrl||'') //txt小说 this.txtFile.pushAllData(temp) this.txtFiles = this.txtFile.getListData() },0) @@ -328,12 +328,12 @@ struct BookDetailPage { // 小说标题 Row({ space: CommonConstants.SPACE_20 }) { - Image(this.bookData.bookImage ?? $r('app.media.cover_list')) + Image(this.bookData.coverUrl?? $r('app.media.cover_list')) .width(CommonConstants.NOVEL_IMG_WIDTH) .height(CommonConstants.NOVEL_IMG_HEIGHT) .borderRadius(5) Column({ space: 8 }) { - Text(this.bookData.title.replace(new RegExp('\\..*', 'g'), '')) + Text(this.bookData.bookName.replace(new RegExp('\\..*', 'g'), '')) .fontColor(Color.White) .fontSize(20) Blank() @@ -395,7 +395,7 @@ struct BookDetailPage { // 书籍简介 Flex() { - Text(this.bookData.describe ?? '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + + Text(this.bookData.intro ?? '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + '\n他起初的目的只是自保,顺便在这个没有人权的社会里当个富家翁悠闲度日。 ...... 多年后,许七安回首前尘,身后是早已逝去的敌人,以及累累白骨。 ' + '\n滚滚长江东逝水,浪花淘尽英雄,是非成败转头空。 ' + '\n青山依旧在,几度夕阳红。') diff --git a/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets b/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets index 66bfc0f7..5144fd8a 100644 --- a/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets +++ b/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets @@ -1,107 +1,28 @@ -import cartoonPage from './cartoonPage' -import novelPage from './novelPage' import BookMark from '../../../componets/head/BookMark' - -import soundPage from './soundPage' -import IndexSearchType from '../../../componets/head/IndexSearchType' -import router from '@ohos.router'; // 引入路由管理器 -import confirmDialogExample from '../../../componets/common/confirmDialog' -import Dialog from 'ets/componets/common/Dialog' -import BookFolder from './BookFolder' -import groupTypeComponent from '../../../componets/group/GroupType' -import ShelfBookList from './Shelf/ShelfBookList' - -import picker from '@ohos.file.picker' -import { FileHandler } from 'ets/common/utils/FileHandler' -import RefreshComponent from '../../../componets/common/RefreshComponent' -import CommonConstants from '../../../common/constants/CommonConstants' +import { router } from '@kit.ArkUI' +import BookBodyContent from './components/BookBodyContent' +import { picker } from '@kit.CoreFileKit' +import { FileHandler } from '../../../common/utils/FileHandler' +import Dialog from '../../../componets/common/Dialog' +import { sleep } from '../../../common/utils/utils' @Component export default struct IndexShelf { - @State delCache: boolean = false - IndexShelf: CustomDialogController | null = new CustomDialogController({ - builder: confirmDialogExample({ - cancel: () => { - this.onCancel() - }, - confirm: () => { - this.onAccept() - }, - title: '清空', - delCache: this.delCache - }), - cancel: this.exitApp, - autoCancel: true, - alignment: DialogAlignment.Center, - // offset: { dx: 0, dy: '-40%' }, - gridCount: 4, - customStyle: false, - cornerRadius: 25 - }) @State currentIndex: number = 0 THEME_NAMES: string[] = ['书籍导入', '下载管理', '导入书单', '批量管理'] - EXHIBIT_NAMES: string[] = ['列表', '宫格'] - GROUP_NAMES: string[] = ['标签', '文件夹'] + titleArray: Array = ['小说', '漫画', '有声书'] + + @State bookType:string = '全部' @State EXHIBIT: string = '列表' @State GROUP: string = '标签' @State searchValue: string = '最近阅读' - @State bookType: string = '全部' - @State title: string = '最近阅读' @State isClear: boolean = false - @State isRefreshing: boolean = false - @State counter: number = 0 - @State RefreshingTitle: string = '松开刷新' - @State groupCoverShow: boolean = false + @State isShowImport: boolean = false @State isShowCloudImport: boolean = false @State isShowImportBookList: boolean = false @StorageLink('topRectHeight') topRectHeight: number = 0 @StorageProp('APP_INDEX_SCROLLABLE') APP_INDEX_SCROLLABLE: boolean = false - // 网址导入dialog - dialogController: CustomDialogController = new CustomDialogController({ - builder: Dialog({ - title: '网址导入', - child: () => { - this.DialogInput("请输入书籍目录或详情页", 10) - } - }), - cornerRadius: 8, - offset: { dx: 0, dy: 0 } - }) - tabsController: TabsController = new TabsController(); - private scrollController: Scroller = new Scroller(); - - onAccept() { - console.info('确定') - this.isClear = true - } - - onCancel() { - console.info('取消') - } - - exitApp() { - console.info('点外围取消') - } - - @Builder - DialogInput(placeholder: string, maxlength: number) { - Row() { - TextInput({ placeholder: placeholder }) - .maxLength(maxlength) - .showCounter(true) - .cancelButton({ - icon: { - src: $r('app.media.close') - } - }) - } - .margin({ - top: 16, - bottom: 16 - }) - } - build() { Column() { Flex({ @@ -225,215 +146,43 @@ export default struct IndexShelf { Tabs({ barPosition: BarPosition.Start, - controller: this.tabsController + controller: this.tabsController, + index: this.currentIndex }) { - TabContent() { - this.book() - } - - TabContent() { - this.book() - } - - TabContent() { - this.book() - } + ForEach(this.titleArray, () => { + TabContent() { + Column(){ + BookBodyContent({ + currentIndex: this.currentIndex, + EXHIBIT: this.EXHIBIT, + GROUP: this.GROUP, + searchValue: this.searchValue, + isClear: this.isClear, + bookType: this.bookType + }) + } + } + }) } .layoutWeight(1) .barWidth(0) .barHeight(0) .onChange((index) => { this.tabsController.changeIndex(index) - console.log('index:' + index) this.currentIndex = index }) .backgroundColor(Color.White) .scrollable(this.APP_INDEX_SCROLLABLE) } - .height('100%') .linearGradient({ direction: GradientDirection.Bottom, // 渐变方向 - colors: [["rgb(254, 203, 169)", 0], ["RGB(245, 245, 245)", 0.2]] // 数组末尾元素占比小于1时满足重复着色效果 + colors: [ + ["rgb(254, 203, 169)", 0], ["RGB(245, 245, 245)", 0.15] + , ["RGB254, 203, 169)", 0.25]] // 数组末尾元素占比小于1时满足重复着色效果 }) - // .padding({ top: this.topRectHeight}) .borderRadius({ bottomRight: 5, bottomLeft: 5 }) } - @Builder - book() { - Column() { - Flex( - { - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.SpaceBetween - } - ) { - Scroll() { - Flex({ - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.SpaceBetween - }) { - Row({ space: 15 }) { - IndexSearchType({ title: this.title, searchValue: this.searchValue }) - IndexSearchType({ title: '浏览历史', searchValue: this.searchValue }) - .onClick(() => { - this.GROUP = '标签' - this.searchValue = '浏览历史' - }) - if (this.searchValue !== '浏览历史') { - this.GroupBuilder() - this.ExhibitBuilder() - Text('管理') - .onClick(() => { - router.pushUrl({ - url: 'pages/view/bookShelf/Manage/BookManagePage', - params: { - currentIndex: this.currentIndex, - EXHIBIT: this.EXHIBIT, - GROUPName: this.GROUP, - bookTypes: this.bookType - } - }) - }) - .fontColor('rgba(0,0,0,0.5)') - .fontSize(15) - .fontWeight(400) - } - } - } - } - .scrollBar(BarState.Off) - .scrollable(ScrollDirection.Horizontal) - - if (this.searchValue === '浏览历史') { - Row() { - Text('清空') - .onClick(() => { - if (this.IndexShelf != null) { - this.IndexShelf.open() - } - }) - } - } - } - .padding(15) - - Stack() { - if (this.searchValue !== '浏览历史') { - groupTypeComponent({ - bookType: this.bookType, - currentIndex: this.currentIndex, - groupCoverShow: this.groupCoverShow, - GROUP: this.GROUP - }).zIndex(999) - } - Refresh({ refreshing: $$this.isRefreshing, builder: this.refreshComponent }) { - Scroll() { - Stack({ alignContent: Alignment.Center }) { - if (this.bookType === '书单' && this.searchValue !== '浏览历史') { - ShelfBookList({ - EXHIBIT: this.EXHIBIT, - isClear: this.isClear - }) - } else { - if (this.GROUP === '标签') { - if (this.currentIndex === 0) { - novelPage({ - searchValue: this.searchValue, - currentIndex: 0, - isClear: this.isClear, - EXHIBIT: this.EXHIBIT - }) - .zIndex(0) - } else if (this.currentIndex === 1) { - cartoonPage({ - searchValue: this.searchValue, - currentIndex: 1, - isClear: this.isClear, - EXHIBIT: this.EXHIBIT - }).zIndex(1) - } else if (this.currentIndex === 2) { - soundPage({ - searchValue: this.searchValue, - currentIndex: 2, - isClear: this.isClear, - EXHIBIT: this.EXHIBIT - }).zIndex(2) - } - } else { - BookFolder({ - EXHIBIT: this.EXHIBIT - }) - } - } - - } - .padding({ left: 10, right: 10 ,bottom:10}) - } - // .margin({ bottom: 110 + (this.topRectHeight === 0 ? 10 : this.topRectHeight) }) - .align(Alignment.TopStart) - .scrollBar(BarState.Off) - } - .margin({ top: this.searchValue === '浏览历史' ? 0 : 30 }) - .onStateChange((refreshStatus: RefreshStatus) => { - if (refreshStatus === 1 || refreshStatus === 2) { - this.RefreshingTitle = '松开刷新' - } else { - this.RefreshingTitle = '刷新中...' - } - }) - .onRefreshing(() => { - setTimeout(() => { - this.counter++ - this.isRefreshing = false - }, 1000) - - }) - } - .layoutWeight(1) - .alignContent(Alignment.Top) - } - } - - @Builder - ExhibitBuilder() { - Row({ space: 10 }) { - ForEach(this.EXHIBIT_NAMES, (item: string) => { - if (item !== this.EXHIBIT) { - IndexSearchType({ title: item, searchValue: this.searchValue }) - .onClick(() => { - this.EXHIBIT = item - }) - Divider() - .vertical(true) - .height(15) - .color('#989797') - .opacity(0.5) - .strokeWidth(1) - } - }) - } - } - - @Builder - GroupBuilder() { - Row({ space: 10 }) { - ForEach(this.GROUP_NAMES, (item: string) => { - if (item !== this.GROUP) { - IndexSearchType({ title: item, searchValue: this.searchValue }) - .onClick(() => { - this.GROUP = item - }) - Divider() - .vertical(true) - .height(15) - .color('#989797') - .opacity(0.5) - .strokeWidth(1) - } - }) - } - } @Builder TabBuilderImage(index: number, name: string) { @@ -441,14 +190,7 @@ export default struct IndexShelf { Image($r('app.media.SUB_theme')) }.width('100%') } - - @Builder - refreshComponent() { - RefreshComponent({ - RefreshingTitle: this.RefreshingTitle, - }) - } - + @StorageLink('BOOK_IS_BOOK_REFRESHING') isBookRefreshing: number = 0 @Builder // 书籍导入UI盒子 ImportClickBox(index: number, image: string, text: string) { @@ -491,8 +233,10 @@ export default struct IndexShelf { await documentPicker.select(documentSelectOptions).then((documentSelectResult: Array) => { filePath = documentSelectResult[0]; }) - FileHandler.CopyFile(filePath) + FileHandler.CopyFile(filePath,this.currentIndex) this.isShowImport = false + sleep(500) + this.isBookRefreshing++ break case 1: // 云盘导入 @@ -552,6 +296,38 @@ export default struct IndexShelf { } } + // 网址导入dialog + dialogController: CustomDialogController = new CustomDialogController({ + builder: Dialog({ + title: '网址导入', + child: () => { + this.DialogInput("请输入书籍目录或详情页", 10) + } + }), + cornerRadius: 8, + offset: { dx: 0, dy: 0 } + }) + tabsController: TabsController = new TabsController(); + private scrollController: Scroller = new Scroller(); + + @Builder + DialogInput(placeholder: string, maxlength: number) { + Row() { + TextInput({ placeholder: placeholder }) + .maxLength(maxlength) + .showCounter(true) + .cancelButton({ + icon: { + src: $r('app.media.close') + } + }) + } + .margin({ + top: 16, + bottom: 16 + }) + } + @Builder // 书籍导入-网盘导入弹窗 CloudImportDialog() { @@ -656,8 +432,8 @@ export default struct IndexShelf { }) } - @Builder // 导入书单弹窗 + @Builder ImportBookListDialog() { Column() { Flex({ diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookBodyContent.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookBodyContent.ets new file mode 100644 index 00000000..f6b04798 --- /dev/null +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookBodyContent.ets @@ -0,0 +1,196 @@ +/** + * @author 2008 + * @datetime 2024/7/23 12:01 + * @className: BookBodyContent + */ +import groupTypeComponent from '../../../../componets/group/GroupType' +import IndexSearchType from '../../../../componets/head/IndexSearchType' +import { router } from '@kit.ArkUI' +import confirmDialogExample from '../../../../componets/common/confirmDialog' +import BookContentRefresh from './BookContentRefresh' + +@Component +export default struct BookBodyContent { + @Prop index:number + @Prop currentIndex: number = 0 + @State EXHIBIT_NAMES: string[] = ['列表', '宫格'] + @State GROUP_NAMES: string[] = ['标签', '文件夹'] + @Link EXHIBIT: string + @Link GROUP: string + @Link searchValue: string + @Link bookType: string + @State title: string = '最近阅读' + @State groupCoverShow: boolean = false + @Prop isClear: boolean = false + @State bookBodyIndex: number = 0 + tabsBookBodyController: TabsController = new TabsController(); + build() { + Column() { + Flex( + { + alignContent: FlexAlign.Center, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceBetween + } + ) { + Scroll() { + Flex({ + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceBetween + }) { + Row({ space: 15 }) { + IndexSearchType({ title: this.title, searchValue: this.searchValue }) + IndexSearchType({ title: '浏览历史', searchValue: this.searchValue }) + .onClick(() => { + this.GROUP = '标签' + this.searchValue = '浏览历史' + }) + if (this.searchValue !== '浏览历史') { + this.GroupBuilder() + this.ExhibitBuilder() + Text('管理') + .onClick(() => { + router.pushUrl({ + url: 'pages/view/bookShelf/Manage/BookManagePage', + params: { + currentIndex: this.currentIndex, + EXHIBIT: this.EXHIBIT, + GROUPName: this.GROUP, + bookTypes: this.bookType + } + }) + }) + .fontColor('rgba(0,0,0,0.5)') + .fontSize(15) + .fontWeight(400) + } + } + } + } + .scrollBar(BarState.Off) + .scrollable(ScrollDirection.Horizontal) + + if (this.searchValue === '浏览历史') { + Row() { + Text('清空') + .onClick(() => { + if (this.IndexShelf != null) { + this.IndexShelf.open() + } + }) + } + } + } + .padding(15) + + Stack() { + if (this.searchValue !== '浏览历史') { + groupTypeComponent({ + bookType: this.bookType, + currentIndex: this.currentIndex, + groupCoverShow: this.groupCoverShow, + GROUP: this.GROUP + }).zIndex(999) + } + Tabs({ + controller:this.tabsBookBodyController, + index: this.bookBodyIndex + }){ + TabContent(){ + BookContentRefresh({ + EXHIBIT: this.EXHIBIT, + GROUP: this.GROUP, + searchValue: this.searchValue, + isClear: this.isClear, + currentIndex: this.currentIndex, + bookType: this.bookType + }) + } + .align(Alignment.Top) + } + .scrollable(false) + .barWidth(0) + .barHeight(0) + .onChange((index) => { + this.tabsBookBodyController.changeIndex(index) + this.bookBodyIndex = index + }) + } + .layoutWeight(1) + .alignContent(Alignment.Top) + } + } + @State delCache: boolean = false + IndexShelf: CustomDialogController | null = new CustomDialogController({ + builder: confirmDialogExample({ + cancel: () => { + this.onCancel() + }, + confirm: () => { + this.onAccept() + }, + title: '清空', + delCache: this.delCache + }), + cancel: this.exitApp, + autoCancel: true, + alignment: DialogAlignment.Center, + // offset: { dx: 0, dy: '-40%' }, + gridCount: 4, + customStyle: false, + cornerRadius: 25 + }) + + onAccept() { + console.info('确定') + this.isClear = true + } + + onCancel() { + console.info('取消') + } + + exitApp() { + console.info('点外围取消') + } + + + @Builder + GroupBuilder() { + Row({ space: 10 }) { + ForEach(this.GROUP_NAMES, (item: string) => { + if (item !== this.GROUP) { + IndexSearchType({ title: item, searchValue: this.searchValue }) + .onClick(() => { + this.GROUP = item + }) + Divider() + .vertical(true) + .height(15) + .color('#989797') + .opacity(0.5) + .strokeWidth(1) + } + }) + } + } + @Builder + ExhibitBuilder() { + Row({ space: 10 }) { + ForEach(this.EXHIBIT_NAMES, (item: string) => { + if (item !== this.EXHIBIT) { + IndexSearchType({ title: item, searchValue: this.searchValue }) + .onClick(() => { + this.EXHIBIT = item + }) + Divider() + .vertical(true) + .height(15) + .color('#989797') + .opacity(0.5) + .strokeWidth(1) + } + }) + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookContent.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookContent.ets new file mode 100644 index 00000000..2014c9fa --- /dev/null +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookContent.ets @@ -0,0 +1,82 @@ +/** + * @author 2008 + * @datetime 2024/7/23 14:16 + * @className: BookContent + * 书籍详细列 + */ +import { showMessage } from '../../../../componets/common/promptShow' +import booksDao from '../../../../database/dao/BooksDao' +import { Books } from '../../../../database/entities/Books' +import BookInfoGrids from './BookInfoGrids' +import BookInfos from './BookInfos' + +@Component +export default struct BookContent { + @State bookList:Books[] = [] + @StorageLink('bottomRectHeight') bottomRectHeight: number = 0 + aboutToAppear(): void { + this.getBookList() + } + @Prop EXHIBIT:string + @Prop searchValue:string + @Prop @Watch('changeBookType')currentIndex: number + @Prop @Watch('changeBookType')bookType:string + //更新数据累加刷新数据页面 + @StorageLink('BOOK_IS_BOOK_REFRESHING') @Watch("isRefresh")isBookRefreshing: number = 0 + isRefresh(){ + if (this.isBookRefreshing >= 0) { + this.getBookList() + } + } + + changeBookType(){ + showMessage(JSON.stringify(`${this.bookType},${this.currentIndex}`)) + this.getBookList() + this.isBookRefreshing++ + } + getBookList(){ + booksDao.search().then((val)=>{ + this.bookList = val + }) + } + + build() { + if (this.bookList.length === 0){ + Column() { + Image($r('app.media.no_record')).width(200).height(200) + Text('暂无浏览记录') + .fontSize(12) + .fontColor('rgba(96, 96, 96, 0.6)') + .fontWeight(500) + .padding(5) + } + .margin({ top: 120 }) + } else { + Column( + {space:10} + ){ + if (this.EXHIBIT === '宫格' && this.searchValue !== '浏览历史') { + Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap,alignContent:FlexAlign.Center}){ + ForEach(this.bookList, (item: Books,index:number) => { + BookInfoGrids({ + book:item + }).width('33%') + }) + } + } else { + Column( + { space: 10 } + ) { + ForEach(this.bookList, (item: Books,index:number) => { + BookInfos({ + book:item, + searchValue: this.searchValue, + }) + }) + } + .backgroundColor('rgba(255,250,247,0.8)') + } + } + } + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookContentRefresh.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookContentRefresh.ets new file mode 100644 index 00000000..1b34b8e4 --- /dev/null +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookContentRefresh.ets @@ -0,0 +1,78 @@ +/** + * @author 2008 + * @datetime 2024/7/23 12:18 + * @className: BookContentRefresh + */ +import RefreshComponent from '../../../../componets/common/RefreshComponent' +import BookFolder from '../BookFolder' +import ShelfBookList from '../Shelf/ShelfBookList' +import BookContent from './BookContent' + +@Component +export default struct BookContentRefresh { + @State @Watch('changeRefreshing')isRefreshing: boolean = false + @StorageLink('BOOK_IS_BOOK_REFRESHING') isBookRefreshing: number = 0 + @State counter: number = 0 + @State RefreshingTitle: string = '松开刷新' + @Link bookType:string + @Prop currentIndex: number = 0 + @Link EXHIBIT: string + @Link GROUP: string + @Link searchValue: string + @Prop isClear: boolean = false + + changeRefreshing(){ + if (this.isRefreshing) { + this.isBookRefreshing++ + } + } + build() { + Refresh({ refreshing: $$this.isRefreshing, builder: this.refreshComponent }) { + Scroll() { + Column() { + if (this.bookType === '书单' && this.searchValue !== '浏览历史') { + ShelfBookList({ + EXHIBIT: this.EXHIBIT, + isClear: this.isClear + }) + } else { + if (this.GROUP === '标签') { + BookContent({ + currentIndex:this.currentIndex, + bookType:this.bookType, + }) + } else { + BookFolder({ + EXHIBIT: this.EXHIBIT + }) + } + } + } + .padding({ left: 10, right: 10, bottom: 30 }) + } + .scrollBar(BarState.Off) + } + .height('100%') + .margin({ top: this.searchValue === '浏览历史' ? 0 : 30 }) + .onStateChange((refreshStatus: RefreshStatus) => { + if (refreshStatus === 1 || refreshStatus === 2) { + this.RefreshingTitle = '松开刷新' + } else { + this.RefreshingTitle = '刷新中...' + } + }) + .onRefreshing(() => { + setTimeout(() => { + this.counter++ + this.isRefreshing = false + }, 1000) + + }) + } + @Builder + refreshComponent() { + RefreshComponent({ + RefreshingTitle: this.RefreshingTitle, + }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets new file mode 100644 index 00000000..783218f8 --- /dev/null +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets @@ -0,0 +1,135 @@ +import confirmDialogExample from '../../../../componets/common/confirmDialog' +import { Books } from '../../../../database/entities/Books' +import { router } from '@kit.ArkUI' +import BookInfoDialogs from './dialog/BookInfoDialogs' + +@Component +/** + * 书签_宫格 + */ +export default struct BookInfoGrids{ + + @Prop book:Books + + onDelete: () => void = () => { + + } + @State delCache:boolean = false + //弹窗 + bookInfoDel: CustomDialogController | null = new CustomDialogController({ + builder: confirmDialogExample({ + cancel: ()=> { this.onCancel() }, + confirm: ()=> { this.onAccept() }, + delCache:this.delCache, + isShowCache:true + }), + cancel: this.exitApp, + autoCancel: true, + alignment: DialogAlignment.Center, + // offset: { dx: 0, dy: '-40%' }, + gridCount: 4, + customStyle: false, + cornerRadius: 25, + }) + + onCancel() { + console.info('取消') + } + + onAccept() { + this.onDelete() + } + + exitApp() { + console.info('点外围取消') + } + + + build() { + Column() { + Column(){ + Flex({ + alignItems: ItemAlign.End, + justifyContent:FlexAlign.End + }){ + Flex({ + alignItems: ItemAlign.End, + }){ + // if (this.book.isTop){ + // Text('置顶').fontColor(Color.White).fontWeight(300).fontSize(8).padding(5).margin({left:1,bottom:1}).borderRadius({ bottomLeft:10,bottomRight:5,topRight:5,topLeft:5 }) + // .backgroundColor('rgba(0, 0, 0, 0.45)') + // } + } + .align(Alignment.Bottom) + } + .width(100).height(120) + } + .borderRadius(10) + .width(100).height(120) + .backgroundImage(this.book.coverUrl?$r('app.media.cover_list'):$r('app.media.cover_list')) + .backgroundImageSize({width:100,height:120}) + Text(this.book.bookName) + .fontSize(15) + .fontWeight(700) + .textOverflow({ + overflow:TextOverflow.Ellipsis + }) + .ellipsisMode(EllipsisMode.END) + .maxLines(2) + //描述 + Text(this.book.customIntro).fontSize(12).fontColor('rgb(174,174,174)') + .textOverflow({ + overflow:TextOverflow.Ellipsis + }) + .ellipsisMode(EllipsisMode.END) + .fontWeight(500) + .maxLines(1) + Text(this.book.latestChapterTitle).fontSize(12).fontColor('rgb(174,174,174)') + .textOverflow({ + overflow:TextOverflow.Ellipsis + }) + .ellipsisMode(EllipsisMode.END) + .fontWeight(500) + .maxLines(1) + } + .padding({ left:8,right:8,bottom:5,top:5 }) + .onClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: { + bookId: '1', + bookName: '大奉打更人', + bookAuthor: '卖报小郎君', + bookImage: $r('app.media.cover_list'), + bookDescribe: '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + } + }) + }) + .gesture( + LongPressGesture({ repeat: true,duration:500 }) + .onAction((event: GestureEvent) => { + if (event.repeat) { + this.bookInfoDialog?.open() + } + })) + } + bookInfoDialog: CustomDialogController | null = new CustomDialogController({ + builder: BookInfoDialogs({ + bookData:this.book, + onDelete:this.onDelete, + cancel: () => { + this.exitDialog() + } + }), + cancel: this.exitDialog, + autoCancel: true, + width:'100%', + alignment: DialogAlignment.Bottom, + customStyle:true + + }) + //退出弹框 + exitDialog(){ + this.bookInfoDialog?.close() + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets new file mode 100644 index 00000000..08256625 --- /dev/null +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets @@ -0,0 +1,172 @@ +import confirmDialogExample from '../../../../componets/common/confirmDialog' +import { Books } from '../../../../database/entities/Books' +import { router } from '@kit.ArkUI' +import { showMessage } from '../../../../componets/common/promptShow' +import BookInfoDialogs from './dialog/BookInfoDialogs' + +@Component +/** + * 书签 + */ +export default struct BookInfos{ + @Prop searchValue:string + + @Prop currentIndex:number + + @Prop book:Books + + @State delCache:boolean = false + + onDelete: () => void = () => { + + } + build() { + + Flex( + { + alignItems:ItemAlign.Center, + justifyContent:FlexAlign.SpaceBetween + } + ) { + Row({ + space:20 + }){ + Flex({ + alignItems: ItemAlign.End, + }){ + if (this.book.isTop){ + Text('置顶').fontColor(Color.White).fontWeight(300).fontSize(8).padding(3).borderRadius(5) + .backgroundColor('rgba(0, 0, 0, 0.45)') + } + } + .align(Alignment.Bottom).width(60).height(80) + .backgroundImage(this.book.coverUrl?$r('app.media.cover_list'):$r('app.media.cover_list')) + .backgroundImageSize({width:60,height:80}) + Column({ + space:24 + }) + { + Text(this.book.bookName) + .fontWeight(700) + Column(){ + Text(this.book.intro).fontSize(12).fontColor('rgb(174,174,174)') + .textOverflow({ + overflow:TextOverflow.Ellipsis + }) + .ellipsisMode(EllipsisMode.END) + .fontWeight(500) + .maxLines(1) + Text(this.book.latestChapterTitle).fontSize(12).fontColor('rgb(174,174,174)') + .textOverflow({ + overflow:TextOverflow.Ellipsis + }) + .ellipsisMode(EllipsisMode.END) + .fontWeight(500) + .maxLines(1) + } + .width('40%') + .alignItems(HorizontalAlign.Start) + } + .alignItems(HorizontalAlign.Start) + .onClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: this.book + }) + }) + } + + if (this.searchValue === '浏览历史'){ + Column({space:15}){ + Row(){ + Image($r('app.media.delete_svg')).width(17).fillColor('rgba(0, 0, 0, 0.6)') + } + .onClick(()=>{ + if (this.bookInfoDel != null) { + this.bookInfoDel.open() + } + }) + .padding({right:5}) + Row(){ + Row({space:5}){ + Image(this.book.isJoin?$r("app.media.add_check"):$r("app.media.add_shelf")) + .width(this.book.isJoin?15:10) + .height(this.book.isJoin?15:10) + .fillColor('rgba(0, 0, 0, 0.9)') + Text('书架').fontSize(10).fontColor('rgba(0, 0, 0, 0.45)') + }.padding({ left:15,right:15,bottom:5,top:5 }) + } + .backgroundColor(this.book.isJoin?'rgba(174,174,174,0.2)':'') + .borderColor('rgb(174,174,174)') + .borderWidth(this.book.isJoin?0:1) + .borderRadius(50) + .onClick(()=>{ + this.book.isJoin = !this.book.isJoin + // updateDateListById(this.currentIndex, this.book.isJoin, this.book.bookId) + showMessage(this.book.isJoin?'已加入书架':'已移出书架',) + }) + } + .justifyContent(FlexAlign.Start) + .alignItems(HorizontalAlign.End) + } + } + .gesture( + LongPressGesture({ repeat: true,duration:500 }) + .onAction((event: GestureEvent) => { + if (event.repeat) { + this.bookInfoDialog?.open() + } + })) + .padding(10) + .borderRadius(10) + } + + bookInfoDialog: CustomDialogController | null = new CustomDialogController({ + builder: BookInfoDialogs({ + bookData:this.book, + onDelete:this.onDelete, + cancel: () => { + this.exitDialog() + } + }), + cancel: this.exitDialog, + autoCancel: true, + width:'100%', + alignment: DialogAlignment.Bottom, + customStyle:true + + }) + //退出弹框 + exitDialog(){ + this.bookInfoDialog?.close() + } + + //弹窗 + bookInfoDel: CustomDialogController | null = new CustomDialogController({ + builder: confirmDialogExample({ + cancel: ()=> { this.onCancel() }, + confirm: ()=> { this.onAccept() }, + delCache:this.delCache, + isShowCache:true + }), + cancel: this.exitApp, + autoCancel: true, + alignment: DialogAlignment.Center, + // offset: { dx: 0, dy: '-40%' }, + gridCount: 4, + customStyle: false, + cornerRadius: 25, + }) + + onCancel() { + console.info('取消') + } + + onAccept() { + this.onDelete() + } + + exitApp() { + console.info('点外围取消') + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/bookShelf/components/dialog/BookInfoDialogs.ets b/entry/src/main/ets/pages/view/bookShelf/components/dialog/BookInfoDialogs.ets new file mode 100644 index 00000000..dcb00a30 --- /dev/null +++ b/entry/src/main/ets/pages/view/bookShelf/components/dialog/BookInfoDialogs.ets @@ -0,0 +1,142 @@ +import { buttonList } from '../../../../../componets/dataList/buttonList' +import { Books } from '../../../../../database/entities/Books' +import { router } from '@kit.ArkUI' +import InsideCircleIcon from '../../../../../componets/common/InsideCircleIcon' +import { showMessage } from '../../../../../componets/common/promptShow' +import confirmDialogExample from '../../../../../componets/common/confirmDialog' + +@CustomDialog +/** + * 书籍长按 + */ +export default struct BookInfoDialogs{ + controller?: CustomDialogController + //推送提醒 + @Link bookData:Books + @State pushReminder:boolean = false + @State buttonListInfo:buttonList[] = [ + new buttonList(1,'置顶',$r('app.media.top')), + new buttonList(2,'移动至',$r('app.media.folder')), + new buttonList(3,'加入书单',$r('app.media.shelf')), + new buttonList(4,'删除',$r('app.media.ic_public_delete')) + ] + + cancel: () => void = () => { + } + + onDelete: () => void = () => { + + } + + build() { + Column(){ + Flex({ + justifyContent:FlexAlign.SpaceBetween, + alignItems:ItemAlign.Center + }){ + Row({ + space:20 + }){ + Image(this.bookData.toUrl) + .width(45).height(65) + Column({ + space:4 + }){ + Text(this.bookData.bookName).fontSize(16).fontWeight(500).fontColor($r('app.string.color_black_88')) + Text(this.bookData.author).fontSize(12).fontWeight(400).fontColor($r('app.string.color_black_45')) + }.alignItems(HorizontalAlign.Start) + } + Row({ + space:8 + }){ + Text('书籍详情').fontSize(12).fontWeight(400).fontColor($r('app.string.color_black_45')) + Image($r('app.media.icon_right')).width(20).height(20).fillColor($r('app.string.color_black_45')) + } .onClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: { + bookId: '1', + bookName: '大奉打更人', + bookAuthor: '卖报小郎君', + bookImage: $r('app.media.cover_list'), + bookDescribe: '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + } + }) + }) + }.padding(20) + Divider().strokeWidth(0.5).padding({bottom:16}) + Flex({ + direction: FlexDirection.Row, wrap: FlexWrap.Wrap, + justifyContent:FlexAlign.Start + }){ + ForEach(this.buttonListInfo,(item:buttonList)=>{ + InsideCircleIcon({ + item:item + }) + .onClick(()=>{ + this.bookInfoButton(item.id) + }) + }) + } + Divider().strokeWidth(0.5).padding({bottom:16}) + Column(){ + Text('取消').fontColor('rgba(0, 0, 0, 0.88)').fontSize(16).fontWeight(400).lineHeight(24).textAlign(TextAlign.Center) + } + .onClick(()=>{ + this.cancel() + this.controller?.close() + }) + .alignItems(HorizontalAlign.Center) + .padding({bottom:16}) + } + .borderRadius({topLeft:20,topRight:20}) + .backgroundColor(Color.White) + .width('100%') + } + + bookInfoButton(id:number){ + switch (id){ + case 1 : + showMessage(!this.bookData.isTop?'置顶':'取消置顶'); + this.isFolderTop(); break; + case 2 : + showMessage('移动至'); break; + case 3 : + showMessage('加入书单'); break; + case 4 : + showMessage('删除'); this.bookDelDialog?.open(); break; + } + } + + isFolderTop(){ + this.bookData.isTop = !this.bookData.isTop + this.buttonListInfo[0].title = this.bookData.isTop?'取消置顶':'置顶' + //刷新数组buttonListInfo + this.buttonListInfo = this.buttonListInfo.slice(0) + this.bookData.updateTime = Date.now() + } + + @State delCache:boolean = false + //弹窗 + bookDelDialog: CustomDialogController | null = new CustomDialogController({ + builder: confirmDialogExample({ + confirm: ()=> { this.deleteGroup() }, + delCache:this.delCache + }), + cancel: this.exitApp, + autoCancel: true, + alignment: DialogAlignment.Center, + gridCount: 4, + customStyle: false, + cornerRadius: 25, + }) + + deleteGroup() { + this.onDelete() + this.cancel() + } + + exitApp() { + this.bookDelDialog?.close() + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/bookShelf/novelPage.ets b/entry/src/main/ets/pages/view/bookShelf/novelPage.ets index 0496def2..d6efe0b8 100644 --- a/entry/src/main/ets/pages/view/bookShelf/novelPage.ets +++ b/entry/src/main/ets/pages/view/bookShelf/novelPage.ets @@ -1,103 +1,103 @@ -import { BookList } from '../../../componets/dataList/bookList' -import BookInfo from './BookInfo' -import { promptAction } from '@kit.ArkUI' -import BookInfoGrid from './BookInfoGrid' -import CommonConstants from '../../../common/constants/CommonConstants' -import { delBookListAll, delBookListByBookId } from '../../../storage/bookListData' -import { updateShelfBookData } from '../../../preferences/bookDataPreferences' - - -@Component -export default struct novelPage{ - @Prop searchValue:string - @Link @Watch('onIsClearChange') isClear:boolean - @Prop currentIndex:number - @State lastIndex:string = '9999' - @Prop bookType:string - @Prop @Watch('onIsEXHIBITChange') EXHIBIT:string - - @StorageLink(CommonConstants.KEY_NOVEL_BOOK_DATA) - @Watch('updatePreferences')bookList:BookList[] = [] - updatePreferences(){ - updateShelfBookData(this.bookList, 0) - } - - //监听isClear变化 - onIsClearChange() { - if (this.currentIndex === 0 && this.isClear) { - delBookListAll(0) - this.isClear = false - promptAction.showToast({ - message: '清空成功', - duration: 1000, - }) - } - } - - //监听EXHIBIT变化 - onIsEXHIBITChange() { - console.log(this.EXHIBIT) - } - - removeListByIndex(bookId:string){ - if (this.lastIndex === bookId) { - return - } - this.lastIndex = bookId - // this.bookList = this.bookList.filter(book => book.bookId !== bookId); - delBookListByBookId(0, bookId) - promptAction.showToast({ - message: '删除成功', - duration: 1000, - }) - //防止快速点击删除 - setTimeout(()=>{ - this.lastIndex = '9999' - },500) - } - - - build() { - if (this.bookList === null || this.bookList.length === 0) { - Column() { - Image($r('app.media.no_record')).width(200).height(200) - Text('暂无浏览记录').fontSize(12).fontColor('rgba(96, 96, 96, 0.6)').fontWeight(500).padding(5) - }.margin({ top: 120 }) - - } else { - Column( - {space:10} - ){ - if (this.EXHIBIT === '宫格' && this.searchValue !== '浏览历史') { - Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap,alignContent:FlexAlign.Center}){ - ForEach(this.bookList, (item: BookList,index:number) => { - BookInfoGrid({ - bookData:item, - onDelete:(): void=>this.removeListByIndex(item.bookId) - }).width('33%') - }) - } - } else { - Column( - { space: 10 } - ) { - ForEach(this.bookList, (item: BookList,index:number) => { - BookInfo({ - bookData:item, - currentIndex:this.currentIndex, - searchValue: this.searchValue, - onDelete:(): void=>this.removeListByIndex(item.bookId) - }) - }) - } - .backgroundColor('rgba(255,250,247,0.8)') - } - Divider().vertical(false) - Row() { - Text('END').fontColor('rgba(84, 84, 84, 0.30)').fontWeight(500) - } - } - - } - } -} \ No newline at end of file +// import { BookList } from '../../../componets/dataList/bookList' +// import BookInfo from './BookInfo' +// import { promptAction } from '@kit.ArkUI' +// import BookInfoGrid from './BookInfoGrid' +// import CommonConstants from '../../../common/constants/CommonConstants' +// import { delBookListAll, delBookListByBookId } from '../../../storage/bookListData' +// import { updateShelfBookData } from '../../../preferences/bookDataPreferences' +// +// +// @Component +// export default struct novelPage{ +// @Prop searchValue:string +// @Link @Watch('onIsClearChange') isClear:boolean +// @Prop currentIndex:number +// @State lastIndex:string = '9999' +// @Prop bookType:string +// @Prop @Watch('onIsEXHIBITChange') EXHIBIT:string +// +// @StorageLink(CommonConstants.KEY_NOVEL_BOOK_DATA) +// @Watch('updatePreferences')bookList:BookList[] = [] +// updatePreferences(){ +// updateShelfBookData(this.bookList, 0) +// } +// +// //监听isClear变化 +// onIsClearChange() { +// if (this.currentIndex === 0 && this.isClear) { +// delBookListAll(0) +// this.isClear = false +// promptAction.showToast({ +// message: '清空成功', +// duration: 1000, +// }) +// } +// } +// +// //监听EXHIBIT变化 +// onIsEXHIBITChange() { +// console.log(this.EXHIBIT) +// } +// +// removeListByIndex(bookId:string){ +// if (this.lastIndex === bookId) { +// return +// } +// this.lastIndex = bookId +// // this.bookList = this.bookList.filter(book => book.bookId !== bookId); +// delBookListByBookId(0, bookId) +// promptAction.showToast({ +// message: '删除成功', +// duration: 1000, +// }) +// //防止快速点击删除 +// setTimeout(()=>{ +// this.lastIndex = '9999' +// },500) +// } +// +// +// build() { +// if (this.bookList === null || this.bookList.length === 0) { +// Column() { +// Image($r('app.media.no_record')).width(200).height(200) +// Text('暂无浏览记录').fontSize(12).fontColor('rgba(96, 96, 96, 0.6)').fontWeight(500).padding(5) +// }.margin({ top: 120 }) +// +// } else { +// Column( +// {space:10} +// ){ +// if (this.EXHIBIT === '宫格' && this.searchValue !== '浏览历史') { +// Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap,alignContent:FlexAlign.Center}){ +// ForEach(this.bookList, (item: BookList,index:number) => { +// BookInfoGrid({ +// bookData:item, +// onDelete:(): void=>this.removeListByIndex(item.bookId) +// }).width('33%') +// }) +// } +// } else { +// Column( +// { space: 10 } +// ) { +// ForEach(this.bookList, (item: BookList,index:number) => { +// BookInfo({ +// bookData:item, +// currentIndex:this.currentIndex, +// searchValue: this.searchValue, +// onDelete:(): void=>this.removeListByIndex(item.bookId) +// }) +// }) +// } +// .backgroundColor('rgba(255,250,247,0.8)') +// } +// Divider().vertical(false) +// Row() { +// Text('END').fontColor('rgba(84, 84, 84, 0.30)').fontWeight(500) +// } +// } +// +// } +// } +// } \ No newline at end of file diff --git a/entry/src/main/ets/storage/bookListData.ets b/entry/src/main/ets/storage/bookListData.ets index 14bebdd1..880a8ec1 100644 --- a/entry/src/main/ets/storage/bookListData.ets +++ b/entry/src/main/ets/storage/bookListData.ets @@ -9,6 +9,7 @@ import { getBookData } from '../preferences/bookDataPreferences' let KEY = '' export const initBookListData = ()=>{ + AppStorage.setOrCreate(CommonConstants.BOOK_IS_BOOK_REFRESHING, 0) // AppStorage.setOrCreate(CommonConstants.PREFERENCES_BOOK_TYPE_NUMBER,0) AppStorage.setOrCreate(CommonConstants.KEY_NOVEL_BOOK_DATA,getBookData(0)) AppStorage.setOrCreate(CommonConstants.KEY_SOUND_BOOK_DATA,getBookData(1)) From d659af54e1f8144429391e1456cc5c38dd46ad74 Mon Sep 17 00:00:00 2001 From: 2008 <59199830@qq.com> Date: Tue, 23 Jul 2024 23:46:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决冲突 --- .../main/ets/pages/view/BookDetailPage.ets | 16 +++++------ .../ets/pages/view/bookShelf/IndexShelf.ets | 28 +++++++++++-------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/entry/src/main/ets/pages/view/BookDetailPage.ets b/entry/src/main/ets/pages/view/BookDetailPage.ets index dae66fe4..aa5b3e4a 100644 --- a/entry/src/main/ets/pages/view/BookDetailPage.ets +++ b/entry/src/main/ets/pages/view/BookDetailPage.ets @@ -90,11 +90,9 @@ struct BookDetailPage { console.log('router BookDetailPage:' + JSON.stringify(router.getParams())) if (router.getParams() as Books) { this.bookData = router.getParams() as Books - setTimeout(async () => { - let temp = await FileHandler.readFile(this.bookData?.bookUrl||'') //txt小说 - this.txtFile.pushAllData(temp) - this.txtFiles = this.txtFile.getListData() - },0) + let temp = await FileHandler.readFile(this.bookData?.bookUrl||'') //txt小说 + this.txtFile.pushAllData(temp) + this.txtFiles = this.txtFile.getListData() } } @@ -121,7 +119,7 @@ struct BookDetailPage { Tabs({ barPosition: BarPosition.Start }) { TabContent() { Column() { - if (this.txtFiles.length=== 0 || undefined) { + if (this.txtFiles.length === 0 || undefined) { SwipeRefresher({ content: '目录加载中...', isLoading: true @@ -221,7 +219,7 @@ struct BookDetailPage { .width(150) .height(40) .borderRadius(200) - .backgroundColor(this.txtFile.totalCount() ? '#FF6600' : 'gray') + .backgroundColor(this.txtFile.totalCount() > 0 ? '#FF6600' : 'gray') .fontColor('#FFFFFF') .enabled(this.txtFile.totalCount() > 0) .onClick(() => { @@ -331,12 +329,12 @@ struct BookDetailPage { // 小说标题 Row({ space: CommonConstants.SPACE_20 }) { - Image(this.bookData.bookImage ?? $r('app.media.cover_list')) + Image(this.bookData.coverUrl?? $r('app.media.cover_list')) .width(CommonConstants.NOVEL_IMG_WIDTH) .height(CommonConstants.NOVEL_IMG_HEIGHT) .borderRadius(5) Column({ space: 8 }) { - Text(this.bookData.title.replace(new RegExp('\\..*', 'g'), '')) + Text(this.bookData.bookName.replace(new RegExp('\\..*', 'g'), '')) .fontColor(Color.White) .fontSize(20) Blank() diff --git a/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets b/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets index f81f6198..12810f5d 100644 --- a/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets +++ b/entry/src/main/ets/pages/view/bookShelf/IndexShelf.ets @@ -146,19 +146,23 @@ export default struct IndexShelf { Tabs({ barPosition: BarPosition.Start, - controller: this.tabsController + controller: this.tabsController, + index: this.currentIndex }) { - TabContent() { - this.book() - } - - TabContent() { - this.book() - } - - TabContent() { - this.book() - } + ForEach(this.titleArray, () => { + TabContent() { + Column(){ + BookBodyContent({ + currentIndex: this.currentIndex, + EXHIBIT: this.EXHIBIT, + GROUP: this.GROUP, + searchValue: this.searchValue, + isClear: this.isClear, + bookType: this.bookType + }) + } + } + }) } .layoutWeight(1) .barWidth(0)