From 46d4726f792e4d79cfd1ea2083e948ca9b7960cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BF=9E=E6=BC=AA?= Date: Wed, 9 Apr 2025 16:41:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E8=A8=80=E5=8F=98=E5=8C=96=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=85=83=E6=9C=8D=E5=8A=A1label=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 连漪 --- customappbar/interfaces/custom_app_bar.js | 27 +++++++++++++++++++++-- customappbar/source/custom_app_bar.ets | 9 ++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/customappbar/interfaces/custom_app_bar.js b/customappbar/interfaces/custom_app_bar.js index f6212ca..2cdc46f 100644 --- a/customappbar/interfaces/custom_app_bar.js +++ b/customappbar/interfaces/custom_app_bar.js @@ -70,6 +70,7 @@ const EVENT_NAME_CUSTOM_APP_BAR_DID_BUILD = 'arkui_custom_app_bar_did_build'; const EVENT_NAME_CUSTOM_APP_BAR_CREATE_SERVICE_PANEL = 'arkui_custom_app_bar_create_service_panel'; const ARKUI_APP_BAR_SERVICE_PANEL = 'arkui_app_bar_service_panel'; const ARKUI_APP_BAR_CLOSE = 'arkui_app_bar_close'; +const ARKUI_APP_BAR_PROVIDE_SERVICE = 'arkui_app_bar_provide_service'; /** * 适配不同颜色模式集合 @@ -137,10 +138,11 @@ export class CustomAppBar extends ViewPU { this.__breakPoint = new ObservedPropertySimplePU(BreakPointsType.NONE, this, 'breakPoint'); this.__serviceMenuRead = new ObservedPropertySimplePU(this.getStringByResourceToken(ARKUI_APP_BAR_SERVICE_PANEL), this, 'serviceMenuRead'); this.__closeRead = new ObservedPropertySimplePU(this.getStringByResourceToken(ARKUI_APP_BAR_CLOSE), this, 'closeRead'); + this.__provideService = new ObservedPropertySimplePU('', this, 'provideService'); + this.__labelName = new ObservedPropertySimplePU('', this, 'labelName'); this.isHalfToFullScreen = false; this.isDark = true; this.bundleName = ''; - this.labelName = ''; this.icon = { 'id': -1, 'type': 20000, params: ['sys.media.ohos_app_icon'], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }; this.fullContentMarginTop = 0; this.windowWidth = 0; @@ -244,6 +246,9 @@ export class CustomAppBar extends ViewPU { if (params.closeRead !== undefined) { this.closeRead = params.closeRead; } + if (params.provideService !== undefined) { + this.provideService = params.provideService; + } if (params.isHalfToFullScreen !== undefined) { this.isHalfToFullScreen = params.isHalfToFullScreen; } @@ -314,6 +319,8 @@ export class CustomAppBar extends ViewPU { this.__breakPoint.purgeDependencyOnElmtId(rmElmtId); this.__serviceMenuRead.purgeDependencyOnElmtId(rmElmtId); this.__closeRead.purgeDependencyOnElmtId(rmElmtId); + this.__provideService.purgeDependencyOnElmtId(rmElmtId); + this.__labelName.purgeDependencyOnElmtId(rmElmtId); } aboutToBeDeleted() { this.__menuResource.aboutToBeDeleted(); @@ -346,6 +353,8 @@ export class CustomAppBar extends ViewPU { this.__breakPoint.aboutToBeDeleted(); this.__serviceMenuRead.aboutToBeDeleted(); this.__closeRead.aboutToBeDeleted(); + this.__provideService.aboutToBeDeleted(); + this.__labelName.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id__()); this.aboutToBeDeletedInternal(); } @@ -529,10 +538,23 @@ export class CustomAppBar extends ViewPU { set closeRead(newValue) { this.__closeRead.set(newValue); } + get provideService() { + return this.__provideService.get(); + } + set provideService(newValue) { + this.__provideService.set(newValue); + } + get labelName() { + return this.__labelName.get(); + } + set labelName(newValue) { + this.__labelName.set(newValue); + } aboutToAppear() { if (this.isHalfScreen) { this.contentBgColor = Color.Transparent; this.titleHeight = EYELASH_HEIGHT + 2 * TITLE_MARGIN_TOP + this.statusBarHeight; + this.provideService = this.getStringByResourceToken(ARKUI_APP_BAR_PROVIDE_SERVICE); this.halfScreenShowAnimation(); } else { @@ -655,6 +677,7 @@ export class CustomAppBar extends ViewPU { } this.bundleName = splitArray[0]; this.labelName = splitArray[1]; + this.provideService = this.getStringByResourceToken(ARKUI_APP_BAR_PROVIDE_SERVICE); } else if (eventName === ARKUI_APP_BAR_SCREEN) { this.isHalfScreen = this.parseBoolean(param); @@ -975,7 +998,7 @@ export class CustomAppBar extends ViewPU { }, Text); Text.pop(); this.observeComponentCreation2((elmtId, isInitialRender) => { - Text.create('提供服务'); + Text.create(this.provideService); Text.fontSize(TITLE_FONT_SIZE); Text.lineHeight(TITLE_LINE_HEIGHT); Text.fontColor('#FFFFFF'); diff --git a/customappbar/source/custom_app_bar.ets b/customappbar/source/custom_app_bar.ets index ff84270..0add41d 100644 --- a/customappbar/source/custom_app_bar.ets +++ b/customappbar/source/custom_app_bar.ets @@ -63,6 +63,7 @@ const ARKUI_APP_BAR_SCREEN: string = 'arkui_app_bar_screen'; const ARKUI_APP_BG_COLOR: string = 'arkui_app_bg_color'; const ARKUI_APP_BAR_SERVICE_PANEL: string = 'arkui_app_bar_service_panel'; const ARKUI_APP_BAR_CLOSE: string = 'arkui_app_bar_close'; +const ARKUI_APP_BAR_PROVIDE_SERVICE: string = 'arkui_app_bar_provide_service'; const EVENT_NAME_CUSTOM_APP_BAR_MENU_CLICK = 'arkui_custom_app_bar_menu_click'; const EVENT_NAME_CUSTOM_APP_BAR_CLOSE_CLICK = 'arkui_custom_app_bar_close_click'; const EVENT_NAME_CUSTOM_APP_BAR_DID_BUILD = 'arkui_custom_app_bar_did_build'; @@ -149,10 +150,11 @@ export struct CustomAppBar { @State @Watch('onBreakPointChange') breakPoint: BreakPointsType = BreakPointsType.NONE; @State serviceMenuRead: string = this.getStringByResourceToken(ARKUI_APP_BAR_SERVICE_PANEL); @State closeRead: string = this.getStringByResourceToken(ARKUI_APP_BAR_CLOSE); + @State provideService: string = ''; private isHalfToFullScreen: boolean = false; private isDark: boolean = true; private bundleName: string = ''; - private labelName: string = ''; + @State labelName: string = ''; private icon: Resource | string | PixelMap = $r('sys.media.ohos_app_icon'); private fullContentMarginTop: number = 0; private windowWidth: number = 0; @@ -166,6 +168,7 @@ export struct CustomAppBar { if (this.isHalfScreen) { this.contentBgColor = Color.Transparent; this.titleHeight = EYELASH_HEIGHT + 2 * TITLE_MARGIN_TOP + this.statusBarHeight; + this.provideService = this.getStringByResourceToken(ARKUI_APP_BAR_PROVIDE_SERVICE); this.halfScreenShowAnimation(); } else { this.containerHeight = '100%'; @@ -290,6 +293,8 @@ export struct CustomAppBar { } this.bundleName = splitArray[0]; this.labelName = splitArray[1]; + this.provideService = this.getStringByResourceToken(ARKUI_APP_BAR_PROVIDE_SERVICE); + } else if (eventName === ARKUI_APP_BAR_SCREEN) { this.isHalfScreen = this.parseBoolean(param); this.initBreakPointListener(); @@ -548,7 +553,7 @@ export struct CustomAppBar { .maxLines(1) .textOverflow({ overflow: TextOverflow.Ellipsis }) .ellipsisMode(EllipsisMode.END) - Text('提供服务') + Text(this.provideService) .fontSize(TITLE_FONT_SIZE) .lineHeight(TITLE_LINE_HEIGHT) .fontColor('#FFFFFF') -- Gitee