1/* 2 * Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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'; 17 18@Component 19export default struct Title { 20 private titleText: string | Resource = $r('app.string.EntryAbility_label'); 21 private hasBack: boolean = false; 22 private isIndex: boolean = true; 23 24 aboutToAppear() { 25 this.hasBack = Number(router.getLength()) > 0; 26 } 27 28 build() { 29 Row() { 30 Row({ space: 16 }) { 31 if (this.hasBack) { 32 Image(this.isIndex ? $r('app.media.ic_back') : $r('app.media.ic_back_black')) 33 .id('back') 34 .width(24) 35 .height('100%') 36 .objectFit(ImageFit.Contain) 37 .onClick(() => { 38 router.back(); 39 AppStorage.Set('isRefresh', true); 40 }) 41 } 42 Text(this.titleText) 43 .layoutWeight(1) 44 .fontColor(this.isIndex ? $r('app.color.COLOR_FFFFFF') : $r('app.color.COLOR_E6000000')) 45 .fontSize(20) 46 .fontFamily($r('app.string.font_family')) 47 } 48 .width('40%') 49 .height('100%') 50 .margin({ left: 26, right: 18 }) 51 52 Blank() 53 54 if (this.isIndex) { 55 Image($r('app.media.ic_more')) 56 .id('setting') 57 .width(24) 58 .height('100%') 59 .objectFit(ImageFit.Contain) 60 .margin({ right: 24 }) 61 .onClick(() => { 62 router.pushUrl({ url: 'pages/Setting' }); 63 }) 64 } 65 66 } 67 .height('8%') 68 .width('100%') 69 .alignItems(VerticalAlign.Center) 70 .constraintSize({ minHeight: 70 }) 71 .backgroundColor(this.isIndex ? $r('app.color.COLOR_000000') : $r('app.color.COLOR_F1F3F5')) 72 } 73}