From 38cee0a0a1d9d536b155cca4e1796c75e94fc0c2 Mon Sep 17 00:00:00 2001 From: Andy <454846659@qq.com> Date: Sat, 20 Jul 2024 00:29:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=91=E7=8E=B0=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E8=BF=9B=E5=85=A5=E5=88=86=E7=B1=BB=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B5=E9=9D=A2=EF=BC=8C=E4=B9=A6=E7=B1=8D=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E8=B7=B3=E8=BD=AC=E5=88=B0=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/database/types/BookSourceType.ets | 25 +++ .../main/ets/pages/view/BookDetailPage.ets | 6 +- .../pages/view/Find/CategoryList/Index.ets | 152 ++++++++++++++++++ .../view/Find/components/BookFindContent.ets | 27 ++-- .../pages/view/Find/components/CardItem.ets | 12 ++ .../view/Find/components/ContentRefresh.ets | 11 +- .../resources/base/profile/main_pages.json | 3 +- 7 files changed, 207 insertions(+), 29 deletions(-) create mode 100644 entry/src/main/ets/pages/view/Find/CategoryList/Index.ets diff --git a/entry/src/main/ets/database/types/BookSourceType.ets b/entry/src/main/ets/database/types/BookSourceType.ets index 9061cd3b..79fcafcd 100644 --- a/entry/src/main/ets/database/types/BookSourceType.ets +++ b/entry/src/main/ets/database/types/BookSourceType.ets @@ -15,4 +15,29 @@ export interface BookSourceSearchParams { hasLoginUrl?: boolean, // 是否存在发现 hasExploreUrl?: boolean +} + +export interface ExploreQuery { + url: string, + pageSize: number, + bookList?: string + name?: string + author?: string + intro?: string + kind?: string + lastChapter?: string + bookUrl?: string + coverUrl?: string + wordCount?: string +} + +export interface ExploreItemStyle { + layout_flexGrow?: number; + layout_flexBasisPercent?: number; +} + +export interface ExploreItem { + title: string, + url: string, + style?: ExploreItemStyle } \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/BookDetailPage.ets b/entry/src/main/ets/pages/view/BookDetailPage.ets index 56c6729d..3f8c9367 100644 --- a/entry/src/main/ets/pages/view/BookDetailPage.ets +++ b/entry/src/main/ets/pages/view/BookDetailPage.ets @@ -328,7 +328,7 @@ struct BookDetailPage { // 小说标题 Row({ space: CommonConstants.SPACE_20 }) { - Image($r('app.media.cover_list')) + Image(this.bookData.bookImage ?? $r('app.media.cover_list')) .width(CommonConstants.NOVEL_IMG_WIDTH) .height(CommonConstants.NOVEL_IMG_HEIGHT) .borderRadius(5) @@ -338,7 +338,7 @@ struct BookDetailPage { .fontSize(20) Blank() Row() { - Text('卖报小郎君') + Text(this.bookData.author ?? '卖报小郎君') .fontSize(CommonConstants.FONT_NOVEL_DETAIL_AUTHOR_SIZE) .fontColor('#FFF') .opacity(0.45) @@ -395,7 +395,7 @@ struct BookDetailPage { // 书籍简介 Flex() { - Text('《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + + Text(this.bookData.describe ?? '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' + '\n他起初的目的只是自保,顺便在这个没有人权的社会里当个富家翁悠闲度日。 ...... 多年后,许七安回首前尘,身后是早已逝去的敌人,以及累累白骨。 ' + '\n滚滚长江东逝水,浪花淘尽英雄,是非成败转头空。 ' + '\n青山依旧在,几度夕阳红。') diff --git a/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets b/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets new file mode 100644 index 00000000..0efd6985 --- /dev/null +++ b/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets @@ -0,0 +1,152 @@ +import Header from '../../../../componets/common/Header'; +import { router } from '@kit.ArkUI'; +import { ExploreItem, ExploreQuery } from '../../../../database/types/BookSourceType'; +import { ExploreRule } from '../../../../database/entities/rule'; +import RefreshComponent from '../../../../componets/common/RefreshComponent'; +import { isNetworkUrl } from '../../../../common/utils/utils'; +import axios, { AxiosResponse } from '@ohos/axios'; +import noFind from '../../../../componets/common/noFind'; +import { CardItem } from '../components/CardItem'; + +interface RouteParams { + bookSourceUrl: string, + exploreItem: ExploreItem, + exploreRule: ExploreRule +} + +@Entry +@Component +struct CateGoryListPage { + @State bookSourceUrl: string = '' + @State exploreItem: ExploreItem = { + title: '', + url: '' + } + @State exploreRule: ExploreRule = {} + @State pageNum: number = 1 + @State pageSize: number = 10 + @State bookList: ExploreRule[] = [] + @State startLoading: boolean = false + @State loading: boolean = false + @State isRefreshing: boolean = false + @State RefreshingTitle: string = '松开刷新' + + async aboutToAppear() { + this.startLoading = true + const params = router.getParams() as RouteParams; + console.log('TagInfo', JSON.stringify(params)) + this.bookSourceUrl = params.bookSourceUrl + this.exploreItem = params.exploreItem + this.exploreRule = params.exploreRule + await this.getList() + this.startLoading = false + } + + async getList() { + let url = this.exploreItem.url.replace('{{page}}', this.pageNum.toString()) + if (!isNetworkUrl(url)) { + url = this.bookSourceUrl + url + } + const exploreQuery: ExploreQuery = { + url, + bookList: this.exploreRule.bookList, + pageSize: this.pageSize, + name: this.exploreRule.name, + author: this.exploreRule.author, + intro: this.exploreRule.intro, + kind: this.exploreRule.kind, + lastChapter: this.exploreRule.lastChapter, + bookUrl: this.exploreRule.bookUrl, + coverUrl: this.exploreRule.coverUrl, + wordCount: this.exploreRule.wordCount + } + if (this.pageNum * this.pageSize - this.bookList.length >= this.pageSize * 2 && !this.startLoading) { + return + } + this.loading = true + try { + const res: AxiosResponse = await axios.post('http://legado.wisdoms.xin/analysisRules', exploreQuery) + console.info('TagInfo, 解析内容:', JSON.stringify(res.data)) + if (this.pageNum === 1) { + this.bookList = res.data + } else { + this.bookList = this.bookList.concat(res.data) + } + this.loading = false + } catch (err) { + console.log('TagInfo 请求失败:', JSON.stringify(err.message)); + this.loading = false + } + } + + build() { + Column() { + Header({ + title: this.exploreItem.title + }) + + Column() { + Refresh({ refreshing: $$this.isRefreshing, builder: this.refreshComponent }) { + Scroll() { + Column() { + if (this.startLoading) { + Column() { + LoadingProgress() + .color(0xff6600) + .width('50%') + Text('加载中...') + } + .justifyContent(FlexAlign.Center) + } else if (this.bookList.length === 0) { + noFind({ + hintIndex: 0 + }).padding({ + top: 75 + }) + } else { + ForEach(this.bookList, (item: ExploreRule, index) => { + CardItem({ item: item }) + }) + } + } + .padding({ left: 16, right: 16 }) + } + .padding({ bottom: 16 }) + .scrollBar(BarState.Off) + .onReachEnd(() => { + this.pageNum += 1 + this.getList() + }) + } + .onStateChange((refreshStatus: RefreshStatus) => { + if (refreshStatus === 1 || refreshStatus === 2) { + this.RefreshingTitle = '松开刷新' + } else { + this.RefreshingTitle = '刷新中...' + } + }) + .height('100%') + .onRefreshing(() => { + setTimeout(async () => { + this.pageNum = 1 + this.startLoading = true + await this.getList() + this.startLoading = false + this.isRefreshing = false + }, 1000) + }) + } + .layoutWeight(1) + + } + .height('100%') + .width('100%') + } + + @Builder + refreshComponent() { + RefreshComponent({ + RefreshingTitle: this.RefreshingTitle, + }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/Find/components/BookFindContent.ets b/entry/src/main/ets/pages/view/Find/components/BookFindContent.ets index 33e8c858..a85e8202 100644 --- a/entry/src/main/ets/pages/view/Find/components/BookFindContent.ets +++ b/entry/src/main/ets/pages/view/Find/components/BookFindContent.ets @@ -8,23 +8,10 @@ import axios, { AxiosResponse, AxiosError } from '@ohos/axios' import { isNetworkUrl } from '../../../../common/utils/utils' import noFind from '../../../../componets/common/noFind' import { ExploreRule } from '../../../../database/entities/rule' +import { ExploreItem, ExploreQuery } from '../../../../database/types/BookSourceType' import mayAlsoLike from '../mayAlsoLike' import { CardItem } from './CardItem' -import { ExploreItem } from './ContentRefresh' - -interface ExploreQuery { - url: string, - pageSize: number, - bookList?: string - name?: string - author?: string - intro?: string - kind?: string - lastChapter?: string - bookUrl?: string - coverUrl?: string - wordCount?: string -} +import { router } from '@kit.ArkUI' @Component export default struct BookFindContent { @@ -119,6 +106,16 @@ export default struct BookFindContent { .margin({ top: 20 }) .backgroundColor('#0F000000') .borderRadius(4) + .onClick(() => { + router.pushUrl({ + url: 'pages/view/Find/CategoryList/Index', + params: { + bookSourceUrl: this.bookSourceUrl, + exploreItem: this.exploreItem, + exploreRule: this.exploreRule + } + }) + }) } } .height('100%') diff --git a/entry/src/main/ets/pages/view/Find/components/CardItem.ets b/entry/src/main/ets/pages/view/Find/components/CardItem.ets index b233755f..c205b45a 100644 --- a/entry/src/main/ets/pages/view/Find/components/CardItem.ets +++ b/entry/src/main/ets/pages/view/Find/components/CardItem.ets @@ -1,4 +1,5 @@ import { ExploreRule } from '../../../../database/entities/rule'; +import { router } from '@kit.ArkUI'; @Component export struct CardItem { @@ -77,5 +78,16 @@ export struct CardItem { } .width('100%') .padding({ top: 20 }) + .onClick(() => { + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: { + title: this.item.name, + bookImage: this.item.coverUrl, + author: this.item.author, + describe: this.item.intro + } + }) + }) } } \ No newline at end of file diff --git a/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets b/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets index 739b8880..55d7383f 100644 --- a/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets +++ b/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets @@ -5,17 +5,8 @@ import { BookSource } from '../../../../database/entities/BookSource' import BookFindContent from './BookFindContent' import { JSON } from '@kit.ArkTS' import { ExploreRule } from '../../../../database/entities/rule' +import { ExploreItem } from '../../../../database/types/BookSourceType' -interface ExploreItemStyle { - layout_flexGrow: number; - layout_flexBasisPercent: number; -} - -export interface ExploreItem { - title: string, - url: string, - style: ExploreItemStyle -} @Component export default struct ContentRefresh { diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json index 17aaafee..d9b38ea4 100644 --- a/entry/src/main/resources/base/profile/main_pages.json +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -24,6 +24,7 @@ "pages/view/Find/BookSource/Index", "pages/view/Find/BookSource/AddSourcePage", "pages/view/Subscription/components/SubscriptionSearch", - "pages/view/Subscription/rssWebView" + "pages/view/Subscription/rssWebView", + "pages/view/Find/CategoryList/Index" ] } \ No newline at end of file