• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 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 router from '@ohos.router';
17import taskpool from '@ohos.taskpool';
18import { IconItem } from './IconView';
19import { IconItemSource } from './IconItemSource';
20
21@Concurrent
22function loadPicture(count: number): IconItemSource[] {
23  let iconItemSourceList: IconItemSource[] = [];
24  // 遍历添加count*6个IconItem的数据
25  for (let index = 0; index < count; index++) {
26    const numStart: number = index * 6;
27    // 此处循环使用6张图片资源
28    iconItemSourceList.push(new IconItemSource($r('app.media.nearby'), `item${numStart + 1}`));
29    iconItemSourceList.push(new IconItemSource($r('app.media.scan'), `item${numStart + 2}`));
30    iconItemSourceList.push(new IconItemSource($r('app.media.shop'), `item${numStart + 3}`));
31    iconItemSourceList.push(new IconItemSource($r('app.media.cards'), `item${numStart + 4}`));
32    iconItemSourceList.push(new IconItemSource($r('app.media.album'), `item${numStart + 5}`));
33    iconItemSourceList.push(new IconItemSource($r('app.media.applet'), `item${numStart + 6}`));
34  }
35  return iconItemSourceList;
36}
37
38@Component
39export struct MultiTask {
40  @State iconItemSourceList: IconItemSource[] = [];
41
42  build() {
43    Column() {
44      // 顶部导航栏
45      Row() {
46        Image($r("app.media.back"))
47          .height(24)
48          .width(24)
49          .onClick(() => {
50            router.back();
51          })
52
53        Text($r('app.string.scenario_2'))
54          .fontSize(24)
55          .lineHeight(30)
56          .fontColor(Color.Black)
57          .fontWeight(FontWeight.Bold)
58          .textAlign(TextAlign.Start)
59          .textOverflow({ overflow: TextOverflow.MARQUEE })
60          .margin({
61            left: 16
62          })
63      }
64      .width($r('app.string.percent_100'))
65      .height(50)
66      .justifyContent(FlexAlign.Start)
67      .padding({
68        left: 24
69      })
70
71      Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true })
72        .fontSize(14)
73        .borderRadius(8)
74        .backgroundColor(Color.Blue)
75        .width(250)
76        .height(60)
77        .margin({
78          top: 30
79        })
80        .onClick(() => {
81          let taskGroup: taskpool.TaskGroup = new taskpool.TaskGroup();
82          taskGroup.addTask(new taskpool.Task(loadPicture, 30));
83          taskGroup.addTask(new taskpool.Task(loadPicture, 20));
84          taskGroup.addTask(new taskpool.Task(loadPicture, 10));
85          taskpool.execute(taskGroup).then((ret: Object[]) => {
86            for (let i = 0; i < ret.length; i++) {
87              let iconItems: IconItemSource[] = (ret[i] as IconItemSource[]);
88              for (let j = 0; j < iconItems.length; j++) {
89                this.iconItemSourceList.push(iconItems[j] as IconItemSource);
90              }
91            }
92          })
93        })
94      if (this.iconItemSourceList.length > 0) {
95        List({ space: 20 }) {
96          ForEach(this.iconItemSourceList, (item: IconItemSource) => {
97            ListItem() {
98              IconItem({ image: item.image, text: item.text });
99            }
100          }, (item: IconItemSource, index) => index.toString())
101        }
102        .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线
103        .width($r('app.string.percent_100'))
104        .height($r('app.string.percent_100'))
105        .layoutWeight(1)
106      }
107    }
108    .width($r('app.string.percent_100'))
109    .height($r('app.string.percent_100'))
110    .alignItems(HorizontalAlign.Center)
111  }
112}