• 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
16const BOOKS = [
17  { title: 'My diary', introduction: 'I am happy today', image: $r('app.media.book_img1') },
18  { title: 'Cat', introduction: 'I have a cat', image: $r('app.media.book_img2') },
19  { title: 'Happy', introduction: 'Have fun every day', image: $r('app.media.book_img3') },
20  { title: 'Sentiment', introduction: 'I\'m not angry', image: $r('app.media.book_img4') },
21  { title: 'Tree', introduction: 'Small tree observation diary', image: $r('app.media.book_img1') },
22  { title: 'I am very kind', introduction: 'I am very kind', image: $r('app.media.book_img2') },
23  { title: 'Seahorse Daddy', introduction: 'Big-bellied hippocampus dad', image: $r('app.media.book_img3') },
24  { title: 'Butterfly', introduction: 'Butterfly', image: $r('app.media.book_img4') },
25  { title: 'Good friend', introduction: 'Good friends are with you all your life', image: $r('app.media.book_img1') }
26]
27
28class DataModel {
29  private books: Array<{
30    title: string,
31    introduction: string,
32    image: Resource
33  }> = BOOKS
34
35  constructor() {
36  }
37
38  query(key: string) {
39    let result: Array<{
40      title: string,
41      introduction: string,
42      image: Resource
43    }> = []
44    this.books.forEach((item) => {
45      if (item.title.match(key) || item.introduction.match(key)) {
46        result.push(item)
47      }
48    })
49    return result
50  }
51
52  getAllData() {
53    return this.books
54  }
55}
56
57export default new DataModel()