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