1/* 2* Copyright (c) 2023 Hunan OpenValley Digital Industry Development 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 router from '@ohos.router'; 17import emitter from '@ohos.events.emitter'; 18import { getString } from '@ohos/common/src/main/ets/util/ResourceUtil'; 19import { Constant } from '@ohos/capabilities'; 20 21@Entry 22@Component 23export struct AddKeyValueView { 24 @State value: string = '' 25 @State title: string = ''; 26 @State flag: string = ''; 27 28 aboutToAppear() { 29 let tem: string = (router.getParams() as Record<string, Object>)['title'] as string; 30 if (!tem) { 31 return; 32 } 33 this.flag = tem; 34 let regex: RegExp = new RegExp('.*(?=\\(|()'); 35 let matchArr: RegExpMatchArray | null = tem.match(regex); 36 if (matchArr !== null) { 37 this.title = `${getString($r('app.string.add'))}${matchArr[0]}`; 38 } 39 } 40 41 build() { 42 Column() { 43 Row() { 44 Row() { 45 Image($r("app.media.ic_public_back")) 46 .height(24) 47 .aspectRatio(1) 48 .objectFit(ImageFit.Contain) 49 } 50 .height('100%') 51 .aspectRatio(1) 52 .padding({ left: 24 }) 53 .onClick(() => { 54 router.back(); 55 }) 56 57 Text(this.title) 58 .fontColor($r('app.color.text_color_primary')) 59 .fontSize(20) 60 .margin({ left: 24 }) 61 62 Blank() 63 64 Row() { 65 Image($r("app.media.ic_public_confirm")) 66 .height(24) 67 .aspectRatio(1) 68 .objectFit(ImageFit.Contain) 69 } 70 .id('add_confirm') 71 .height('100%') 72 .aspectRatio(1) 73 .padding({ right: 24 }) 74 .onClick(() => { 75 let eventId = Constant.EMITTER_ID_DEFAULT; 76 switch (this.flag) { 77 case getString($r('app.string.hash_set')): 78 eventId = Constant.EMITTER_ID_HASH_SET; 79 break; 80 case getString($r('app.string.light_weight_set')): 81 eventId = Constant.EMITTER_ID_LIGHT_WEIGHT_SET; 82 break; 83 case getString($r('app.string.tree_set')): 84 eventId = Constant.EMITTER_ID_TREE_SET; 85 break; 86 default: 87 eventId = Constant.EMITTER_ID_DEFAULT; 88 break; 89 } 90 91 let event: emitter.InnerEvent = { 92 eventId: eventId, 93 priority: emitter.EventPriority.HIGH 94 }; 95 96 let eventData: emitter.EventData = { 97 data: { 'value': this.value } 98 }; 99 100 emitter.emit(event, eventData); 101 router.back(); 102 }) 103 } 104 .width('100%') 105 .height(56) 106 107 Row() { 108 Text('Value') 109 .margin({ left: 19 }) 110 .fontSize(16) 111 .fontColor($r('app.color.text_color_primary')) 112 Column() { 113 TextInput({ placeholder: $r('app.string.input_value') }) 114 .id('add_value') 115 .height(48) 116 .fontSize(16) 117 .backgroundColor($r('sys.color.ohos_id_color_background_transparent')) 118 .onChange((value: string) => { 119 this.value = value; 120 }) 121 } 122 .layoutWeight(1) 123 .margin({ left: 52, right: 16 }) 124 } 125 .height(64) 126 .width('100%') 127 .borderRadius(16) 128 .backgroundColor($r('app.color.bg_white')) 129 .margin({ top: 12 }) 130 } 131 .height('100%') 132 .backgroundColor($r('sys.color.ohos_id_color_sub_background')) 133 .padding({ left: 12, right: 12 }) 134 } 135}