1/* 2 * Copyright (c) 2022 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 { gridData } from '../model/GridData' 17 18@Component 19export struct GridDataItem { 20 @State bgrColor: string = '#222324' 21 @Link isBom: boolean 22 @Link isTitle: string 23 @Link isXComponent: boolean 24 @Link @Watch('clickSetBgrColor') clickIndex: number 25 private context: any 26 private item: gridData 27 private index: number = -1 28 @State videoText:string = '' 29 async aboutToAppear() { 30 this.videoText = await this.convertResourceToString($r('app.string.phoneMain_video')) 31 } 32 async convertResourceToString(resource: Resource){ 33 return await this.context.resourceManager.getString(resource) 34 } 35 clickSetBgrColor() { 36 if (this.index !== this.clickIndex) { 37 this.bgrColor = '#222324' 38 } else { 39 this.bgrColor = 'rgba(255,255,255,0.1)' 40 } 41 } 42 43 build() { 44 Column() { 45 Image(this.item.icon).width(40).height(40) 46 Text(this.item.textStr) 47 .margin({ top: 5 }) 48 .fontSize(16) 49 .fontColor('rgba(255,255,255,0.90)') 50 .fontStyle(FontStyle.Normal) 51 .fontWeight(400) 52 .textAlign(TextAlign.Center) 53 .fontFamily('HarmonyHeiTi') 54 } 55 .justifyContent(FlexAlign.Center) 56 .alignItems(HorizontalAlign.Center) 57 .width(95) 58 .height(95) 59 .borderRadius(12) 60 .backgroundColor(this.bgrColor) 61 .onClick(() => { 62 this.clickIndex = this.index 63 this.isBom = !this.isBom 64 this.isTitle = this.item.textStr 65 if (this.isTitle == this.videoText ) { 66 this.isXComponent = true 67 } 68 }) 69 } 70}