From 1958a3b2352a50084bc769343029854536187c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B3=BD?= <65395957+wangzetx@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:33:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=89=E5=85=A8=E7=BC=96=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ets/common/constants/CommonConstants.ets | 9 ---- .../main/ets/entryability/EntryAbility.ets | 40 ++++++++------ .../main/ets/pages/BindContentCoverDemo.ets | 1 - entry/src/main/ets/pages/Privacy.ets | 3 -- entry/src/main/ets/pages/Toast.ets | 1 - entry/src/main/ets/view/AddPassengers.ets | 6 ++- .../ets/view/CustomCalendarPickerDialog.ets | 3 +- entry/src/main/ets/view/DefaultList.ets | 8 ++- entry/src/main/ets/viewmodel/DataManager.ets | 54 +------------------ .../main/ets/viewmodel/MonthDataSource.ets | 25 +-------- 10 files changed, 37 insertions(+), 113 deletions(-) diff --git a/entry/src/main/ets/common/constants/CommonConstants.ets b/entry/src/main/ets/common/constants/CommonConstants.ets index 6c5077c..688004c 100644 --- a/entry/src/main/ets/common/constants/CommonConstants.ets +++ b/entry/src/main/ets/common/constants/CommonConstants.ets @@ -124,15 +124,6 @@ export class CommonConstants { */ public static readonly BREAK_POINT_SM: string = 'sm'; - /** - * Breakpoint md. - */ - public static readonly BREAK_POINT_MD: string = 'md'; - - /** - * Breakpoint lg. - */ - public static readonly BREAK_POINT_LG: string = 'lg'; /** * MD and LG width. diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 14d413c..bf6ca96 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -39,7 +39,8 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('currentBreakpoint', this.curBp); } } catch (error) { - hilog.error(0x0000, 'EntryAbility', 'updateBreakpoint catch err:', JSON.stringify(error) ?? ''); + const err = error as BusinessError; + hilog.error(0x0000, 'EntryAbility', `updateBreakpoint catch err, code: ${err.code}, message: ${err.message}`); } } @@ -64,19 +65,24 @@ export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { windowStage.getMainWindow().then((windowObj: window.Window) => { - let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; - let avoidArea = windowObj.getWindowAvoidArea(type); - let bottomRectHeight = avoidArea.bottomRect.height; - AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); - type = window.AvoidAreaType.TYPE_SYSTEM; - avoidArea = windowObj.getWindowAvoidArea(type); - let topRectHeight = avoidArea.topRect.height; - AppStorage.setOrCreate('topRectHeight', topRectHeight); - this.windowObj = windowObj; - this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); - windowObj.on('windowSizeChange', (windowSize) => { - this.updateBreakpoint(windowSize.width); - }) + try { + let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; + let avoidArea = windowObj.getWindowAvoidArea(type); + let bottomRectHeight = avoidArea.bottomRect.height; + AppStorage.setOrCreate('bottomRectHeight', bottomRectHeight); + type = window.AvoidAreaType.TYPE_SYSTEM; + avoidArea = windowObj.getWindowAvoidArea(type); + let topRectHeight = avoidArea.topRect.height; + AppStorage.setOrCreate('topRectHeight', topRectHeight); + this.windowObj = windowObj; + this.updateBreakpoint(windowObj.getWindowProperties().windowRect.width); + windowObj.on('windowSizeChange', (windowSize) => { + this.updateBreakpoint(windowSize.width); + }); + } catch (error) { + const err = error as BusinessError; + hilog.error(0x000, '[EntryAbility]', `onWindowStageCreate catch err, code: ${err.code}, message:${err.message}`); + } }); // Main window is created, set main page for this ability hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); @@ -85,7 +91,7 @@ export default class EntryAbility extends UIAbility { AppStorage.setOrCreate('resourceManager', resourceManager); windowStage.loadContent('pages/Index', (err, data) => { if (err.code) { - hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + hilog.error(0x0000, 'testTag', `Failed to load the content, err code: ${err.code}, message: ${err.message}`); return; } hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); @@ -94,8 +100,8 @@ export default class EntryAbility extends UIAbility { windowClass.setWindowLayoutFullScreen(isLayoutFullScreen).then(() => { hilog.info(0x0000, 'testTag', '%{public}s', 'Succeeded in setting the window layout to full-screen mode.'); }).catch((err: BusinessError) => { - hilog.error(0x0000, 'testTag', '%{public}s', - `Failed to set the window layout to full-screen mode. Cause:${err}`); + hilog.error(0x0000, 'testTag', + `Failed to set the window layout to full-screen mode, err code: ${err.code}, message: ${err.message}}`); }); }); } diff --git a/entry/src/main/ets/pages/BindContentCoverDemo.ets b/entry/src/main/ets/pages/BindContentCoverDemo.ets index 8a837dd..20fba93 100644 --- a/entry/src/main/ets/pages/BindContentCoverDemo.ets +++ b/entry/src/main/ets/pages/BindContentCoverDemo.ets @@ -21,7 +21,6 @@ struct BindContentCoverDemo { @StorageLink('topRectHeight') topRectHeight: number = 0; @StorageLink('bottomRectHeight') bottomRectHeight: number = 0; @StorageLink('currentBreakpoint') curBp: string = CommonConstants.BREAK_POINT_SM; - @State isPresent: boolean = false; pageInfos: NavPathStack = new NavPathStack(); build() { diff --git a/entry/src/main/ets/pages/Privacy.ets b/entry/src/main/ets/pages/Privacy.ets index 199481a..4194654 100644 --- a/entry/src/main/ets/pages/Privacy.ets +++ b/entry/src/main/ets/pages/Privacy.ets @@ -23,8 +23,6 @@ struct Privacy { @StorageLink('topRectHeight') topRectHeight: number = 0; @StorageLink('bottomRectHeight') bottomRectHeight: number = 0; @StorageLink('currentBreakpoint') curBp: string = CommonConstants.BREAK_POINT_SM; - @State visible: Visibility = Visibility.None; - scroller: Scroller = new Scroller(); dialogController: CustomDialogController | null = new CustomDialogController({ builder: PrivacyDialog({ cancel: () => { @@ -44,7 +42,6 @@ struct Privacy { } } }) - controller?: CustomDialogController; onCancel() { hilog.info(0x0000, 'Privacy', '%{public}s', 'Callback when the first button is clicked'); diff --git a/entry/src/main/ets/pages/Toast.ets b/entry/src/main/ets/pages/Toast.ets index e4d2f1f..7a8b021 100644 --- a/entry/src/main/ets/pages/Toast.ets +++ b/entry/src/main/ets/pages/Toast.ets @@ -41,7 +41,6 @@ struct CustomDialogUser { @StorageLink('topRectHeight') topRectHeight: number = 0; @StorageLink('bottomRectHeight') bottomRectHeight: number = 0; @StorageLink('currentBreakpoint') curBp: string = CommonConstants.BREAK_POINT_SM; - @State textValue: string = ''; @State inputValue: ResourceStr = $r('app.string.click'); dialogController: CustomDialogController | null = new CustomDialogController({ builder: CustomDialogExample(), diff --git a/entry/src/main/ets/view/AddPassengers.ets b/entry/src/main/ets/view/AddPassengers.ets index 977d2d9..aa72c5f 100644 --- a/entry/src/main/ets/view/AddPassengers.ets +++ b/entry/src/main/ets/view/AddPassengers.ets @@ -16,6 +16,9 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { PersonList, personList } from '../viewmodel/BindContentModel'; import { CommonConstants } from '../common/constants/CommonConstants'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG = '[getResourceString]'; @Builder export function AddPassengersBuilder() { @@ -34,7 +37,8 @@ export struct AddPassengers { try { resourceString = getContext(this).resourceManager.getStringSync(resource.id); } catch (error) { - hilog.error(0x0000, '[getResourceString]', `getResourceString err: ${error}`); + const err = error as BusinessError; + hilog.error(0x0000, TAG, `getResourceString catch error, code: ${err.code}, message: ${err.message}`); } return resourceString; } diff --git a/entry/src/main/ets/view/CustomCalendarPickerDialog.ets b/entry/src/main/ets/view/CustomCalendarPickerDialog.ets index 419f8a7..0b2019b 100644 --- a/entry/src/main/ets/view/CustomCalendarPickerDialog.ets +++ b/entry/src/main/ets/view/CustomCalendarPickerDialog.ets @@ -30,7 +30,7 @@ export struct CustomCalendarPickerDialog { @State contentData: MonthDataSource = new MonthDataSource(); @State nextMonth: number = 1; @State nextYear: number = 1; - @State nextMonthDay: number[] = []; + @State currentMonthDay: number[] = []; @State initialIndex: number = 0; @Link currentMonth: number; @@ -59,7 +59,6 @@ export struct CustomCalendarPickerDialog { this.nextMonth = this.currentMonth + 1; this.nextYear = this.currentYear; } - this.nextMonthDay = getMonthDate(this.nextMonth, this.nextYear); let months: Month[] = [ { month: `${this.currentYear}${this.getResourceString($r('app.string.year'))} ${this.currentMonth}${this.getResourceString($r('app.string.month'))}`, diff --git a/entry/src/main/ets/view/DefaultList.ets b/entry/src/main/ets/view/DefaultList.ets index 9132533..b046b74 100644 --- a/entry/src/main/ets/view/DefaultList.ets +++ b/entry/src/main/ets/view/DefaultList.ets @@ -1,4 +1,4 @@ -/* + /* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ import { hilog } from '@kit.PerformanceAnalysisKit'; import { CommonConstants } from '../common/constants/CommonConstants'; +import { BusinessError } from '@kit.BasicServicesKit'; + +const TAG = '[getResourceString]'; @Builder export function DefaultListBuilder() { @@ -33,7 +36,8 @@ export struct DefaultList { try { resourceString = getContext(this).resourceManager.getStringSync(resource.id); } catch (error) { - hilog.error(0x0000, '[getResourceString]', `getResourceString err: ${error}`); + const err = error as BusinessError; + hilog.error(0x0000, TAG, `getResourceString catch error, code: ${err.code}, message: ${err.message}`); } return resourceString; } diff --git a/entry/src/main/ets/viewmodel/DataManager.ets b/entry/src/main/ets/viewmodel/DataManager.ets index dc9fd66..e212d4c 100644 --- a/entry/src/main/ets/viewmodel/DataManager.ets +++ b/entry/src/main/ets/viewmodel/DataManager.ets @@ -18,35 +18,6 @@ import { DateModel } from './DateModel'; import { getRealTimeDate } from './GetDate'; export class DataManager { - static getDate(context: Context, callback: (dateModel: DateModel) => void) { - let dateModel: DateModel = getRealTimeDate(); - try { - let promise = preferences.getPreferences(context, 'date'); - promise.then((object: preferences.Preferences) => { - try { - let getPromise = object.get('selectedDate', ''); - getPromise.then((data: preferences.ValueType) => { - let dateSting = data as string; - if (dateSting.length > 0) { - dateModel = JSON.parse(dateSting) as DateModel; - callback(dateModel); - } else { - callback(dateModel); - } - }).catch(() => { - callback(dateModel); - }) - } catch (err) { - callback(dateModel); - } - }).catch(() => { - callback(dateModel); - }) - } catch (err) { - callback(dateModel); - } - } - static setDate(context: Context, dateModel: DateModel, callback: () => void) { try { let promise = preferences.getPreferences(context, 'date'); @@ -74,27 +45,4 @@ export class DataManager { callback(); } } - - static deleteDate(context: Context, callback: () => void) { - try { - let promise = preferences.getPreferences(context, 'date'); - promise.then((object: preferences.Preferences) => { - try { - let deletePromise = object.delete('selectedDate'); - deletePromise.then(() => { - let flushPromise = object.flush(); - flushPromise.then(() => { - AppStorage.setOrCreate('selectedDate', undefined); - callback(); - }).catch(() => { - }) - }).catch(() => { - }) - } catch (err) { - } - }).catch(() => { - }) - } catch (err) { - } - } -} +} \ No newline at end of file diff --git a/entry/src/main/ets/viewmodel/MonthDataSource.ets b/entry/src/main/ets/viewmodel/MonthDataSource.ets index ff3c4d1..a225006 100644 --- a/entry/src/main/ets/viewmodel/MonthDataSource.ets +++ b/entry/src/main/ets/viewmodel/MonthDataSource.ets @@ -50,29 +50,6 @@ export class MonthDataSource implements IDataSource { }) } - notifyDataChange(index: number): void { - this.listeners.forEach(listener => { - listener.onDataChange(index); - }) - } - - notifyDataDelete(index: number): void { - this.listeners.forEach(listener => { - listener.onDataDelete(index); - }) - } - - notifyDataMove(from: number, to: number): void { - this.listeners.forEach(listener => { - listener.onDataMove(from, to); - }) - } - - public addData(index: number, data: Month): void { - this.dataArray.splice(index, 0, data); - this.notifyDataAdd(index); - } - public pushData(data: Month | Month[]): void { if (Array.isArray(data)) { this.dataArray.push(...data); @@ -81,4 +58,4 @@ export class MonthDataSource implements IDataSource { } this.notifyDataAdd(this.dataArray.length - 1); } -} +} \ No newline at end of file -- Gitee