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 DateUtil from '@ohos/utils/src/main/ets/default/baseUtil/DateUtil' 17import RdbStoreUtil from '@ohos/utils/src/main/ets/default/baseUtil/RdbStoreUtil' 18import FolderData from '@ohos/utils/src/main/ets/default/model/databaseModel/FolderData' 19import NoteData from '@ohos/utils/src/main/ets/default/model/databaseModel/NoteData' 20import { 21 TableName, 22 NoteTableColumn, 23 SysDefFolderUuid, 24 Favorite, 25 Delete 26} from '@ohos/utils/src/main/ets/default/model/databaseModel/EnumData' 27import StyleConstants from '@ohos/utils/src/main/ets/default/constants/StyleConstants' 28import { EditContentDialog, DeleteDialog, EditTitleDialog } from './CusDialogComp' 29import FolderUtil from '@ohos/utils/src/main/ets/default/baseUtil/FolderUtil' 30import NoteUtil from '@ohos/utils/src/main/ets/default/baseUtil/NoteUtil' 31import prompt from '@system.prompt' 32import util from '@ohos.util' 33import { LogUtil } from '@ohos/utils/src/main/ets/default/baseUtil/LogUtil' 34import OperationUtils from '@ohos/utils/src/main/ets/default/baseUtil/OperationUtils' 35import mediaquery from '@ohos.mediaquery' 36import inputMethod from '@ohos.inputMethod'; 37import { folderTextMap } from '@ohos/utils/src/main/ets/default/model/NoteBaseData' 38import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; 39 40const TAG = "NoteContentComp" 41 42var timeId: number 43 44// Note content component 45let inSetValue = AppStorage.Link('inSetValue') 46 47@Component 48export struct NoteContentComp { 49 @Consume('SelectedNoteData') selectedNoteData: NoteData 50 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 51 @Consume('SelectedFolderData') selectedFolderData: FolderData 52 @Consume('RefreshFlag') refreshFlag: number 53 @Consume('EditModel') editModel: boolean 54 @Consume('SectionStatus') sectionStatus: number 55 @Consume('LastSectionStatus') lastSectionStatus: number 56 @Consume('Issave') issave: number 57 @Consume('Search') search: boolean 58 @StorageLink('dpi') dpi: number = 240 59 controllerShow: WebviewController 60 private editContentFlag = false 61 @State uri1: string = "" 62 private context = getContext(this) 63 @StorageLink('ScrollTopPercent') scrollTopPercent: number = 0.0 64 @StorageLink('isUpdate') isUpdate: boolean = false 65 @StorageLink('refreshCurrentNote') @Watch('isDataChange') refreshCurrentNote: boolean = false 66 @Consume('AsideWidth') asideWidth: number 67 68 isDataChange() { 69 if (!this.refreshCurrentNote) { 70 return 71 } 72 this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')") 73 this.refreshCurrentNote = false 74 } 75 76 storeScrollTop(scrollTop: number) { 77 if (scrollTop < 0) { 78 return 79 } 80 AppStorage.SetOrCreate<number>('ScrollTopPercent', scrollTop / this.controllerShow.getPageHeight()) 81 } 82 83 restoreScrollTop() { 84 if (!AppStorage.Has('remoteScrollTopPercent')) { 85 return 86 } 87 var scrollTopPercent = AppStorage.Get<number>('remoteScrollTopPercent') 88 if (scrollTopPercent < 0) { 89 return 90 } 91 this.controllerShow.runJavaScript( 92 'document.documentElement.scrollTop = ' + this.controllerShow.getPageHeight() * scrollTopPercent 93 ) 94 } 95 96 restoreFocus() { 97 if (!AppStorage.Has('isRemoteFocusOnSearch')) { 98 return 99 } 100 let isRemoteFocusOnSearch = AppStorage.Get<boolean>('isRemoteFocusOnSearch') 101 if (isRemoteFocusOnSearch) { 102 focusControl.requestFocus('searchInput') 103 } 104 AppStorage.Delete('isRemoteFocusOnSearch') 105 } 106 107 noteContent = { 108 callbackhtml: (html) => { 109 LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid) 110 this.selectedNoteData.content_text = html 111 this.selectedNoteData.modified_time = new Date().getTime() 112 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 113 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 114 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 115 LogUtil.info(TAG, 'update note success:' + this.selectedNoteData.uuid) 116 // save continue data 117 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 118 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 119 LogUtil.info(TAG, "callbackhtml, set continue note success") 120 return "AceString" 121 }, 122 callbackImagePath: (imgName) => { 123 // updata note image 124 LogUtil.info(TAG, 'note imgName is:' + imgName) 125 this.selectedNoteData.content_img = imgName 126 }, 127 128 callbackhtmlSave: (html) => { 129 LogUtil.info(TAG, 'note uuid is:' + this.selectedNoteData.uuid) 130 this.selectedNoteData.content_text = html 131 this.selectedNoteData.modified_time = new Date().getTime() 132 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 133 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 134 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 135 LogUtil.info(TAG, 'update note success:' + this.selectedNoteData.uuid) 136 this.sectionStatus = this.lastSectionStatus 137 this.sectionStatus = mediaquery.matchMediaSync('(width < 2000)').matches ? 2 : 3 138 // save continue data 139 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 140 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 141 AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus) 142 LogUtil.info(TAG, "callbackhtmlSave, set continue note and section success") 143 return "AceString" 144 }, 145 146 callbackScheduledSave: (html) => { 147 LogUtil.info(TAG, 'callbackScheduledSave') 148 if (this.selectedNoteData.content_text == html) { 149 LogUtil.info(TAG, 'callbackScheduledSave the same value return') 150 return; 151 } 152 this.selectedNoteData.content_text = html 153 this.selectedNoteData.modified_time = new Date().getTime() 154 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 155 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 156 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 157 LogUtil.info(TAG, 'callbackScheduledSave, update note success:' + this.selectedNoteData.uuid) 158 // save continue data 159 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 160 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 161 LogUtil.info(TAG, 'callbackScheduledSave, set continue note success') 162 }, 163 164 callbackPasteImage: (html) => { 165 if (html) { 166 LogUtil.info(TAG, 'paste info' + html) 167 let realHtml = "" 168 let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/ 169 if (html && html.indexOf("base64") > 0) { 170 LogUtil.info(TAG, " getSrcFromHtml, src[1] : " + html) 171 let imgData = html.split(',')[1]; 172 let imgType = 'png' 173 if (html.indexOf("jpeg") > 0) { 174 imgType = 'jpg' 175 } else if (html.indexOf("gif") > 0) { 176 imgType = 'gif' 177 } 178 let filePath = "" 179 if (base64regex.test(imgData)) { 180 let base64 = new util.Base64() 181 let decodeArr = base64.decodeSync(imgData) 182 filePath = OperationUtils.saveImageData(decodeArr, imgType) 183 } else { 184 filePath = OperationUtils.saveImage(imgData, imgType) 185 } 186 realHtml = "file://" + filePath 187 } 188 LogUtil.info(TAG, 'paste info11-' + realHtml) 189 this.controllerShow.runJavaScript("javascript:RICH_EDITOR.insertImageHtml('" + realHtml + "')") 190 LogUtil.info(TAG, 'paste info11--' + realHtml) 191 } else { 192 LogUtil.info(TAG, 'paste info22225') 193 } 194 }, 195 callbackGetSize: (fontSize) => { 196 if (fontSize === 16) { 197 this.selectedNoteData.slider_value = 0 198 } else if (fontSize === 18) { 199 this.selectedNoteData.slider_value = 4 200 } else if (fontSize === 24) { 201 this.selectedNoteData.slider_value = 8 202 } else if (fontSize === 32) { 203 this.selectedNoteData.slider_value = 12 204 } else if (fontSize === 48) { 205 this.selectedNoteData.slider_value = 16 206 } 207 } 208 } 209 210 build() { 211 Stack({ alignContent: Alignment.Bottom }) { 212 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.NoWrap, 213 alignItems: ItemAlign.Start, alignContent: FlexAlign.SpaceAround }) { 214 Column() { 215 ToolBarComp({ controllerShow: this.controllerShow }) 216 } 217 .margin({ left: 24, right: 24 }) 218 219 Column() { 220 NoteContentOverViewComp({ controllerShow: this.controllerShow }) 221 Text(this.refreshFlag.toString()).visibility(Visibility.None) 222 Text(this.AllNoteArray.length.toString()).visibility(Visibility.None) // 用于强制刷新使用 223 224 Web({ src: $rawfile('editor.html'), controller: this.controllerShow }) 225 .javaScriptAccess(true) 226 .javaScriptProxy({ 227 object: this.noteContent, 228 name: "callBackToApp", // html--> name.method 229 methodList: ["callbackhtml", "callbackhtmlSave", "callbackScheduledSave", "callbackGetSize", "callbackPasteImage", "callbackImagePath"], 230 controller: this.controllerShow 231 }) 232 .enabled(this.sectionStatus !== 1 ? false : true) 233 .onPageEnd((e) => { 234 if (this.dpi <= 240) { 235 this.controllerShow.runJavaScript("changeSizeToRk()") 236 } else if (this.dpi <= 320 && this.dpi > 240) { 237 this.controllerShow.runJavaScript("changeSizeToPhone()") 238 } else { 239 this.controllerShow.runJavaScript("changeSizeToTablet()") 240 } 241 if (AppStorage.Get('breakPoint') !== 'sm') { 242 this.controllerShow.runJavaScript("hiddenButton()") 243 } 244 LogUtil.info(TAG, "finish loadurl") 245 if (this.selectedNoteData) { 246 let self = this 247 this.controllerShow.runJavaScript( 248 "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')", 249 () => { 250 // wait for the image in the note to load 251 setTimeout(function () { 252 self.restoreScrollTop() 253 self.restoreFocus() 254 }, 100) 255 } 256 ) 257 } 258 // 初次加载为为小屏预览模式 259 if (this.sectionStatus != 1) { 260 this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)") 261 } 262 }) 263 .imageAccess(true) 264 .onlineImageAccess(true) 265 .fileAccess(true) 266 .domStorageAccess(true) 267 .zoomAccess(false) 268 .height('88%') 269 .width('100%') 270 .onScroll((event) => { 271 this.storeScrollTop(event.yOffset) 272 }) 273 } 274 .margin({ left: 24, right: 24 }) 275 // .width(StyleConstants.PERCENTAGE_100) 276 .enabled(this.selectedNoteData && this.selectedNoteData.is_deleted == Delete.Yes ? false : true) 277 .onClick(() => { 278 this.issave = 0 279 LogUtil.info(TAG, "editModel : " + this.editModel + ", sectionStatus : " + this.sectionStatus) 280 let isContinue = AppStorage.Get<boolean>('IsContinue') 281 LogUtil.info(TAG, "isContinue : " + isContinue) 282 // 点击第三屏进入全屏编辑模式 283 if (this.sectionStatus != 1 || isContinue) { 284 this.asideWidth = 0 285 this.lastSectionStatus = this.sectionStatus 286 this.sectionStatus = 1 287 this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(true)") 288 // 添加定时器:3s自动保存 289 if (timeId) { 290 clearInterval(timeId) 291 } 292 timeId = setInterval(() => { 293 this.controllerShow.runJavaScript("scheduledSaveContent()") 294 }, 3000) 295 LogUtil.info(TAG, "setInterval timeId : " + timeId) 296 // save continue data 297 AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus) 298 LogUtil.info(TAG, "set continue section success") 299 this.editModel = !this.editModel 300 AppStorage.SetOrCreate<boolean>('IsContinue', false) 301 } 302 }) 303 } 304 .id(this.isUpdate + '') 305 .height(StyleConstants.PERCENTAGE_100) 306 .visibility(FolderUtil.getNoteCount(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) == 0 ? Visibility.Hidden : Visibility.Visible) 307 308 Column() { 309 } 310 .height("100%") 311 .width("100%") 312 .backgroundColor("#18181A") 313 .opacity(0.1) 314 .visibility(this.search ? Visibility.Visible : Visibility.Hidden) 315 } 316 .height(StyleConstants.PERCENTAGE_100) 317 .width(StyleConstants.PERCENTAGE_100) 318 } 319 320 aboutToAppear(): void { 321 LogUtil.info(TAG, "aboutToAppear") 322 } 323 324 aboutToDisappear(): void { 325 clearInterval(timeId) 326 LogUtil.info(TAG, "aboutToDisappear") 327 } 328} 329 330@Component 331export struct NoteContentOverViewComp { 332 @Consume('SelectedNoteData') selectedNoteData: NoteData 333 @StorageLink('AllFolderArray') @Watch('getArray') AllFolderArray: FolderData[] = [] 334 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 335 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 336 @Consume('SelectedFolderData') selectedFolderData: FolderData 337 @Consume('EditModel') editModel: boolean 338 @Consume('SectionStatus') sectionStatus: number 339 @Consume('RefreshFlag') refreshFlag: number 340 @StorageLink('isUpdate') isUpdate: boolean = false 341 NoteDataMoveArray: FolderData[] 342 controllerShow: WebviewController 343 editTitleDialogCtl: CustomDialogController = new CustomDialogController({ 344 builder: EditTitleDialog({ confirm: this.confirm.bind(this) }), 345 alignment: DialogAlignment.Center, 346 autoCancel: false, 347 customStyle: true, 348 }) 349 350 getArray() { 351 this.NoteDataMoveArray = this.AllFolderArray.slice(2, this.AllFolderArray.length); 352 if (this.AllFolderArray[1] === undefined || this.AllFolderArray[1] === null) { 353 LogUtil.info(TAG, "this AllFolderArray[1] undefined") 354 return 355 } 356 this.NoteDataMoveArray.push(this.AllFolderArray[1]); 357 } 358 359 aboutToAppear() { 360 this.NoteDataMoveArray = this.AllFolderArray.slice(2, this.AllFolderArray.length); 361 if (this.AllFolderArray[1] === undefined || this.AllFolderArray[1] === null) { 362 LogUtil.info(TAG, "this AllFolderArray[1] undefined") 363 return 364 } 365 this.NoteDataMoveArray.push(this.AllFolderArray[1]); 366 } 367 368 aboutToDisappear() { 369 this.editTitleDialogCtl = null 370 } 371 372 confirm(newTitle: string) { 373 this.selectedNoteData.title = newTitle 374 this.selectedNoteData.modified_time = new Date().getTime() 375 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 376 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 377 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 378 NoteUtil.refreshAll() 379 } 380 381 @Builder MenuBuilder() { 382 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 383 List() { 384 if (this.NoteDataMoveArray !== undefined && this.NoteDataMoveArray !== null && this.NoteDataMoveArray !== []) { 385 ForEach(this.NoteDataMoveArray, (item) => { 386 ListItem() { 387 NoteDataMoveItemCompTablet({ folderItem: item, uuid: this.selectedNoteData.folder_uuid }) 388 } 389 .onClick(() => { 390 this.selectedNoteData.folder_uuid = item.uuid 391 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 392 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 393 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 394 if (this.sectionStatus != 1) { 395 this.selectedNoteData = NoteUtil.getFirstNoteData(this.AllNoteArray, this.selectedFolderData.uuid) 396 this.controllerShow.runJavaScript( 397 "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" 398 ) 399 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 400 } else { 401 this.selectedFolderData = FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), item.uuid) 402 } 403 // save continue data 404 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 405 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 406 LogUtil.info(TAG, "NoteContentOverViewComp, MenuBuilder, set continue note success") 407 NoteUtil.refreshAll() 408 }) 409 }, noteItem => noteItem.uuid) 410 } 411 }.listDirection(Axis.Vertical) 412 .edgeEffect(EdgeEffect.Spring) 413 .height(this.AllFolderArray.length > 12 ? 504 : (this.AllFolderArray.length - 3) * 56) 414 } 415 .width(148) 416 .backgroundColor($r("app.color.color_fffffB")) 417 .padding({ left: 24, right: 24 }) 418 } 419 420 build() { 421 if (this.selectedNoteData) { 422 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.NoWrap, 423 justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 424 Row() { 425 Text(this.selectedNoteData.title) 426 .id(this.isUpdate + '') 427 .fontSize(30) 428 .margin({ left: 0, right: 24 }) 429 .onClick(() => { 430 clearInterval(timeId) 431 this.editTitleDialogCtl.open() 432 // save continue data 433 AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus) 434 LogUtil.info(TAG, "NoteContentComp, set continue section success") 435 }) 436 }.height(40) 437 .width(StyleConstants.PERCENTAGE_100) 438 439 Row() { 440 Text(DateUtil.formateDateForNoteContent(new Date(this.selectedNoteData.modified_time))) 441 .id(this.isUpdate + '') 442 .fontSize(12) 443 .padding({ top: 4, bottom: 4 }) 444 .fontColor($r("app.color.modified_time_font_color")) 445 .margin({ left: 0 }) 446 Row() { 447 Text(FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid)) == 448 folderTextMap["sys_def_myFavorites_uuid"] ? folderTextMap["sys_def_unClassified_uuid"] : 449 FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid))) 450 .id(this.isUpdate + '') 451 .fontSize(12) 452 .fontColor($r("app.color.list_modified_time_font_color")) 453 .padding({ top: 1 }) 454 Image($r('app.media.triangle')) 455 .width(6) 456 .height(12) 457 .margin({ left: 4 }) 458 } 459 .id(this.isUpdate + '') 460 .padding({ left: 8, right: 8, top: 4, bottom: 4 }) 461 .margin({ left: 8 }) 462 .borderRadius(16) 463 .backgroundColor(NoteUtil.getNoteBgColor(AppStorage.Get('AllFolderArray'), this.selectedNoteData.folder_uuid, SysDefFolderUuid.AllNotes, false)) 464 .bindMenu(this.MenuBuilder) 465 }.alignItems(VerticalAlign.Top).height(40).width(StyleConstants.PERCENTAGE_100) 466 } 467 .opacity(this.selectedNoteData.is_deleted == Delete.Yes ? 0.4 : 1) 468 .width(StyleConstants.PERCENTAGE_100) 469 .height(80) 470 } 471 } 472} 473 474@Component 475export struct ToolBarComp { 476 @Consume('SelectedNoteData') selectedNoteData: NoteData 477 @Consume('RefreshFlag') refreshFlag: number 478 @Consume('SectionStatus') sectionStatus: number 479 @Consume('LastSectionStatus') lastSectionStatus: number 480 @Consume('SelectedFolderData') selectedFolderData: FolderData 481 @Consume('ChooseNote') chooseNote: boolean 482 @Consume('PortraitModel') portraitModel: boolean 483 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 484 @Consume('EditModel') editModel: boolean 485 @Consume('Issave') issave: number 486 controllerShow: WebviewController 487 private context = getContext(this) 488 noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({ 489 builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this) }), 490 alignment: DialogAlignment.Center, 491 autoCancel: false, 492 customStyle: true, 493 }) 494 @Consume('AsideWidth') asideWidth: number 495 496 aboutToDisappear() { 497 this.noteDataDeleteDialogCtl = null 498 this.editContentDialogCtl = null 499 } 500 501 onDeleteConfirm() { 502 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 503 this.selectedNoteData.is_deleted = Delete.Yes 504 this.selectedNoteData.deleted_time = new Date().getTime() 505 // update note to db 506 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 507 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 508 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 509 } else { 510 NoteUtil.removeNoteData(this.AllNoteArray, this.selectedNoteData.uuid) 511 // delete note from db 512 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 513 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 514 RdbStoreUtil.delete(predicates_note, null) 515 } 516 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 517 this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) 518 this.controllerShow.runJavaScript("RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')") 519 this.chooseNote = false 520 // save continue data 521 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 522 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 523 LogUtil.info(TAG, "NoteContentOverViewComp, set continue note success") 524 AppStorage.SetOrCreate('isUpdate', true) 525 } 526 527 editContentDialogCtl: CustomDialogController = new CustomDialogController({ 528 builder: EditContentDialog({ confirm: this.confirm.bind(this) }), 529 alignment: DialogAlignment.Bottom, 530 autoCancel: true, 531 customStyle: true, 532 }) 533 534 confirm(excuteJs: string) { 535 this.controllerShow.runJavaScript(excuteJs) 536 } 537 538 build() { 539 Flex({ direction: FlexDirection.Row, wrap: FlexWrap.NoWrap, 540 justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 541 Image(this.sectionStatus == 1 ? $r('app.media.narrow') : $r('app.media.zoom')) 542 .height(24) 543 .width(24) 544 .onClick(() => { 545 if (this.sectionStatus != 1) { 546 this.lastSectionStatus = this.sectionStatus 547 this.sectionStatus = 1 548 this.asideWidth = 0 549 this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(true)") 550 } else { 551 if (this.lastSectionStatus != undefined) { 552 this.asideWidth = 200 553 // 切换为小屏预览模式 554 this.controllerShow.runJavaScript("RICH_EDITOR.setInputEnabled(false)") 555 this.sectionStatus = this.lastSectionStatus 556 // 退出全屏时存库 557 LogUtil.info(TAG, "close note" + this.selectedNoteData.uuid) 558 this.controllerShow.runJavaScript("saveHtmlContent()") 559 //退出键盘 560 // @ts-ignore 561 inputMethod.getController().stopInputSession(); 562 // 清除定时器 563 if (timeId != undefined) { 564 LogUtil.info(TAG, "zoom, clearInterval timeId : " + timeId) 565 clearInterval(timeId) 566 } 567 } else { 568 this.sectionStatus = 3 569 } 570 } 571 this.editModel = !this.editModel 572 // save continue data 573 AppStorage.SetOrCreate<number>('ContinueSection', this.sectionStatus) 574 LogUtil.info(TAG, "ToolBarComp, set continue section success") 575 NoteUtil.refreshAll() 576 }) 577 .visibility(!this.selectedNoteData ? Visibility.None : this.selectedNoteData.is_deleted == Delete.Yes ? Visibility.None : Visibility.Visible) 578 579 if (this.selectedNoteData) { 580 if (this.selectedNoteData.is_deleted == Delete.Yes) { 581 Row({ space: StyleConstants.SPACE_24 }) { 582 Image($r('app.media.delete')) 583 .height(24) 584 .width(24) 585 .onClick(() => { 586 this.noteDataDeleteDialogCtl.open() 587 }) 588 Image($r('app.media.recover')) 589 .height(24) 590 .width(24) 591 .onClick(() => { 592 this.selectedNoteData.is_deleted = Delete.No 593 this.selectedNoteData.deleted_time = 0 594 let context: any = getContext(this) 595 let resource = { 596 bundleName: "com.ohos.note", 597 moduleName: "default", 598 id: $r('app.string.restore').id 599 }; 600 context.resourceManager.getString(resource, (error, value) => { 601 if (error != null) { 602 console.log("error is " + error); 603 } else { 604 prompt.showToast({ message: value, duration: 2000 }); 605 } 606 }); 607 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 608 this.chooseNote = false 609 // update note to db 610 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 611 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 612 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 613 614 this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), this.selectedFolderData.uuid) 615 this.controllerShow.runJavaScript( 616 "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" 617 ) 618 // save continue data 619 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 620 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 621 LogUtil.info(TAG, "recover, set continue note success") 622 NoteUtil.refreshAll() 623 }) 624 }.width(72) 625 } else if (this.editModel == true) { 626 Row({ space: StyleConstants.SPACE_6 }) { 627 Button({ type: ButtonType.Normal, stateEffect: true }) { 628 Image($r('app.media.circle_tick1')) 629 .height(24) 630 .width(24) 631 .onClick(() => { 632 // 清单 633 this.controllerShow.runJavaScript("javascript:RICH_EDITOR.setTodo()") 634 // 退出键盘 635 // @ts-ignore 636 inputMethod.getController().stopInputSession(); 637 }) 638 }.width(42) 639 .height(42) 640 .borderRadius(8) 641 .backgroundColor($r('app.color.color_fffffB')) 642 643 Button({ type: ButtonType.Normal, stateEffect: true }) { 644 Image($r('app.media.styles')) 645 .height(24) 646 .width(24) 647 .onClick(() => { 648 // 退出键盘 649 // @ts-ignore 650 inputMethod.getController().stopInputSession(); 651 this.editContentDialogCtl.open() 652 }) 653 }.width(42) 654 .height(42) 655 .borderRadius(8) 656 .backgroundColor($r('app.color.color_fffffB')) 657 658 Button({ type: ButtonType.Normal, stateEffect: true }) { 659 Image($r('app.media.picture_white')) 660 .height(24) 661 .width(24) 662 .onClick(async () => { 663 let permissionList: Array<string> = [ 664 "ohos.permission.READ_MEDIA", 665 "ohos.permission.WRITE_MEDIA", 666 ] 667 let context: any = getContext(this); 668 let AtManager = abilityAccessCtrl.createAtManager(); 669 // @ts-ignore 670 await AtManager.requestPermissionsFromUser(context, permissionList).then((data) => { 671 LogUtil.info(TAG, 'data permissions : ' + data.permissions) 672 LogUtil.info(TAG, 'data result: ' + data.authResults) 673 let sum = 0 674 for (let i = 0; i < data.authResults.length; i++) { 675 sum += data.authResults[i] 676 } 677 LogUtil.info(TAG, 'request permissions sum: ' + sum) 678 }).catch((err) => { 679 LogUtil.warn(TAG, 'failed to requestPermissionsFromUser : ' + err.code); 680 }) 681 // 退出键盘 682 // @ts-ignore 683 inputMethod.getController().stopInputSession(); 684 LogUtil.info(TAG, 'startAbility start') 685 await globalThis.noteContext.startAbilityForResult({ 686 parameters: { uri: "singleselect" }, 687 bundleName: "com.ohos.photos", 688 abilityName: "com.ohos.photos.MainAbility", 689 }) 690 .then(v => { 691 let want = v['want']; 692 if (want != null && want != undefined) { 693 let param = want['parameters']; 694 let imageUri = "" 695 if (param != null && param != undefined) { 696 let uri = param['select-item-list']; 697 imageUri = uri; 698 } 699 // 拷贝 700 if (imageUri != null && imageUri != "") { 701 OperationUtils.copy(imageUri).then((uriPath) => { 702 var path = "file://" + uriPath 703 LogUtil.info(TAG, 'image uri is:' + path) 704 this.controllerShow.runJavaScript( 705 "javascript:RICH_EDITOR.insertImage('" + path + "')" 706 ) 707 this.issave = 1 708 // 保存笔记信息到数据库 709 this.controllerShow.runJavaScript("getHtmlContent()") 710 }) 711 } 712 } 713 NoteUtil.refreshAll() 714 }); 715 }) 716 }.width(42) 717 .height(42) 718 .borderRadius(8) 719 .backgroundColor($r('app.color.color_fffffB')) 720 721 Button({ type: ButtonType.Normal, stateEffect: true }) { 722 Image($r('app.media.undo')) 723 .height(24) 724 .width(24) 725 .onClick(() => { 726 // 退出键盘 727 // @ts-ignore 728 inputMethod.getController().stopInputSession(); 729 this.controllerShow.runJavaScript("RICH_EDITOR.undo()") 730 }) 731 }.width(42) 732 .height(42) 733 .borderRadius(8) 734 .backgroundColor($r('app.color.color_fffffB')) 735 736 Button({ type: ButtonType.Normal, stateEffect: true }) { 737 Image($r('app.media.todo')) 738 .height(24) 739 .width(24) 740 .onClick(() => { 741 // 退出键盘 742 // @ts-ignore 743 inputMethod.getController().stopInputSession(); 744 this.controllerShow.runJavaScript("RICH_EDITOR.redo()") 745 }) 746 }.width(42) 747 .height(42) 748 .borderRadius(8) 749 .backgroundColor($r('app.color.color_fffffB')) 750 751 752 Button({ type: ButtonType.Normal, stateEffect: true }) { 753 Image($r('app.media.tick_thin')) 754 .height(24) 755 .width(24) 756 .fillColor(this.issave == 0 ? Color.Black : Color.Grey) 757 .onClick(() => { 758 // 保存笔记信息到数据库 759 this.controllerShow.runJavaScript("getHtmlContent()") 760 if (this.selectedNoteData.title == "标题" && this.selectedNoteData.content_text == "") { 761 LogUtil.info(TAG, "note is empty,save note failed") 762 } 763 this.issave = 1 764 }) 765 }.width(42) 766 .height(42) 767 .borderRadius(8) 768 .backgroundColor($r('app.color.color_fffffB')) 769 }.width(274) 770 } else { 771 Row({ space: StyleConstants.SPACE_24 }) { 772 Image(this.selectedNoteData.is_favorite == Favorite.Yes ? $r('app.media.favorite') : $r('app.media.favorite_cancel')) 773 .height(24) 774 .width(24) 775 .onClick(() => { 776 this.selectedNoteData.is_favorite = (this.selectedNoteData.is_favorite == Favorite.Yes ? Favorite.No : Favorite.Yes) 777 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 778 // update note to db 779 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 780 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData.uuid) 781 RdbStoreUtil.update(this.selectedNoteData.toNoteObject(), predicates_note, null) 782 if (this.selectedFolderData.uuid === SysDefFolderUuid.MyFavorites) { 783 this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites) 784 this.controllerShow.runJavaScript( 785 "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" 786 ) 787 // save continue data 788 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 789 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 790 LogUtil.info(TAG, "ToolBarComp, set continue note success") 791 } 792 NoteUtil.refreshAll() 793 }) 794 Image($r('app.media.delete')) 795 .height(24) 796 .width(24) 797 .onClick(() => { 798 this.noteDataDeleteDialogCtl.open() 799 }) 800 }.width(72) 801 } 802 } 803 } 804 .width(StyleConstants.PERCENTAGE_100) 805 .height(80) 806 } 807} 808 809@Component 810struct NoteDataMoveItemCompTablet { 811 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 812 @StorageLink('AllFolderArray') AllFolderArray: FolderData[] = [] 813 @StorageLink('isUpdate') isUpdate: boolean = false 814 folderItem: FolderData 815 uuid: String 816 817 build() { 818 Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) { 819 Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap }) { 820 Image(FolderUtil.getFolderIcon(this.folderItem.uuid)) 821 .id(this.isUpdate + '') 822 .objectFit(ImageFit.Fill) 823 .width(24) 824 .height(24) 825 .flexShrink(0) 826 .fillColor(FolderUtil.getFolderIconColor(this.AllFolderArray, this.folderItem.uuid, this.folderItem.uuid == this.uuid)) 827 } 828 .width(24) 829 830 Column() { 831 Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween }) { 832 Text(FolderUtil.getFolderText(this.folderItem)) 833 .id(this.isUpdate + '') 834 .padding({ top: 3 }) 835 .fontSize(16) 836 .fontColor(FolderUtil.getFolderIconColor(this.AllFolderArray, this.folderItem.uuid == this.uuid ? this.folderItem.uuid : '', this.folderItem.uuid == this.uuid)) 837 .textAlign(TextAlign.Center) 838 .maxLines(1) 839 .textOverflow({ overflow: TextOverflow.Ellipsis }) 840 .flexShrink(1) 841 } 842 .width('100%') 843 .height(55) 844 845 if (this.folderItem.uuid != SysDefFolderUuid.UnClassified) { 846 Divider() 847 .color($r("app.color.divider_color_e4e4e4")) 848 .strokeWidth(1) 849 } 850 } 851 .padding({ left: 16 }) 852 } 853 .id(this.isUpdate + '') 854 .width('100%') 855 .height(56) 856 .visibility(FolderUtil.isFolderMoveIn(this.folderItem) ? Visibility.Visible : Visibility.None) 857 } 858} 859