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 } 349} 350 351@Component 352export struct NoteContentOverViewComp { 353 @Consume('SelectedNoteData') selectedNoteData: NoteData 354 @StorageLink('AllFolderArray') AllFolderArray: FolderData[] = [] 355 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 356 @StorageLink('isUpdate') isUpdate: boolean = false 357 NoteDataMoveArray: FolderData[] 358 editTitleDialogCtl: CustomDialogController = new CustomDialogController({ 359 builder: EditTitleDialog({ confirm: this.confirm.bind(this) }), 360 alignment: DialogAlignment.Center, 361 autoCancel: false, 362 customStyle: true, 363 }) 364 365 aboutToAppear() { 366 this.NoteDataMoveArray = this.AllFolderArray.slice(2, this.AllFolderArray.length); 367 if (this.AllFolderArray[1] === undefined || this.AllFolderArray[1] === null) { 368 LogUtil.info(TAG, "this AllFolderArray[1] undefined") 369 return 370 } 371 this.NoteDataMoveArray.push(this.AllFolderArray[1]); 372 } 373 374 confirm(newTitle: string) { 375 this.selectedNoteData.title = newTitle 376 this.selectedNoteData.modified_time = new Date().getTime() 377 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 378 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 379 RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) 380 // save continue data 381 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 382 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 383 LogUtil.info(TAG, 'NoteContentOverViewComp, MenuBuilder, set continue note success') 384 NoteUtil.refreshAll() 385 } 386 387 @Builder MenuBuilder() { 388 Column() { 389 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignItems: ItemAlign.Center }) { 390 List() { 391 if (this.NoteDataMoveArray !== undefined && this.NoteDataMoveArray !== null && this.NoteDataMoveArray !== []) { 392 ForEach(this.NoteDataMoveArray, (item) => { 393 ListItem() { 394 NoteDataMoveItemCompMenu({ folderItem: item, uuid: this.selectedNoteData?.folder_uuid }) 395 } 396 .onClick(() => { 397 this.selectedNoteData.folder_uuid = item.uuid 398 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 399 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 400 RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) 401 // save continue data 402 let continueNote: string = JSON.stringify(this.selectedNoteData?.toNoteObject()) 403 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 404 LogUtil.info(TAG, 'MenuBuilder, set continue note success') 405 NoteUtil.refreshAll() 406 }) 407 }, noteItem => noteItem?.uuid) 408 } 409 } 410 .margin({ top: 4, bottom: 4 }) 411 .listDirection(Axis.Vertical) 412 .edgeEffect(EdgeEffect.Spring) 413 .height(this.AllFolderArray.length > 12 ? 504 : (this.AllFolderArray.length - 3) * 56) 414 } 415 .backgroundColor($r('app.color.folder_color_ffffff')) 416 .width(148) 417 .padding({ left: 24, right: 24 }) 418 } 419 } 420 421 build() { 422 if (this.selectedNoteData) { 423 Flex({ direction: FlexDirection.Column, wrap: FlexWrap.NoWrap, 424 justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 425 Row() { 426 Text(this.selectedNoteData?.title) 427 .id(this.isUpdate + '') 428 .fontSize(30).fontWeight(FontWeight.Medium) 429 .onClick(() => { 430 clearInterval(time_id) 431 this.editTitleDialogCtl.open() 432 }) 433 }.height(40) 434 .width(StyleConstants.PERCENTAGE_100) 435 436 Row() { 437 Text(DateUtil.formateDateForNoteContent(new Date(this.selectedNoteData?.modified_time))) 438 .id(this.isUpdate + '') 439 .fontSize(12) 440 .padding({ top: 4, bottom: 4 }) 441 .fontColor($r("app.color.modified_time_font_color")) 442 Row() { 443 Text(FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData?.folder_uuid)) == 444 folderTextMap["sys_def_myFavorites_uuid"] ? folderTextMap["sys_def_unClassified_uuid"] : 445 FolderUtil.getFolderText(FolderUtil.getFolderData(AppStorage.Get('AllFolderArray'), this.selectedNoteData?.folder_uuid))) 446 .id(this.isUpdate + '') 447 .fontColor($r('app.color.folder_color_99182431')) 448 .fontSize(12) 449 Image($r('app.media.triangle')) 450 .width(6) 451 .height(12) 452 .margin({ left: 4 }) 453 } 454 .id(this.isUpdate + '') 455 .padding({ left: 8, right: 8, top: 4, bottom: 4 }) 456 .margin({ left: 8 }) 457 .borderRadius(16) 458 .backgroundColor(NoteUtil.getNoteBgColor(AppStorage.Get('AllFolderArray'), this.selectedNoteData?.folder_uuid, SysDefFolderUuid.AllNotes, false)) 459 .bindMenu(this.MenuBuilder) 460 }.alignItems(VerticalAlign.Top).height(40).width(StyleConstants.PERCENTAGE_100) 461 } 462 .opacity(this.selectedNoteData?.is_deleted == Delete.Yes ? 0.4 : 1) 463 .width(StyleConstants.PERCENTAGE_100) 464 .height(82) 465 } 466 } 467} 468 469@Component 470export struct ToolBarComp { 471 @Consume('SelectedNoteData') selectedNoteData: NoteData 472 @Consume('SelectedFolderData') selectedFolderData: FolderData 473 @Consume('EditModel') editModel: boolean 474 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 475 controllerShow: WebviewController 476 477 onDeleteConfirm() { 478 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 479 this.selectedNoteData.is_deleted = Delete.Yes 480 this.selectedNoteData.deleted_time = new Date().getTime() 481 // update note to db 482 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 483 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 484 RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) 485 routePage() 486 } else { 487 NoteUtil.removeNoteData(this.AllNoteArray, this.selectedNoteData?.uuid) 488 // delete note from db 489 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 490 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 491 RdbStoreUtil.delete(predicates_note, null) 492 routePage() 493 } 494 AppStorage.SetOrCreate('isUpdate', true) 495 } 496 497 noteDataDeleteDialogCtl: CustomDialogController = new CustomDialogController({ 498 builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }), 499 alignment: DialogAlignment.Bottom, 500 autoCancel: false, 501 customStyle: true, 502 }) 503 504 build() { 505 Flex({ direction: FlexDirection.Row, wrap: FlexWrap.NoWrap, 506 justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 507 508 Image($r('app.media.back')) 509 .height(24) 510 .width(24) 511 .responseRegion({ width: 54, height: 54 }) 512 .onClick(() => { 513 try { 514 this.controllerShow.runJavaScript("getHtmlContent()") 515 // 清除定时器 516 if (time_id != undefined) { 517 LogUtil.info(TAG, "back, clearInterval time_id : " + time_id) 518 clearInterval(time_id) 519 } 520 setTimeout(() => { 521 LogUtil.info(TAG, "wait save cotext") 522 router.back() 523 }, 50) 524 NoteUtil.refreshAll() 525 } catch (error) { 526 LogUtil.info(TAG, 'back error') 527 } 528 }) 529 530 if (this.editModel == false) { 531 Row({ space: StyleConstants.SPACE_24 }) { 532 Image(this.selectedNoteData?.is_favorite == Favorite.Yes ? $r('app.media.favorite') : $r('app.media.favorite_cancel')) 533 .height(24).width(24) 534 .onClick(() => { 535 try { 536 this.selectedNoteData.is_favorite = (this.selectedNoteData?.is_favorite == Favorite.Yes ? Favorite.No : Favorite.Yes) 537 // update note to db 538 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 539 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 540 RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) 541 if (this.selectedFolderData?.uuid === SysDefFolderUuid.MyFavorites) { 542 this.selectedNoteData = NoteUtil.getFirstNoteData(AppStorage.Get('AllNoteArray'), SysDefFolderUuid.MyFavorites) 543 if (!this.selectedNoteData) { 544 routePage() 545 } 546 this.controllerShow.runJavaScript( 547 "RICH_EDITOR.setHtml('" + this.selectedNoteData.content_text + "')" 548 ) 549 // save continue data 550 let continueNote: string = JSON.stringify(this.selectedNoteData.toNoteObject()) 551 AppStorage.SetOrCreate<string>('ContinueNote', continueNote) 552 LogUtil.info(TAG, "ToolBarComp, set continue note success") 553 } 554 NoteUtil.refreshAll() 555 } catch (error) { 556 LogUtil.info(TAG, 'favorite error') 557 } 558 }) 559 Image($r('app.media.delete')).height(24).width(24) 560 .onClick(() => { 561 this.noteDataDeleteDialogCtl.open() 562 }) 563 }.width(72) 564 .visibility(this.selectedNoteData?.is_deleted == Delete.Yes ? Visibility.None : Visibility.Visible) 565 } else { 566 Row({ space: StyleConstants.SPACE_6 }) { 567 Button({ type: ButtonType.Normal, stateEffect: true }) { 568 Image($r('app.media.undo')).height(24).width(24) 569 .onClick(() => { 570 try { 571 // 退出键盘 572 // @ts-ignore 573 inputMethod.getController().stopInputSession(); 574 this.controllerShow.runJavaScript("javascript:RICH_EDITOR.undo()") 575 } catch (error) { 576 LogUtil.info(TAG, 'undo error') 577 } 578 }) 579 }.width(42) 580 .height(42) 581 .borderRadius(8) 582 .backgroundColor($r('app.color.color_fffffB')) 583 584 Button({ type: ButtonType.Normal, stateEffect: true }) { 585 Image($r('app.media.todo')).height(24).width(24) 586 .onClick(() => { 587 try { 588 // 退出键盘 589 // @ts-ignore 590 inputMethod.getController().stopInputSession(); 591 this.controllerShow.runJavaScript("javascript:RICH_EDITOR.redo()") 592 } catch (error) { 593 LogUtil.info(TAG, 'todo error') 594 } 595 }) 596 }.width(42) 597 .height(42) 598 .borderRadius(8) 599 .backgroundColor($r('app.color.color_fffffB')) 600 601 Button({ type: ButtonType.Normal, stateEffect: true }) { 602 Image($r('app.media.tick_thin')).height(24).width(24) 603 .onClick(() => { 604 try { 605 // 保存笔记信息到数据库 606 this.controllerShow.runJavaScript("getHtmlContent()") 607 this.editModel = false 608 } catch (error) { 609 LogUtil.info(TAG, 'tick_thin error') 610 } 611 }) 612 }.width(42) 613 .height(42) 614 .borderRadius(8) 615 .backgroundColor($r('app.color.color_fffffB')) 616 } 617 .width(130) 618 .visibility(this.selectedNoteData?.is_deleted == Delete.Yes ? Visibility.None : Visibility.Visible) 619 } 620 } 621 .width(StyleConstants.PERCENTAGE_100) 622 .height(40) 623 } 624} 625 626@Component 627export struct DeleteNoteComp { 628 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 629 @StorageLink('AllNoteArray') AllNoteArray: NoteData[] = AppStorage.Link('AllNoteArray') 630 @Consume('SelectedFolderData') selectedFolderData: FolderData 631 @Consume('RefreshFlag') refreshFlag: number 632 @Consume('SelectedNoteData') selectedNoteData: NoteData; 633 noteDataDeleteDialogCtlBottom: CustomDialogController = new CustomDialogController({ 634 builder: DeleteDialog({ onConfirm: this.onDeleteConfirm.bind(this), multiSelect: true }), 635 alignment: DialogAlignment.Bottom, 636 autoCancel: false, 637 customStyle: true, 638 }) 639 640 onDeleteConfirm() { 641 if (this.selectedFolderData.uuid != SysDefFolderUuid.RecentDeletes) { 642 this.selectedNoteData.is_deleted = Delete.Yes 643 this.selectedNoteData.deleted_time = new Date().getTime() 644 // update note to db 645 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 646 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 647 RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) 648 routePage() 649 } else { 650 NoteUtil.removeNoteData(this.AllNoteArray, this.selectedNoteData?.uuid) 651 // delete note from db 652 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 653 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 654 RdbStoreUtil.delete(predicates_note, null) 655 NoteUtil.refreshAll() 656 routePage() 657 } 658 AppStorage.SetOrCreate('isUpdate', false) 659 } 660 661 build() { 662 Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap, justifyContent: FlexAlign.SpaceBetween }) { 663 Column() { 664 Image($r('app.media.delete')) 665 .width(24) 666 .height(24) 667 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 668 .onClick(() => { 669 this.noteDataDeleteDialogCtlBottom.open() 670 }) 671 Text($r("app.string.delete")) 672 .fontSize(10) 673 .fontColor($r('app.color.delete_font_color')) 674 .padding({ top: 5 }) 675 } 676 .height("100%") 677 .width(180) 678 .justifyContent(FlexAlign.Center) 679 .alignItems(HorizontalAlign.Center) 680 681 Column() { 682 Image($r('app.media.recover')) 683 .width(24) 684 .height(24) 685 .responseRegion({ x: -15.0, y: -15.0, width: 54, height: 54 }) 686 .onClick(() => { 687 this.selectedNoteData.is_deleted = Delete.No 688 this.selectedNoteData.deleted_time = 0 689 let context: any = getContext(this) 690 let resource = { 691 bundleName: "com.ohos.note", 692 moduleName: "default", 693 id: $r('app.string.restore').id 694 }; 695 context.resourceManager.getString(resource, (error, value) => { 696 if (error != null) { 697 console.log("error is " + error); 698 } else { 699 prompt.showToast({ message: value, duration: 2000 }); 700 } 701 }); 702 this.refreshFlag = (this.refreshFlag == 0 ? 1 : 0) 703 // update note to db 704 let predicates_note = RdbStoreUtil.getRdbPredicates(TableName.NoteTable) 705 predicates_note.equalTo(NoteTableColumn.Uuid, this.selectedNoteData?.uuid) 706 RdbStoreUtil.update(this.selectedNoteData?.toNoteObject(), predicates_note, null) 707 NoteUtil.refreshAll() 708 }) 709 Text($r("app.string.recover")) 710 .fontSize(10) 711 .fontColor($r('app.color.recover_font_color')) 712 .padding({ top: 5 }) 713 } 714 .height("100%") 715 .width(180) 716 .justifyContent(FlexAlign.Center) 717 .alignItems(HorizontalAlign.Center) 718 } 719 .width(360) 720 .height(56) 721 .visibility(this.selectedNoteData?.is_deleted == Delete.Yes ? 722 Visibility.Visible : Visibility.None) 723 } 724} 725 726@Component 727struct NoteDataMoveItemCompMenu { 728 @StorageLink('CheckedNoteArray') CheckedNoteArray: NoteData[] = [] 729 @StorageLink('AllFolderArray') AllFolderArray: FolderData[] = [] 730 @StorageLink('isUpdate') isUpdate: boolean = false 731 folderItem: FolderData 732 uuid: String 733 734 build() { 735 Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.Center }) { 736 Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap }) { 737 Image(FolderUtil.getFolderIcon(this.folderItem.uuid)) 738 .id(this.isUpdate + '') 739 .objectFit(ImageFit.Fill) 740 .width(24) 741 .height(24) 742 .flexShrink(0) 743 .fillColor(FolderUtil.getFolderIconColor(this.AllFolderArray, this.folderItem.uuid, this.folderItem.uuid == this.uuid)) 744 } 745 .width(24) 746 747 Column() { 748 Flex({ alignItems: ItemAlign.Center, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween }) { 749 Text(FolderUtil.getFolderText(this.folderItem)) 750 .id(this.isUpdate + '') 751 .fontSize(16) 752 .fontColor(FolderUtil.getFolderIconColor(this.AllFolderArray, this.folderItem.uuid == this.uuid ? this.folderItem.uuid : '', this.folderItem.uuid == this.uuid)) 753 .textAlign(TextAlign.Center) 754 .maxLines(1) 755 .textOverflow({ overflow: TextOverflow.Ellipsis }) 756 .flexShrink(1) 757 } 758 .width('100%') 759 .height(55) 760 761 if (this.folderItem.uuid != SysDefFolderUuid.UnClassified) { 762 Divider() 763 .color($r("app.color.divider_color_e4e4e4")) 764 .strokeWidth(1) 765 } 766 767 } 768 .padding({ left: 16 }) 769 } 770 .id(this.isUpdate + '') 771 .width('100%') 772 .height(56) 773 .visibility(FolderUtil.isFolderMoveIn(this.folderItem) ? Visibility.Visible : Visibility.None) 774 } 775} 776