FirstTabTopSearchComponent.ets
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* 首页顶部搜索导航栏
* 竖向滚动实现方案
* 方案一 使用动画 + 定时器
* 方案二 使用容器组件Swiper(当前)
*/
import { SPHelper } from 'wdKit/Index'
import { WDRouterPage, WDRouterRule } from 'wdRouter'
import DailyPaperTopicModel from '../../model/DailyPaperTopicModel'
import SearcherAboutDataModel from '../../model/SearcherAboutDataModel'
const TAG = "FirstTabTopSearchComponent"
@Component
export struct FirstTabTopSearchComponent {
@State searchTextData: string[] = []
private swiperController: SwiperController = new SwiperController()
async aboutToAppear() {
this.getSearchHint()
let dailyPaperTopicBean = await DailyPaperTopicModel.getDailyPaperTopic()
if (dailyPaperTopicBean) {
SPHelper.default.saveSync('dailyPaperTopicPageId', dailyPaperTopicBean.id);
}
}
getSearchHint() {
SearcherAboutDataModel.getSearchHintData(getContext(this)).then((value) => {
if (value != null) {
this.searchTextData = value
}
this.setDefaultHitData()
}).catch((err: Error) => {
console.log(TAG, JSON.stringify(err))
this.setDefaultHitData()
})
}
setDefaultHitData(){
if(this.searchTextData.length === 0){
this.searchTextData.push("搜索")
}
}
build() {
Row() {
Image($r('app.media.icon_search'))
.width(18)
.height(18)
.margin({right:'10lpx'})
if (this.searchTextData != null && this.searchTextData.length > 0) {
Swiper(this.swiperController) {
ForEach(this.searchTextData, (item: string, index: number) => {
Text(item)
.fontWeight(400)
.fontColor($r('app.color.color_B0B0B0'))
.fontSize($r('app.float.font_size_13'))
.textAlign(TextAlign.Start)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Clip })
})
}
.loop(true)
.autoPlay(true)
.interval(3000)
.indicator(false)
.vertical(true)
.height(30)
.enabled(false)
.focusable(false)
}
}
.height(30)
.width(124)
.padding({ left: 15 })
.backgroundImage($r('app.media.background_search'))
.backgroundImageSize(ImageSize.Cover)
.onClick(() => {
WDRouterRule.jumpWithPage(WDRouterPage.searchPage)
})
}
}