From d812cc06d946aa614925942430b9bbc86f814832 Mon Sep 17 00:00:00 2001 From: haoxiaohui Date: Fri, 7 Nov 2025 13:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BB=B4=E6=B5=8B=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=8C=E4=BF=AE=E6=94=B9jscrash=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: haoxiaohui --- .../ets/default/access/MediaLibraryAccess.ets | 2 +- .../src/main/ets/default/baseUtil/LogUtil.ts | 15 +++++--- .../ets/default/baseUtil/OperationUtils.ets | 4 +- .../src/main/ets/components/NoteContent.ets | 12 ++++-- .../components/NoteContentCompPortrait.ets | 13 ++++--- .../src/main/ets/MainAbility/MainAbility.ts | 38 ++++++++++++++++--- .../src/main/ets/pages/NoteContentHome.ets | 2 + .../default/src/main/ets/pages/NoteHome.ets | 6 ++- 8 files changed, 69 insertions(+), 23 deletions(-) diff --git a/common/utils/src/main/ets/default/access/MediaLibraryAccess.ets b/common/utils/src/main/ets/default/access/MediaLibraryAccess.ets index 17b4ed3..2c2846d 100644 --- a/common/utils/src/main/ets/default/access/MediaLibraryAccess.ets +++ b/common/utils/src/main/ets/default/access/MediaLibraryAccess.ets @@ -33,7 +33,7 @@ export class MediaLibraryAccess { try { // 通过Uri拷贝图片到指定指定的包路径下 // 1、获取本地路径 - + LogUtil.info(TAG, 'getFirstObject start: '+JSON.stringify(fetchOpt)); let fileResult = await photoAccessHelper.getPhotoAccessHelper(context).getAssets(fetchOpt) if (fileResult != undefined) { album.count = fileResult.getCount(); diff --git a/common/utils/src/main/ets/default/baseUtil/LogUtil.ts b/common/utils/src/main/ets/default/baseUtil/LogUtil.ts index 8043a88..521018f 100644 --- a/common/utils/src/main/ets/default/baseUtil/LogUtil.ts +++ b/common/utils/src/main/ets/default/baseUtil/LogUtil.ts @@ -12,13 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import hilog from '@ohos.hilog' +import hilog from '@ohos.hilog'; + +const TAG: string = 'SampleNote'; export class LogUtil { private static readonly IS_DEBUG_ON: boolean = false; private static readonly CONTACTS_DOMAIN: number = 0x0927; private static readonly SLASH: string = "/"; private static readonly COLON: string = ": "; + constructor() { } @@ -28,21 +31,21 @@ export class LogUtil { static debug(tag: string, msg: string, ...args: any[]) { if (this.IS_DEBUG_ON) { - hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); + hilog.info(this.CONTACTS_DOMAIN, TAG, this.prefix(tag)+ msg, args); } else { - hilog.debug(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); + hilog.debug(this.CONTACTS_DOMAIN, TAG, this.prefix(tag)+ msg, args); } } static info(tag: string, msg: string, ...args: any[]) { - hilog.info(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); + hilog.info(this.CONTACTS_DOMAIN, TAG, this.prefix(tag)+ msg, args); } static warn(tag: string, msg: string, ...args: any[]) { - hilog.warn(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); + hilog.warn(this.CONTACTS_DOMAIN, TAG, this.prefix(tag)+ msg, args); } static error(tag: string, msg: string, ...args: any[]) { - hilog.error(this.CONTACTS_DOMAIN, this.prefix(tag), msg, args); + hilog.error(this.CONTACTS_DOMAIN, TAG, this.prefix(tag)+ msg, args); } } \ No newline at end of file diff --git a/common/utils/src/main/ets/default/baseUtil/OperationUtils.ets b/common/utils/src/main/ets/default/baseUtil/OperationUtils.ets index 10b3b67..0c5435f 100644 --- a/common/utils/src/main/ets/default/baseUtil/OperationUtils.ets +++ b/common/utils/src/main/ets/default/baseUtil/OperationUtils.ets @@ -25,9 +25,11 @@ let noteContext = AppStorage.Get('noteContext')!; export class OperationUtils { async copy(uri: string): Promise { + LogUtil.info(TAG, 'copy start :'+ uri); let imagePath: string = ''; try { let context = noteContext; + LogUtil.info(TAG, 'getFileAssetById start :'+ uri); let fileAsset = await this.getFileAssetById(uri, context); if (fileAsset == null || fileAsset == undefined) { LogUtil.warn(TAG, "Failed to get fileAsset"); @@ -110,7 +112,7 @@ export class OperationUtils { } async getFileAssetById(imagePath: string, context: common.UIAbilityContext) { - LogUtil.info(TAG, 'getFileAssetById', imagePath); + LogUtil.info(TAG, 'getFileAssetById:', imagePath); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOpt: photoAccessHelper.FetchOptions = { fetchColumns: [], diff --git a/features/src/main/ets/components/NoteContent.ets b/features/src/main/ets/components/NoteContent.ets index b0482ea..3f17804 100644 --- a/features/src/main/ets/components/NoteContent.ets +++ b/features/src/main/ets/components/NoteContent.ets @@ -37,6 +37,7 @@ import inputMethod from '@ohos.inputMethod'; import { folderTextMap } from '@ohos/utils/src/main/ets/default/model/NoteBaseData' import webview from '@ohos.web.webview'; import common from '@ohos.app.ability.common'; +import { emitter } from '@kit.BasicServicesKit' const TAG: string = 'NoteContent'; @@ -267,13 +268,16 @@ export struct NoteContent { aboutToAppear(): void { LogUtil.info(TAG, "aboutToAppear") + emitter.on('backToHome', () => { + clearInterval(timeID); + }) } aboutToDisappear(): void { - AppStorage.Set("refreshCurrentNote", true) - NoteUtil.refreshAll() - clearInterval(timeID) - LogUtil.info(TAG, "aboutToDisappear") + AppStorage.set("refreshCurrentNote", true); + emitter.off('backToHome'); + NoteUtil.refreshAll(); + LogUtil.info(TAG, "aboutToDisappear"); } } diff --git a/features/src/main/ets/components/NoteContentCompPortrait.ets b/features/src/main/ets/components/NoteContentCompPortrait.ets index 9945836..8597794 100644 --- a/features/src/main/ets/components/NoteContentCompPortrait.ets +++ b/features/src/main/ets/components/NoteContentCompPortrait.ets @@ -44,6 +44,7 @@ import common from '@ohos.app.ability.common'; import window from '@ohos.window'; import { wantAgent, WantAgent } from '@kit.AbilityKit'; import { backgroundTaskManager } from '@kit.BackgroundTasksKit'; +import { emitter } from '@kit.BasicServicesKit' let time_id: number = 0; let noteContext = AppStorage.get('noteContext')!; @@ -143,7 +144,6 @@ export struct NoteContentCompPortrait { if (this.selectedNoteData.content_text === html) { return; } - ; this.selectedNoteData.content_text = html; this.selectedNoteData.modified_time = new Date().getTime(); let predicatesNote = RdbStoreUtil.getRdbPredicates(TableName.NoteTable); @@ -423,7 +423,10 @@ export struct NoteContentCompPortrait { } aboutToAppear(): void { - this.isClickBack = false + this.isClickBack = false; + emitter.on('backToHome', () => { + clearInterval(time_id); + }) LogUtil.info(TAG, 'aboutToAppear'); window.getLastWindow(this.getUIContext().getHostContext()).then(currentWindow => { currentWindow.setWindowLayoutFullScreen(true); @@ -432,10 +435,10 @@ export struct NoteContentCompPortrait { aboutToDisappear(): void { this.isClickBack = true - clearInterval(time_id) - NoteUtil.refreshAll() + emitter.off('backToHome'); + NoteUtil.refreshAll(); LogUtil.info(TAG, 'aboutToDisappear'); - this.editContentDialogCtl = null + this.editContentDialogCtl = null; } } diff --git a/product/default/src/main/ets/MainAbility/MainAbility.ts b/product/default/src/main/ets/MainAbility/MainAbility.ts index 9ec141d..16eb395 100644 --- a/product/default/src/main/ets/MainAbility/MainAbility.ts +++ b/product/default/src/main/ets/MainAbility/MainAbility.ts @@ -24,6 +24,7 @@ import window from '@ohos.window'; import util from '@ohos.util'; import common from '@ohos.app.ability.common'; import relationalStore from '@ohos.data.relationalStore'; +import { Configuration } from '@ohos.app.ability.Configuration'; AppStorage.setOrCreate('rdbStore', undefined); @@ -33,7 +34,8 @@ export default class MainAbility extends UIAbility { onCreate(want, launchParam) { AppStorage.setOrCreate('context', this.context); - LogUtil.info(this.Tag, " onCreate, launchReason is " + launchParam.launchReason + ", deviceType" + deviceInfo.deviceType); + LogUtil.info(this.Tag, + " onCreate, launchReason is " + launchParam.launchReason + ", deviceType" + deviceInfo.deviceType); if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { AppStorage.setOrCreate('Expand', false); AppStorage.setOrCreate('Choose', true); @@ -79,6 +81,7 @@ export default class MainAbility extends UIAbility { let windowClass = data; try { windowClass.on('windowSizeChange', (data) => { + LogUtil.info(this.Tag, " --------------- windowSizeChange ---------------"); this.screenBreakPoints(data.width); }) // 窗口规避区域 @@ -105,6 +108,7 @@ export default class MainAbility extends UIAbility { } }) window.getLastWindow(this.context, (err, data) => { + LogUtil.info(this.Tag, " --------------- getLastWindow ----------------"); if (data && data.getWindowProperties()) { let windowWidth = data.getWindowProperties().windowRect.width; LogUtil.info(this.Tag, " getLastWindow:" + windowWidth); @@ -122,15 +126,39 @@ export default class MainAbility extends UIAbility { } onForeground() { - LogUtil.info(this.Tag, " onForeground"); + LogUtil.info(this.Tag, " ------------- onForeground ------------- "); } onBackground() { - LogUtil.info(this.Tag, " onBackground"); + LogUtil.info(this.Tag, " ------------- onBackground ------------- "); // 退出键盘 inputMethod.getController().stopInputSession(); } + onWillBackground(): void { + LogUtil.info(this.Tag, " ------------- onWillBackground ------------- "); + } + + onDidBackground(): void { + LogUtil.info(this.Tag, " ------------- onDidBackground ------------- "); + } + + onWillForeground(): void { + LogUtil.info(this.Tag, " ------------- onWillForeground ------------- "); + } + + onDidForeground(): void { + LogUtil.info(this.Tag, " ------------- onDidForeground ------------- "); + } + + onConfigurationUpdate(newConfig: Configuration): void { + LogUtil.info(this.Tag, " ------------- onConfigurationUpdate : " + JSON.stringify(newConfig) + " ------------- "); + } + + onMemoryLevel(level: AbilityConstant.MemoryLevel): void { + LogUtil.info(this.Tag, " ------------- onMemoryLevel : " + JSON.stringify(level) + " ------------- "); + } + onContinue(wantParam: { [key: string]: any }) { LogUtil.info(this.Tag, " onContinue"); // 获取本端的迁移数据 @@ -186,7 +214,7 @@ export default class MainAbility extends UIAbility { } getSrcFromHtml(html: string): any { - LogUtil.info(this.Tag, " getSrcFromHtml "+ html); + LogUtil.info(this.Tag, " getSrcFromHtml " + html); let srcArray = []; if (html == undefined || html == null || html == "") { return srcArray; @@ -235,7 +263,7 @@ export default class MainAbility extends UIAbility { screenDpi = displayClass.densityDPI; AppStorage.setOrCreate('dpi', screenDpi); let windowWidth = data / (screenDpi / 160); - LogUtil.debug(this.Tag, " screenBreakPoints windowWidth: " + windowWidth); + LogUtil.info(this.Tag, " screenBreakPoints windowWidth: " + windowWidth); if (windowWidth >= 320 && windowWidth < 520 || windowWidth < 320) { AppStorage.setOrCreate('breakPoint', 'sm'); } else if (windowWidth >= 520 && windowWidth < 840) { diff --git a/product/default/src/main/ets/pages/NoteContentHome.ets b/product/default/src/main/ets/pages/NoteContentHome.ets index 697ab4c..8736507 100644 --- a/product/default/src/main/ets/pages/NoteContentHome.ets +++ b/product/default/src/main/ets/pages/NoteContentHome.ets @@ -21,6 +21,7 @@ import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil import inputMethod from '@ohos.inputMethod' import webview from '@ohos.web.webview'; import common from '@ohos.app.ability.common'; +import { emitter } from '@kit.BasicServicesKit'; @Entry @Component @@ -56,6 +57,7 @@ struct NoteContentHome { if (deviceInfo.deviceType !== 'phone' && deviceInfo.deviceType !== 'default') { inputMethod.getController().stopInputSession(); } + emitter.emit('backToHome'); } catch (error) { LogUtil.info(this.TAG, 'onBackPress error') } diff --git a/product/default/src/main/ets/pages/NoteHome.ets b/product/default/src/main/ets/pages/NoteHome.ets index c56f1d8..e9cb339 100644 --- a/product/default/src/main/ets/pages/NoteHome.ets +++ b/product/default/src/main/ets/pages/NoteHome.ets @@ -42,11 +42,15 @@ export struct NoteHomeComp { @Provide('SelectedAll') selectedAll: boolean = false @Provide('EditModel') editModel: boolean = false //编辑模式:临时方案 @Provide('Issave') issave: number = 0 - @StorageLink('breakPoint') breakPoints: string = 'lg' + @StorageLink('breakPoint') @Watch('onBreakPoints') breakPoints: string = 'lg' controllerShow: webview.WebviewController = new webview.WebviewController(); TAG = "NoteHomeComp_Tablet" @Provide('AsideWidth') asideWidth: number = 200 + onBreakPoints(){ + LogUtil.info(this.TAG, "onBreakPoints : "+this.breakPoints); + } + build() { Flex({ justifyContent: FlexAlign.Start }) { if (this.breakPoints === 'lg') {