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 */ 15import router from '@ohos.router' 16import { MARKS } from '../model/Const' 17import DistributedObjectModel from '../model/DistributedObjectModel' 18import Note from '../model/Note' 19import TitleBar from '../common/TitleBar' 20 21@Entry 22@Component 23struct Edit { 24 @State note: Note = router.getParams()['note'] 25 private isAdd: boolean = router.getParams()['isAdd'] 26 @State imageShow: boolean = false 27 @StorageLink('objectModel') globalObject: DistributedObjectModel = new DistributedObjectModel() 28 29 build() { 30 Column() { 31 TitleBar({ title: this.note.title === '' ? $r('app.string.add_note') : this.note.title }) 32 Column() { 33 Row() { 34 Image(this.note.mark >= 0 ? MARKS[this.note.mark] : $r('app.media.mark')) 35 .width(30) 36 .aspectRatio(1) 37 .margin({ left: 16, top: 16 }) 38 .objectFit(ImageFit.Contain) 39 .alignSelf(ItemAlign.Start) 40 Select([{ value: ' ', icon: MARKS[0] }, 41 { value: ' ', icon: MARKS[1] }, 42 { value: ' ', icon: MARKS[2] }, 43 { value: ' ', icon: MARKS[3] }, 44 { value: ' ', icon: MARKS[4] }]) 45 .selected(this.note.mark) 46 .margin({ top: 5 }) 47 .onSelect((index: number) => { 48 this.note.mark = index 49 }) 50 } 51 .width('100%') 52 53 TextInput({ placeholder: 'input the title', text: this.note.title }) 54 .key('titleInput') 55 .placeholderColor(Color.Gray) 56 .fontSize(30) 57 .margin({ left: 15, right: 15, top: 15 }) 58 .height(60) 59 .backgroundColor(Color.White) 60 .onChange((value: string) => { 61 this.note.title = value 62 }) 63 TextArea({ placeholder: 'input the content', text: this.note.content }) 64 .key('contentInput') 65 .placeholderColor(Color.Gray) 66 .backgroundColor(Color.White) 67 .fontSize(30) 68 .height('35%') 69 .margin({ left: 16, right: 16, top: 16 }) 70 .textAlign(TextAlign.Start) 71 .onChange((value: string) => { 72 this.note.content = value 73 }) 74 75 Button() { 76 Text($r('app.string.save')) 77 .fontColor(Color.White) 78 .fontSize(17) 79 } 80 .key('saveNote') 81 .backgroundColor('#0D9FFB') 82 .height(50) 83 .width(200) 84 .margin({ top: 20 }) 85 .onClick(() => { 86 if (!this.isAdd) { 87 let index = router.getParams()['index'] 88 this.globalObject.update(index, this.note.title, this.note.content, this.note.mark) 89 } else { 90 this.globalObject.add(this.note.title, this.note.content, this.note.mark) 91 } 92 router.back() 93 }) 94 } 95 } 96 .width('100%') 97 .height('100%') 98 .backgroundColor('#F5F5F5') 99 } 100}