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