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