1/* 2 * Copyright (c) 2022 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 */ 15 16import deviceInfo from '@ohos.deviceInfo'; 17import { NoteContentCompPortrait } from '@ohos/component/src/main/ets/components/NoteContentCompPortrait' 18import { NoteContent } from '@ohos/component/src/main/ets/components/NoteContent' 19import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' 20import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil' 21import inputMethod from '@ohos.inputMethod' 22 23@Entry 24@Component 25struct NoteContentHome { 26 @Provide('RefreshFlag') refreshFlag: number = 0 27 private controllerShow: WebController = new WebController() 28 @StorageLink('DBQueryFinished') dBQueryFinished: number = 0 29 @StorageLink('breakPoint') breakPoints: string = 'lg' 30 TAG = "NoteContentHome_Tablet" 31 32 build() { 33 // Note content display area 34 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { 35 if (this.dBQueryFinished == 1) { 36 if (this.breakPoints == 'sm') { 37 NoteContentCompPortrait({ controllerShow: this.controllerShow }) 38 } else { 39 NoteContent({ controllerShow: this.controllerShow }) 40 } 41 42 } 43 } 44 .backgroundColor($r("app.color.notecontent_color_ffffff")) 45 .width('100%') 46 .height('100%') 47 } 48 49 onBackPress(): void { 50 LogUtil.info(this.TAG, "onBackPress") 51 this.controllerShow.runJavaScript({ script: "RICH_EDITOR.setInputEnabled(false)" }) 52 this.controllerShow.runJavaScript({ script: "getHtmlContent()" }) 53 if (deviceInfo.deviceType !== 'phone' && deviceInfo.deviceType !== 'default') { 54 // @ts-ignore 55 inputMethod.getController().stopInputSession(); 56 } 57 } 58 59 aboutToAppear(): void { 60 this.breakPoints = AppStorage.Get('breakPoint') 61 LogUtil.info(this.TAG, "aboutToAppear") 62 let isContinue = AppStorage.Get<boolean>('IsContinue') 63 LogUtil.info(this.TAG, "aboutToAppear, isContinue : " + isContinue) 64 if (isContinue) { 65 RdbStoreUtil.initAppStorage(globalThis.noteContext) 66 } 67 if (deviceInfo.deviceType === 'phone' || deviceInfo.deviceType === 'default') { 68 AppStorage.SetOrCreate<boolean>('NoteContentHomeExist', true) 69 } 70 } 71}