1/* 2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import router from '@ohos.router'; 17import Logger from '../utils/Logger'; 18import { getMockSearchResult, MockInput } from '../mock/MockData'; 19import { SearchResult } from '../appsampled/data/SearchResult'; 20import SearchSynthesizeComponent from './SearchSynthesizeComponent'; 21import SearchVideoComponent from './SearchVideoComponent'; 22 23const TAG: string = '[SearchResultComponent]'; 24 25@Component 26export default struct SearchResultComponent { 27 private scrollerHor_1: Scroller = new Scroller(); 28 private titleList: Array<Resource> = [$r('app.string.Synthesize'), $r('app.string.Video'), $r('app.string.Music'), 29 $r('app.string.User'), $r('app.string.Commodity'), $r('app.string.Live_streaming')]; 30 private searchResultList: Array<SearchResult> = getMockSearchResult(); // mock 31 private inputSearch: string = ''; // 搜索输入框输入的字符串 32 @State currSearchResult: SearchResult = this.searchResultList[0]; // mock 33 @State selectTopIndex: number = 0; // 综合、视频等title选择索引 34 35 aboutToAppear() { 36 // 默认值 37 if (this.inputSearch === '') { 38 this.inputSearch = MockInput.TEST_INPUT_CONTENT_1; 39 } 40 // 依据不同的搜索展示不同的模拟数据 41 Logger.info(TAG, `this.inputSearch: ${JSON.stringify(this.inputSearch)}`); 42 if (this.inputSearch.indexOf(MockInput.TEST_INPUT_CONTENT_1) !== -1) { 43 // 输入"黑夜问白天"的模拟数据 44 this.currSearchResult = this.searchResultList[0]; 45 } else if (this.inputSearch.indexOf(MockInput.TEST_INPUT_CONTENT_2) !== -1) { 46 // 输入"哦想"的模拟数据 47 this.currSearchResult = this.searchResultList[1]; 48 } else if (this.inputSearch.indexOf(MockInput.TEST_INPUT_CONTENT_3) !== -1) { 49 // 输入"我不愿让你一个人"的模拟数据 50 this.currSearchResult = this.searchResultList[2]; 51 } 52 Logger.info(TAG, `this.currSearchResult: ${JSON.stringify(this.currSearchResult)}`); 53 } 54 55 build() { 56 Column() { 57 Row() { 58 // 横向Label列表 59 Scroll(this.scrollerHor_1) { 60 Row() { 61 ForEach(this.titleList, (title: Resource, index: number) => { 62 Column() { 63 Text(title) 64 .width(60) 65 .height(20) 66 .fontColor(this.selectTopIndex === index ? $r('app.color.COLOR_FFFFFF') : $r('app.color.COLOR_CCFFFFFF')) 67 .fontSize(18) 68 .fontFamily($r('app.string.Font_family_medium')) 69 .textAlign(TextAlign.Center) 70 Divider() 71 .vertical(false) 72 .height(20) 73 .width(60) 74 .strokeWidth(3) 75 .color($r('app.color.COLOR_D7B837')) 76 .visibility(this.selectTopIndex === index ? Visibility.Visible : Visibility.Hidden) 77 } 78 .id(`titleID_${index+1}`) 79 .width(78) 80 .height('100%') 81 .onClick(e => { 82 this.selectTopIndex = index; 83 }) 84 }) 85 } 86 .height('100%') 87 .justifyContent(FlexAlign.Start) 88 } 89 .scrollable(ScrollDirection.Horizontal) 90 .scrollBar(BarState.Off) 91 .width('90%') 92 .height('100%') 93 94 Row() { 95 Image($r('app.media.app_icon')) 96 .width(18) 97 .height(18) 98 .objectFit(ImageFit.Contain) 99 .margin({ left: 4, top: 2 }) 100 } 101 .width('10%') 102 .height('100%') 103 .justifyContent(FlexAlign.Center) 104 .alignItems(VerticalAlign.Top) 105 } 106 .width('100%') 107 .height('6%') 108 .padding({ left: 8, right: 6 }) 109 .justifyContent(FlexAlign.Start) 110 .backgroundColor($r('app.color.COLOR_151724')) 111 112 Divider() 113 .vertical(false) 114 .height(1) 115 .width('100%') 116 .color($r('app.color.COLOR_5A5B63')) 117 118 119 Column() { 120 if (this.selectTopIndex === 0){ 121 SearchSynthesizeComponent({currSearchResult: this.currSearchResult}) 122 }else if (this.selectTopIndex === 1){ 123 SearchVideoComponent({currSearchResult: this.currSearchResult}) 124 } 125 126 } 127 .width('100%') 128 .height('94%') 129 } 130 .width('100%') 131 .height('100%') 132 .backgroundColor($r('app.color.COLOR_151724')) 133 } 134}