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 { FolderListComp } from '@ohos/component/src/main/ets/components/FolderListComp' 17import { NoteListComp } from '@ohos/component/src/main/ets/components/NoteListComp' 18import { NoteContentComp } from '@ohos/component/src/main/ets/components/NoteContentComp' 19import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants' 20import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' 21import { circleColorArray } from '@ohos/utils/src/main/ets/default/model/NoteBaseData' 22import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData' 23import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData' 24import LayoutUtil from '@ohos/utils/src/main/ets/default/baseUtil/LayoutUtil' 25import webview from '@ohos.web.webview'; 26 27@Entry 28@Component 29export struct NoteHomeComp { 30 // 当前文件夹、笔记、分栏 31 @Provide('SelectedFolderData') selectedFolderData: FolderData = AppStorage.Get('Folder')!; 32 @Provide('SelectedNoteData') selectedNoteData: NoteData = AppStorage.Get('Note')!; 33 @Provide('SectionStatus') sectionStatus: number = AppStorage.Get('Section')!; 34 @Provide('SelectedColor') selectedColor: string = circleColorArray[0] 35 @Provide('LastSectionStatus') lastSectionStatus: number = 3 // 记录分栏上一次的状态 36 @Provide('Longpress') longpress: boolean = false // 第二栏长按状态 37 @Provide('ExpandStatus') expandStatus: boolean = false // 笔记本折叠展开状态 38 @Provide('ChooseNote') chooseNote: boolean = true // 是否选择笔记进行打开 39 @Provide('Search') search: boolean = AppStorage.Get('Search')!; // 是否处于搜索状态 40 @Provide('SearchResultList') searchResultList: NoteData[] = [] // 搜索得到的笔记列表 41 @Provide('InputKeyword') inputKeyword: string = '' // 搜索的字串 42 @Provide('SelectedAll') selectedAll: boolean = false 43 @Provide('EditModel') editModel: boolean = false //编辑模式:临时方案 44 @Provide('Issave') issave: number = 0 45 @StorageLink('breakPoint') breakPoints: string = 'lg' 46 controllerShow: webview.WebviewController = new webview.WebviewController(); 47 TAG = "NoteHomeComp_Tablet" 48 @Provide('AsideWidth') asideWidth: number = 200 49 50 build() { 51 Flex({ justifyContent: FlexAlign.Start }) { 52 if (this.breakPoints === 'lg') { 53 // Folder list display area 54 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) { 55 FolderListComp({ controllerShow: this.controllerShow }) 56 } 57 .flexShrink(0) 58 .backgroundColor($r("app.color.folderlist_bgcolor_f1f3f5")) 59 .width(this.asideWidth) 60 .height(StyleConstants.PERCENTAGE_100) 61 .animation({ duration: 200 }) 62 .enabled(this.search ? false : true) 63 64 // Note list display area 65 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { 66 Divider() 67 .vertical(true) 68 .strokeWidth(1) 69 .color($r("app.color.divider_color_182431")) 70 .height("100%") 71 .opacity(StyleConstants.OPACITY_10) 72 NoteListComp({ controllerShow: this.controllerShow }) 73 } 74 .flexShrink(1) 75 .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) 76 .layoutWeight(2) 77 .height(StyleConstants.PERCENTAGE_100) 78 .visibility( 79 LayoutUtil.getWidthWeightMessage(this.sectionStatus) 80 .noteListVisibility == 0 ? Visibility.None : Visibility.Visible) 81 // Note content display area 82 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { 83 Divider() 84 .vertical(true) 85 .strokeWidth(1) 86 .color($r("app.color.divider_color_182431")) 87 .height("100%") 88 .opacity(StyleConstants.OPACITY_10) 89 NoteContentComp({ controllerShow: this.controllerShow }) 90 } 91 .flexShrink(0) 92 .backgroundColor($r("app.color.notecontent_color_ffffff")) 93 .layoutWeight(this.sectionStatus != 1 ? 3 : null) 94 .height(StyleConstants.PERCENTAGE_100) 95 .enabled(this.longpress || this.search && this.inputKeyword.length == 0 ? false : true) 96 } else if (this.breakPoints === 'md') { 97 Stack({ alignContent: Alignment.Start }) { 98 Row() { 99 // Note list display area 100 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { 101 Divider() 102 .vertical(true) 103 .strokeWidth(1) 104 .color($r("app.color.divider_color_182431")) 105 .height("100%") 106 .opacity(StyleConstants.OPACITY_10) 107 NoteListComp({ controllerShow: this.controllerShow }) 108 } 109 .flexShrink(1) 110 .backgroundColor($r("app.color.notelist_bgcolor_f1f3f5")) 111 .layoutWeight(2) 112 .height(StyleConstants.PERCENTAGE_100) 113 .visibility( 114 LayoutUtil.getWidthWeightMessage(this.sectionStatus) 115 .noteListVisibility == 0 ? Visibility.None : Visibility.Visible) 116 117 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.Start }) { 118 Divider() 119 .vertical(true) 120 .strokeWidth(1) 121 .color($r("app.color.divider_color_182431")) 122 .height("100%") 123 .opacity(StyleConstants.OPACITY_10) 124 NoteContentComp({ controllerShow: this.controllerShow }) 125 } 126 .flexShrink(0) 127 .backgroundColor($r("app.color.notecontent_color_ffffff")) 128 .layoutWeight(this.sectionStatus != 1 ? 3 : null) 129 .height(StyleConstants.PERCENTAGE_100) 130 .enabled(this.longpress || this.search && this.inputKeyword.length == 0 ? false : true) 131 } 132 133 // 蒙层 134 if (this.expandStatus) { 135 Column() 136 .width('100%') 137 .height('100%') 138 .position({ x: 0, y: 0 }) 139 .backgroundColor(Color.Black) 140 .opacity(0.2) 141 .transition({ opacity: 0 }) 142 } 143 //Folder list display area 144 Column() { 145 FolderListComp() 146 } 147 .width(200) 148 .height(StyleConstants.PERCENTAGE_100) 149 .translate({ x: this.expandStatus ? 0 : '-200', y: 0 }) 150 } 151 .width(StyleConstants.PERCENTAGE_100).height(StyleConstants.PERCENTAGE_100) 152 } 153 } 154 .width(StyleConstants.PERCENTAGE_100) 155 .height(StyleConstants.PERCENTAGE_100) 156 } 157 158 aboutToAppear(): void { 159 LogUtil.info(this.TAG, "aboutToAppear") 160 let isContinue = AppStorage.Get<boolean>('IsContinue') 161 LogUtil.info(this.TAG, "aboutToAppear, isContinue : " + isContinue) 162 if (isContinue) { 163 this.sectionStatus = AppStorage.Get('Section')!; 164 } 165 // continue from phone 166 let continueFromPhone = AppStorage.Get<boolean>('ContinueFromPhone') 167 LogUtil.info(this.TAG, "aboutToAppear, continueFromPhone : " + continueFromPhone) 168 if (continueFromPhone) { 169 this.sectionStatus = 1 170 } 171 // save continue data 172 AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus) 173 LogUtil.info(this.TAG, "aboutToAppear, set continue section success") 174 } 175 176 aboutToDisappear(): void { 177 LogUtil.info(this.TAG, "aboutToDisappear") 178 } 179}