|
@@ -1,14 +1,22 @@
|
|
|
-import { YTAvoid, YTHeader } from 'basic'
|
|
|
|
|
|
|
+import { YTAvoid, YTHeader, YTRequest } from 'basic'
|
|
|
import { DeerSearch } from '../../components/DeerSearch'
|
|
import { DeerSearch } from '../../components/DeerSearch'
|
|
|
import { CustomTextStyle } from '../../style/CustomTextStyle'
|
|
import { CustomTextStyle } from '../../style/CustomTextStyle'
|
|
|
import { LengthMetrics, PersistenceV2 } from '@kit.ArkUI'
|
|
import { LengthMetrics, PersistenceV2 } from '@kit.ArkUI'
|
|
|
import { HistoryStorage } from '../../model/Storage'
|
|
import { HistoryStorage } from '../../model/Storage'
|
|
|
|
|
+import { HotSearchItem } from '../../model/BookModelIndex'
|
|
|
|
|
+import { bookListApi } from '../../apis/BookListApi'
|
|
|
|
|
|
|
|
// 书籍搜索页面
|
|
// 书籍搜索页面
|
|
|
@ComponentV2
|
|
@ComponentV2
|
|
|
struct BookSearchPage {
|
|
struct BookSearchPage {
|
|
|
@Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
|
|
@Local safeBottom: number = AppStorage.get(YTAvoid.SAFE_BOTTOM_KEY) as number
|
|
|
|
|
|
|
|
|
|
+ // 热门搜索
|
|
|
|
|
+ @Local hotSearchKeys: HotSearchItem[] = []
|
|
|
|
|
+ // 热门主题
|
|
|
|
|
+ @Local hotSearchClassifyKeys: HotSearchItem[] = []
|
|
|
|
|
+
|
|
|
|
|
+ // 搜索历史记录
|
|
|
searHistory: HistoryStorage = PersistenceV2.connect(HistoryStorage, () => new HistoryStorage())!
|
|
searHistory: HistoryStorage = PersistenceV2.connect(HistoryStorage, () => new HistoryStorage())!
|
|
|
|
|
|
|
|
// 清空历史记录
|
|
// 清空历史记录
|
|
@@ -18,9 +26,19 @@ struct BookSearchPage {
|
|
|
|
|
|
|
|
// 开始搜索
|
|
// 开始搜索
|
|
|
onSearch(text: string) {
|
|
onSearch(text: string) {
|
|
|
- let key = text
|
|
|
|
|
|
|
+ if(!text) return
|
|
|
|
|
+
|
|
|
|
|
+ this.searHistory.increaseKey(text.trim())
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 获取最热词条
|
|
|
|
|
+ async getHotSearchKeys() {
|
|
|
|
|
+ this.hotSearchKeys = await bookListApi.getHotSearchRecords()
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- console.log('开始搜索searchKey: ' + key)
|
|
|
|
|
|
|
+ aboutToAppear(): void {
|
|
|
|
|
+ this.getHotSearchKeys()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
build() {
|
|
build() {
|
|
@@ -32,7 +50,7 @@ struct BookSearchPage {
|
|
|
List(){
|
|
List(){
|
|
|
ListItem(){
|
|
ListItem(){
|
|
|
DeerSearch({
|
|
DeerSearch({
|
|
|
- onSearch: this.onSearch,
|
|
|
|
|
|
|
+ onSearch: (text: string) => { this.onSearch(text) },
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
.margin({top: 14})
|
|
.margin({top: 14})
|
|
@@ -71,7 +89,7 @@ struct BookSearchPage {
|
|
|
ListItem(){
|
|
ListItem(){
|
|
|
Scroll(){
|
|
Scroll(){
|
|
|
Row({space: 15}){
|
|
Row({space: 15}){
|
|
|
- ForEach(['热门搜索', '主体分类'], (item: string, index) => {
|
|
|
|
|
|
|
+ ForEach(['热门搜索', '主题分类'], (item: string, index) => {
|
|
|
Column(){
|
|
Column(){
|
|
|
Row({space: 8}){
|
|
Row({space: 8}){
|
|
|
Image(index == 0 ?
|
|
Image(index == 0 ?
|
|
@@ -90,18 +108,18 @@ struct BookSearchPage {
|
|
|
.width('90%')
|
|
.width('90%')
|
|
|
.margin({left: 15, top: 13, bottom: 13})
|
|
.margin({left: 15, top: 13, bottom: 13})
|
|
|
|
|
|
|
|
- ForEach(new Array(20).fill(''), (item: string, index) => {
|
|
|
|
|
|
|
+ ForEach(this.hotSearchKeys, (item: HotSearchItem, index) => {
|
|
|
Row({space: 5}){
|
|
Row({space: 5}){
|
|
|
Text(`${index<9?' ':''}${index+1}`)
|
|
Text(`${index<9?' ':''}${index+1}`)
|
|
|
.attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: index < 3 ? '#FFFC3636' : '#FF000000'}))
|
|
.attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: index < 3 ? '#FFFC3636' : '#FF000000'}))
|
|
|
|
|
|
|
|
- Text('西游记')
|
|
|
|
|
|
|
+ Text(item.keyWord)
|
|
|
.attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: index < 3 ? '#FF000000' : '#80000000'}))
|
|
.attributeModifier(new CustomTextStyle({ size: 14, weight: 400, color: index < 3 ? '#FF000000' : '#80000000'}))
|
|
|
}
|
|
}
|
|
|
.width('100%')
|
|
.width('100%')
|
|
|
.margin({top: 12})
|
|
.margin({top: 12})
|
|
|
.justifyContent(FlexAlign.Start)
|
|
.justifyContent(FlexAlign.Start)
|
|
|
- .onClick(() => { this.onSearch('西游记') })
|
|
|
|
|
|
|
+ .onClick(() => { this.onSearch(item.keyWord ?? '') })
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
.width(230)
|
|
.width(230)
|