1/* 2 * Copyright (c) 2024 Shenzhen Kaihong 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 image from '@ohos.multimedia.image'; 18import Logger from '../../../util/Logger'; 19import testNapi, { testNapiValue } from 'libentry.so'; 20import { TitleBar } from '../../../common/TitleBar' 21import hilog from '@ohos.hilog'; 22 23const TAG: string = 'napi_delete_property'; 24 25interface myObjVal { 26 key: string 27} 28 29interface myObj { 30 key1: string; 31 true: number; 32 key3: boolean; 33 key4: Array<string>; 34 key5: Function; 35 key6: myObjVal; 36} 37 38@Entry 39@Component 40struct napiGetPropertyNames { 41 private btnFontColor: Resource = $r('app.color.white'); 42 private pixelMapFormat: image.PixelMapFormat = 3; 43 private textcont: Resource = $r('app.string.napi_delete_property_description'); 44 @State isSetInstance: Boolean = false; 45 @State imagePixelMap: PixelMap | undefined = undefined; 46 @State testcont: string = ' // 测试 N-API napi_delete_property \n' 47 + 'let obj = {key1: "value",true: 1,key3: false,key4: ["a", "b", "c"],key5: function () { return "function" },key6: {key: "value"}} \n' 48 + ' const myData = testNapi.testNapiDeleteProperty(obj, "key1"); \n' 49 + ' console.log(myData); // 输出自定义数据 \n' 50 + ' const myData2 = testNapi.testNapiDeleteProperty(obj, true); \n' 51 + ' console.log(myData2); // 输出自定义数据 \n' 52 + ' const myData3 = testNapi.testNapiDeleteProperty(obj, "key3"); \n' 53 + ' console.log(myData3); // 输出自定义数据 \n' 54 + ' const myData4 = testNapi.testNapiDeleteProperty(obj, "key4"); \n' 55 + ' console.log(myData4); // 输出自定义数据 \n' 56 + ' const myData5 = testNapi.testNapiDeleteProperty(obj, "key5"); \n' 57 + ' console.log(myData5); // 输出自定义数据 \n' 58 + ' const myData6 = testNapi.testNapiDeleteProperty(obj, "key6"); \n' 59 + ' console.log(myData6); // 输出自定义数据 \n'; 60 61 controller: TextAreaController = new TextAreaController() 62 63 build() { 64 Column() { 65 // 标题 66 TitleBar({ title: $r('app.string.napi_delete_property') }) 67 68 Column() { 69 Column() { 70 TextArea({ 71 text: this.textcont, 72 placeholder: '', 73 }) 74 .placeholderFont({ size: 16, weight: 400 }) 75 .width('90%') 76 .margin(10) 77 .fontSize(16) 78 .fontColor($r('app.color.sub_title_color')) 79 .backgroundColor($r('app.color.white')) 80 .enabled(false) 81 82 TextArea({ 83 text: this.testcont, 84 placeholder: '', 85 }) 86 .placeholderFont({ size: 16, weight: 400 }) 87 .width('90%') 88 .margin(10) 89 .fontSize(16) 90 .fontColor($r('app.color.textarea_font_color')) 91 .backgroundColor($r('app.color.textarea_background_color')) 92 .enabled(false) 93 } 94 .width('100%') 95 .alignItems(HorizontalAlign.Center) 96 .justifyContent(FlexAlign.Start) 97 98 Row() { 99 Button($r('app.string.napi_delete_property'), { type: ButtonType.Capsule }) 100 .backgroundColor(Color.Blue) 101 .width('80%') 102 .height(48) 103 .fontSize(16) 104 .fontWeight(500) 105 .fontColor(this.btnFontColor) 106 .margin({ left: 24 }) 107 .id('napi_delete_property') 108 .onClick(() => { 109 let obj: myObj = { 110 key1: "value", 111 true: 1, 112 key3: false, 113 key4: ["a", "b", "c"], 114 key5: () => { 115 return "function"; 116 }, 117 key6: {key: "value"} 118 } 119 let ret = testNapi.testNapiDeleteProperty(obj, "key1"); 120 this.testcont = this.testcont.replace('log(myData)', 'log(## '+JSON.stringify(ret)+' ##)'); 121 let ret2 = testNapi.testNapiDeleteProperty(obj, true); 122 this.testcont = this.testcont.replace('log(myData2)', 'log(## '+JSON.stringify(ret2)+' ##)'); 123 let ret3 = testNapi.testNapiDeleteProperty(obj, "key3"); 124 this.testcont = this.testcont.replace('log(myData3)', 'log(## '+JSON.stringify(ret3)+' ##)'); 125 let ret4 = testNapi.testNapiDeleteProperty(obj, "key4"); 126 this.testcont = this.testcont.replace('log(myData4)', 'log(## '+JSON.stringify(ret4)+' ##)'); 127 let ret5 = testNapi.testNapiDeleteProperty(obj, "key5"); 128 this.testcont = this.testcont.replace('log(myData5)', 'log(## '+JSON.stringify(ret5)+' ##)'); 129 let ret6 = testNapi.testNapiDeleteProperty(obj, "key6"); 130 this.testcont = this.testcont.replace('log(myData6)', 'log(## '+JSON.stringify(ret6)+' ##)'); 131 }) 132 } 133 .width('100%') 134 .height(48) 135 .alignItems(VerticalAlign.Center) 136 .justifyContent(FlexAlign.SpaceBetween) 137 } 138 .width('100%') 139 } 140 .height('100%') 141 .width('100%') 142 .backgroundColor($r('app.color.background_shallow_grey')) 143 } 144} 145