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 */ 15import LazyDataSource, { BaseData } from '../utils/LazyDataSource'; 16 17@Component 18export default struct OperationListView { 19 private title: string | Resource = ''; 20 private operations: Array<BaseData> = []; 21 private handleItemClick: (index: number) => void = () => {}; 22 private operationData: LazyDataSource = new LazyDataSource(); 23 24 aboutToAppear() { 25 this.operationData.dataArray = this.operations; 26 this.operationData.notifyDataReload(); 27 } 28 29 @Builder 30 OperationItem($$: Data) { 31 Column() { 32 if ($$.index !== 0) { 33 Divider() 34 .color($r('app.color.divider')) 35 .width('100%') 36 .strokeWidth(1) 37 .margin({ top: 10, bottom: 10 }) 38 } 39 Text($$.operationInfo.key) 40 .fontSize(22) 41 .width('100%') 42 .margin({ top: 10, bottom: 10 }) 43 if ($$.operationInfo.value !== '') { 44 Text($$.operationInfo.value) 45 .fontColor($r('app.color.gray')) 46 .fontSize(20) 47 .width('100%') 48 .margin({ top: 10, bottom: 10 }) 49 } 50 } 51 .width('100%') 52 .onClick(() => { 53 if (this.handleItemClick) { 54 this.handleItemClick($$.index) 55 } 56 }) 57 } 58 59 build() { 60 Column() { 61 Text(this.title) 62 .width('95%') 63 .margin({ left: 10, top: 15 }) 64 .fontSize(20) 65 .fontColor($r('app.color.gray')) 66 Column() { 67 List() { 68 LazyForEach(this.operationData, (item: BaseData, index: number) => { 69 ListItem() { 70 this.OperationItem(new Data(item, index)); 71 } 72 }, (item: BaseData) => item.key) 73 } 74 } 75 .width('95%') 76 .backgroundColor($r('app.color.white')) 77 .margin({ top: 10 }) 78 .padding(10) 79 .border({ color: $r('app.color.white'), width: 1, radius: 15 }) 80 } 81 } 82} 83 84class Data { 85 operationInfo: BaseData = new BaseData(); 86 index: number = 0; 87 88 constructor(operationInfo: BaseData, index: number) { 89 this.operationInfo = operationInfo; 90 this.index = index; 91 } 92}