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