• 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 { cardsMockData } from '../mock/Data'
17
18export class CardDataFormat {
19  constructor(title: string, detail: string) {
20    this.title = title
21    this.detail = detail
22  }
23
24  getValue(name: string) {
25    if (name === 'title') {
26      return this.title
27    } else if (name === 'detail') {
28      return this.detail
29    }
30  }
31
32  private title: string
33  private detail: string
34}
35
36export function getCardsData(count: number): Array<CardDataFormat> {
37  let data: Array<CardDataFormat> = []
38  if (count === -1) {
39    cardsMockData.forEach((item) => {
40      data.push(new CardDataFormat(item.title, item.detail))
41    })
42    return data
43  }
44  try {
45    cardsMockData.forEach((item, idx) => {
46      if (idx === count) {
47        throw new Error('break')
48      }
49      data.push(new CardDataFormat(item.title, item.detail))
50    })
51  } catch (e) {
52    return data
53  }
54}
55
56@Component
57export struct CardGenerator {
58  private data: CardDataFormat
59
60  build() {
61    Column() {
62      Text(this.data.getValue('title'))
63        .fontWeight(FontWeight.Bold)
64        .fontSize(16)
65        .textAlign(TextAlign.Start)
66        .width('100%')
67      Scroll() {
68        Text(this.data.getValue('detail')).textAlign(TextAlign.Start).width('100%')
69      }.height('70%').scrollBar(BarState.Off).align(Alignment.TopStart)
70    }.borderWidth(1).height(100)
71  }
72}