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