1/* 2 * Copyright (c) 2021 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 prompt from '@ohos.prompt' 17import dataAbility from '@ohos.data.dataAbility' 18import { BASE_URI, DA_HELPER } from '../model/DaHelperConst' 19import { BookModel } from '../model/BookDataModel' 20 21const TAG = 'DataAbility.Update' 22 23@Entry 24@Component 25struct Update { 26 private book: BookModel = <BookModel> router.getParams()['book'] 27 28 aboutToAppear() { 29 console.info(TAG + ' aboutToAppear') 30 } 31 32 updateBook = () => { 33 let predicates = new dataAbility.DataAbilityPredicates() 34 predicates.equalTo('id', this.book.id) 35 let valuesBucket = { 36 'name': this.book.name, 37 'introduction': this.book.introduction 38 } 39 DA_HELPER.update(BASE_URI, valuesBucket, predicates, (err, num) => { 40 console.info(TAG + ' update book num=' + num) 41 router.back() 42 }) 43 } 44 45 build() { 46 Column() { 47 Row() { 48 Image($r('app.media.ic_back')) 49 .width(40).height(40) 50 .objectFit(ImageFit.Contain) 51 .onClick(() => { 52 router.back() 53 }) 54 Text($r('app.string.title')) 55 .fontColor(Color.White) 56 .fontSize(20) 57 .layoutWeight(1) 58 Image($r('app.media.submit')) 59 .width(50).height(50) 60 .objectFit(ImageFit.Contain) 61 .onClick(() => { 62 console.info(TAG + ' update onClick,title=' + this.book.name) 63 if (this.book.name === '' || this.book.introduction === '') { 64 prompt.showToast({ message: 'Please input name or introduction' }) 65 return 66 } 67 this.updateBook() 68 }) 69 } 70 .height(50).width('100%') 71 .backgroundColor('#0D9FFB') 72 .padding({ left: 10, right: 10 }) 73 74 Scroll() { 75 Column() { 76 Image($r('app.media.book')) 77 .width(120).height(150) 78 .objectFit(ImageFit.Fill) 79 .margin(5) 80 Text($r('app.string.book_name')) 81 .fontWeight(FontWeight.Bold) 82 .fontSize(22) 83 .width('100%') 84 .margin({ top: 20 }) 85 .fontColor(Color.Black) 86 TextInput({ placeholder: 'input name', text: this.book.name }) 87 .type(InputType.Normal) 88 .placeholderColor(Color.Gray) 89 .fontSize(19) 90 .margin({ top: 10 }) 91 .onChange((value: string) => { 92 this.book.name = value 93 }) 94 95 Text($r('app.string.book_intro')) 96 .fontWeight(FontWeight.Bold) 97 .fontSize(22) 98 .width('100%') 99 .fontColor(Color.Black) 100 .margin({ top: 20 }) 101 TextInput({ placeholder: 'input introduction', text: this.book.introduction }) 102 .type(InputType.Normal) 103 .placeholderColor(Color.Gray) 104 .fontSize(19) 105 .margin({ right: 10, top: 10 }) 106 .onChange((value: string) => { 107 this.book.introduction = value 108 }) 109 } 110 .width('100%') 111 .constraintSize({ minHeight: '100%' }) 112 .padding(15) 113 }.height('100%') 114 } 115 } 116}