1/* 2 * Copyright (c) 2024 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 IndependentTask { 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_1')) 54 .fontSize(24) 55 .lineHeight(30) 56 .fontColor(Color.Black) 57 .fontWeight(FontWeight.Bold) 58 .textAlign(TextAlign.Start) 59 .margin({ 60 left: 16 61 }) 62 } 63 .width($r('app.string.percent_100')) 64 .height(50) 65 .justifyContent(FlexAlign.Start) 66 .padding({ 67 left: 24 68 }) 69 70 Button($r('app.string.load_image'), { type: ButtonType.Normal, stateEffect: true }) 71 .fontSize(14) 72 .borderRadius(8) 73 .backgroundColor(Color.Blue) 74 .width(250) 75 .height(60) 76 .margin({ 77 top: 30 78 }) 79 .onClick(() => { 80 let lodePictureTask: taskpool.Task = new taskpool.Task(loadPicture, 30); 81 taskpool.execute(lodePictureTask).then((res: Object) => { 82 this.iconItemSourceList = res as IconItemSource[]; 83 }) 84 }) 85 if (this.iconItemSourceList.length > 0) { 86 List({ space: 20 }) { 87 ForEach(this.iconItemSourceList, (item: IconItemSource) => { 88 ListItem() { 89 IconItem({ image: item.image, text: item.text }); 90 } 91 }, (item: IconItemSource, index) => index.toString()) 92 } 93 .divider({ strokeWidth: 2, startMargin: 20, endMargin: 20 }) // 每行之间的分界线 94 .width($r('app.string.percent_100')) 95 .height($r('app.string.percent_100')) 96 .layoutWeight(1) 97 } 98 } 99 .width($r('app.string.percent_100')) 100 .height($r('app.string.percent_100')) 101 .alignItems(HorizontalAlign.Center) 102 } 103}