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