• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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 { getStringArray } from '@ohos/common/src/main/ets/util/ResourceUtil';
17
18@Component
19export struct GridOperation {
20  private operationRes: Resource | undefined = undefined;
21  @State operationSource: string[] = [];
22  private doOperation: (index: number) => void = () => {};
23
24  build() {
25    Column() {
26      GridRow({ columns: 12, gutter: { x: 2, y: 5 },
27        direction: GridRowDirection.Row
28      }) {
29        ForEach(this.operationSource, (item: string, index: number) => {
30          GridCol({ span: { xs: 6, sm: 6, md: 4, lg: 4 } }) {
31            Row() {
32              Button() {
33                Text(item)
34                  .fontSize(16)
35                  .fontColor(Color.White)
36              }
37              .width(160)
38              .height(50)
39              .type(ButtonType.Capsule)
40              .margin({ right: 10, top: 10 })
41              .onClick(() => {
42                this.doOperation(index);
43              })
44            }
45            .justifyContent(FlexAlign.Center)
46          }
47        }, (index: string) => index)
48      }
49    }
50    .width('100%')
51    .padding({ bottom: 15 })
52  }
53
54  async aboutToAppear() {
55    if (this.operationRes) {
56      let menuList = await getStringArray(this.operationRes);
57      this.operationSource = menuList;
58    }
59  }
60}