• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device 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 DataModel from '../model/DataModel'
17import TitleBar from '../common/TitleBar'
18import { MainPage } from '@ohos/search'
19
20@Entry
21@Component
22struct Index {
23  @State changeValue: string = ''
24  @State books: any[] = DataModel.getAllData()
25  private controller: SearchController = new SearchController()
26
27  @Builder
28  BookItem(image: Resource, title: string, introduction: string) {
29    Row() {
30      Image(image)
31        .width(80)
32        .height(120)
33      Column() {
34        Text(title)
35          .fontColor(Color.Black)
36          .fontSize(25)
37        Text(introduction)
38          .fontColor(Color.Gray)
39          .fontSize(25)
40      }
41      .layoutWeight(1)
42      .margin({ left: 10 })
43      .alignItems(HorizontalAlign.Start)
44    }
45    .padding(10)
46    .margin({ left: 10, right: 10 })
47    .backgroundColor(Color.White)
48    .borderRadius(10)
49  }
50
51  build() {
52    Column() {
53      TitleBar()
54      MainPage({ textInfo: $changeValue, customizeFunction: () => {
55        this.books = DataModel.query(this.changeValue)
56      } })
57      List({ space: 10 }) {
58        ForEach(this.books, item => {
59          ListItem() {
60            this.BookItem(item.image, item.title, item.introduction)
61          }
62        }, item => item.title)
63      }
64      .width('100%')
65      .height('100%')
66      .layoutWeight(1)
67      .margin({ bottom: 20 })
68    }
69    .width('100%')
70    .height('100%')
71    .backgroundColor('#F5F5F5')
72  }
73}