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