Skip to content

Commit

Permalink
feat: 发现查看更多进入分类列表页面,书籍卡片跳转到详情页面
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-boide committed Jul 19, 2024
1 parent c1d6a05 commit 38cee0a
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 29 deletions.
25 changes: 25 additions & 0 deletions entry/src/main/ets/database/types/BookSourceType.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions entry/src/main/ets/pages/view/BookDetailPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -395,7 +395,7 @@ struct BookDetailPage {

// 书籍简介
Flex() {
Text('《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' +
Text(this.bookData.describe ?? '《大奉打更人》(第一卷)实体书已在天猫、当当、京东等全平台,以及各个实体书店发售。 这个世界,有儒;有道;有佛;有妖;有术士。 警校毕业的许七安幽幽醒来,发现自己身处牢狱之中,三日后流放边陲..... ' +
'\n他起初的目的只是自保,顺便在这个没有人权的社会里当个富家翁悠闲度日。 ...... 多年后,许七安回首前尘,身后是早已逝去的敌人,以及累累白骨。 ' +
'\n滚滚长江东逝水,浪花淘尽英雄,是非成败转头空。 ' +
'\n青山依旧在,几度夕阳红。')
Expand Down
152 changes: 152 additions & 0 deletions entry/src/main/ets/pages/view/Find/CategoryList/Index.ets
Original file line number Diff line number Diff line change
@@ -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,
})
}
}
27 changes: 12 additions & 15 deletions entry/src/main/ets/pages/view/Find/components/BookFindContent.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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%')
Expand Down
12 changes: 12 additions & 0 deletions entry/src/main/ets/pages/view/Find/components/CardItem.ets
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExploreRule } from '../../../../database/entities/rule';
import { router } from '@kit.ArkUI';

@Component
export struct CardItem {
Expand Down Expand Up @@ -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
}
})
})
}
}
11 changes: 1 addition & 10 deletions entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion entry/src/main/resources/base/profile/main_pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}

0 comments on commit 38cee0a

Please sign in to comment.