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 LogUtils from '../utils/LogUtils' 16import router from '@ohos.router'; 17 18const TAG = 'HeadComponent' 19 20/** 21 * head custom component 22 */ 23@Component 24export default struct HeadComponent { 25 @State isTouch?: boolean = false; 26 title: Resource | string = $r('app.string.mobile_data'); 27 isTerminateSelf: boolean = true 28 29 build() { 30 Row() { 31 Stack({ alignContent: Alignment.Center }) { 32 Image($r('app.media.ic_back')) 33 .width(24) 34 .height(24) 35 .fillColor($r('sys.color.ohos_id_color_primary')) 36 } 37 .margin({ right: 16 }) 38 .backgroundColor(this.isTouch ? $r('app.color.color_E3E3E3_grey') : $r('app.color.color_00000000_transparent')) 39 .onClick(() => { 40 if (this.isTerminateSelf) { 41 globalThis.settingsAbilityContext?.terminateSelf().then((data) => { 42 LogUtils.i(TAG, 'terminateSelfCallBack'); 43 }); 44 } else { 45 router.back() 46 } 47 }) 48 .onTouch((event: TouchEvent) => { 49 if (event.type === TouchType.Down) { 50 this.isTouch = true; 51 } 52 if (event.type === TouchType.Up) { 53 this.isTouch = false; 54 } 55 }); 56 57 Text(this.title) 58 .fontSize(20) 59 .fontFamily('HarmonyHeiTi-Bold') 60 .fontWeight(FontWeight.Medium) 61 .fontColor($r('sys.color.ohos_id_color_text_primary')) 62 .maxLines(1) 63 .textOverflow({ overflow: TextOverflow.Ellipsis }) 64 .textAlign(TextAlign.Start) 65 .margin({ top: 15, bottom: 15 }); 66 } 67 .width('100%') 68 .padding({ left: 12 }) 69 .height(56) 70 .alignItems(VerticalAlign.Center) 71 .align(Alignment.Start) 72 } 73}