diff --git a/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets b/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets index 478318cd..27630020 100644 --- a/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets +++ b/entry/src/main/ets/pages/view/Find/CategoryList/Index.ets @@ -8,23 +8,35 @@ import axios, { AxiosResponse } from '@ohos/axios'; import noFind from '../../../../componets/common/noFind'; import { CardItem } from '../components/CardItem'; import CommonConstants from '../../../../common/constants/CommonConstants'; +import { BookSource } from '../../../../database/entities/BookSource'; interface RouteParams { - bookSourceUrl: string, + bookSource: BookSource, exploreItem: ExploreItem, - exploreRule: ExploreRule, currentIndex: number } @Entry @Component struct CateGoryListPage { - @State bookSourceUrl: string = '' @State exploreItem: ExploreItem = { title: '', url: '' } - @State exploreRule: ExploreRule = {} + @State bookSource?: BookSource = { + bookSourceUrl: '', + bookSourceName: '', + bookSourceType: 0, + customOrder: 0, + enabled: false, + enabledExplore: false, + lastUpdateTime: 0, + respondTime: 0, + weight: 0, + isTop: false, + showRecentIcon: false, + showExplore: true + } @State pageNum: number = 1 @State pageSize: number = 10 @State bookList: ExploreRule[] = [] @@ -38,30 +50,33 @@ struct CateGoryListPage { const params = router.getParams() as RouteParams; this.currentIndex = params.currentIndex console.log('TagInfo', JSON.stringify(params)) - this.bookSourceUrl = params.bookSourceUrl + this.bookSource = params.bookSource this.exploreItem = params.exploreItem - this.exploreRule = params.exploreRule await this.getList() this.startLoading = false } async getList() { + if (!this.bookSource) return + const bookSourceUrl = this.bookSource.bookSourceUrl + const exploreRule = this.bookSource.ruleExplore + const searchRule = this.bookSource.ruleSearch let url = this.exploreItem.url.replace('{{page}}', this.pageNum.toString()) if (!isNetworkUrl(url)) { - url = this.bookSourceUrl + url + url = 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 + bookList: exploreRule?.bookList || searchRule?.bookList, + name: exploreRule?.name || searchRule?.name, + author: exploreRule?.author || searchRule?.author, + intro: exploreRule?.intro || searchRule?.intro, + kind: exploreRule?.kind || searchRule?.kind, + lastChapter: exploreRule?.lastChapter || searchRule?.lastChapter, + bookUrl: exploreRule?.bookUrl || searchRule?.bookUrl, + coverUrl: exploreRule?.coverUrl || searchRule?.coverUrl, + wordCount: exploreRule?.wordCount || searchRule?.wordCount } if (this.pageNum * this.pageSize - this.bookList.length >= this.pageSize * 2 && !this.startLoading) { return @@ -72,7 +87,7 @@ struct CateGoryListPage { console.info('TagInfo, 解析内容:', JSON.stringify(res.data)) const bookList = (res.data as ExploreRule[]).map(item => { if (item.coverUrl && !isNetworkUrl(item.coverUrl)) { - item.coverUrl = this.bookSourceUrl + item.coverUrl + item.coverUrl = bookSourceUrl + item.coverUrl } return item }) diff --git a/entry/src/main/ets/pages/view/Find/components/AllCategory.ets b/entry/src/main/ets/pages/view/Find/components/AllCategory.ets index 5e5668bb..02cd0ad4 100644 --- a/entry/src/main/ets/pages/view/Find/components/AllCategory.ets +++ b/entry/src/main/ets/pages/view/Find/components/AllCategory.ets @@ -1,6 +1,6 @@ import { ExploreItem } from '../../../../database/types/BookSourceType' import { router } from '@kit.ArkUI' -import { ExploreRule } from '../../../../database/entities/rule' +import { BookSource } from '../../../../database/entities/BookSource' export interface GroupExploreList { title: string, @@ -14,8 +14,7 @@ export default struct AllCategory { @StorageLink('bottomRectHeight') bottomRectHeight: number = 0 @Prop list: GroupExploreList[] = [] @Link showSheet: boolean - @Prop bookSourceUrl: string = '' - @Prop exploreRule: ExploreRule = {} + @Prop bookSource?: BookSource build() { Column() { @@ -106,15 +105,14 @@ export default struct AllCategory { .backgroundColor('#0F000000') .borderRadius(4) .onClick(() => { - if (!item.url) { + if (!item.url || !this.bookSource) { return } router.pushUrl({ url: 'pages/view/Find/CategoryList/Index', params: { - bookSourceUrl: this.bookSourceUrl, - exploreItem: item, - exploreRule: this.exploreRule + bookSource: this.bookSource, + exploreItem: item } }) }) 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 7ce1ee11..26a4474e 100644 --- a/entry/src/main/ets/pages/view/Find/components/BookFindContent.ets +++ b/entry/src/main/ets/pages/view/Find/components/BookFindContent.ets @@ -13,48 +13,54 @@ import mayAlsoLike from '../mayAlsoLike' import { CardItem } from './CardItem' import { router } from '@kit.ArkUI' import CommonConstants from '../../../../common/constants/CommonConstants'; +import { BookSource } from '../../../../database/entities/BookSource' @Component export default struct BookFindContent { @Prop currentIndex: number - @Prop bookSourceUrl: string @Prop exploreItem: ExploreItem @Prop @Watch('getList') counter: number = 0 @State loading: boolean = true @State errorExplore: boolean = false @State bookList: ExploreRule[] = [] - @Prop exploreRule: ExploreRule = {} + @Prop bookSource?: BookSource handleClick: () => void = () => { } aboutToAppear() { this.getList() + if (!this.bookSource) return } getList() { + if (!this.bookSource) return + const bookSourceUrl = this.bookSource.bookSourceUrl + const exploreRule = this.bookSource.ruleExplore + const searchRule = this.bookSource.ruleSearch this.loading = true let url = this.exploreItem.url.replace('{{page}}', "1") if (!isNetworkUrl(url)) { - url = this.bookSourceUrl + url + url = bookSourceUrl + url } const exploreQuery: ExploreQuery = { url, - bookList: this.exploreRule.bookList, pageSize: 3, - 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 + bookList: exploreRule?.bookList || searchRule?.bookList, + name: exploreRule?.name || searchRule?.name, + author: exploreRule?.author || searchRule?.author, + intro: exploreRule?.intro || searchRule?.intro, + kind: exploreRule?.kind || searchRule?.kind, + lastChapter: exploreRule?.lastChapter || searchRule?.lastChapter, + bookUrl: exploreRule?.bookUrl || searchRule?.bookUrl, + coverUrl: exploreRule?.coverUrl || searchRule?.coverUrl, + wordCount: exploreRule?.wordCount || searchRule?.wordCount } + console.info('解析参数:', JSON.stringify(exploreQuery)) axios.post(CommonConstants.BASE_URL + '/common/analysisRules', exploreQuery).then((res: AxiosResponse) => { console.info('TagInfo, 解析内容:', JSON.stringify(res.data)) this.bookList = (res.data as ExploreRule[]).map(item => { if (item.coverUrl && !isNetworkUrl(item.coverUrl)) { - item.coverUrl = this.bookSourceUrl + item.coverUrl + item.coverUrl = bookSourceUrl + item.coverUrl } return item }) @@ -115,9 +121,8 @@ export default struct BookFindContent { router.pushUrl({ url: 'pages/view/Find/CategoryList/Index', params: { - bookSourceUrl: this.bookSourceUrl, + bookSource: this.bookSource, exploreItem: this.exploreItem, - exploreRule: this.exploreRule, currentIndex: this.currentIndex } }) 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 db838b2c..ec1ff551 100644 --- a/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets +++ b/entry/src/main/ets/pages/view/Find/components/ContentRefresh.ets @@ -4,7 +4,6 @@ import RefreshComponent from '../../../../componets/common/RefreshComponent' 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' import AllCategory, { GroupExploreList } from './AllCategory' @@ -36,7 +35,6 @@ export default struct ContentRefresh { @State groupExploreList: GroupExploreList[] = [] @State exploreList: ExploreItem[] = [] @State showExploreList: ExploreItem[] = [] - @State exploreRule?: ExploreRule = {} @State showSheet: boolean = false aboutToAppear() { @@ -49,7 +47,6 @@ export default struct ContentRefresh { getList () { try { - this.exploreRule = this.bookSource.ruleExplore console.info('TagInfo: 书源地址:', this.bookSource.bookSourceUrl) console.info('TagInfo: 发现地址:', JSON.stringify(JSON.parse(this.bookSource.exploreUrl ?? '[]'))) const exploreList = JSON.parse(this.bookSource.exploreUrl ?? '[]') as ExploreItem[] @@ -122,9 +119,8 @@ export default struct ContentRefresh { ForEach(this.showExploreList, (item: ExploreItem) => { BookFindContent({ currentIndex: this.currentIndex, - bookSourceUrl: this.bookSource.bookSourceUrl, exploreItem: item, - exploreRule: this.exploreRule, + bookSource: this.bookSource, counter: this.counter, handleClick: () => { this.showSheet = true @@ -180,8 +176,7 @@ export default struct ContentRefresh { Column() { AllCategory({ showSheet: this.showSheet, - bookSourceUrl: this.bookSource.bookSourceUrl, - exploreRule: this.exploreRule, + bookSource: this.bookSource, list: this.groupExploreList }) }