• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 from 'libentry.so';
20import { TitleBar } from '../../../common/TitleBar'
21import hilog from '@ohos.hilog';
22
23const TAG: string = 'napi_roi';
24
25@Entry
26@Component
27struct napiextendederrorinfo {
28  private btnFontColor: Resource = $r('app.color.white');
29  private pixelMapFormat: image.PixelMapFormat = 3;
30  @State isSetInstance: Boolean = false;
31  @State imagePixelMap: PixelMap | undefined = undefined;
32  @State bgColor: string = '#ff719807';
33  @State textcont: string = '指示 Node-API 调用成功或失败的完整状态代码。目前支持以下状态码。'
34    + '如果 API 返回失败状态时需要额外的信息,可以通过调用 napi_get_last_error_info 获取。'
35  @State testcont: string = ' // 获取导出的 N-API 实例对象 \n'
36    + ' // 失败案例,设置 > 10 报错 \n'
37    + ' try { \n'
38    + "   const result = addon.testExterrinfo(5, '10'); \n"
39    + ' } catch (error) { \n'
40    + "   console.error('An error occurred in the addon:', error.message); \n"
41    + ' } \n';
42
43  controller: TextAreaController = new TextAreaController()
44
45  build() {
46    Column() {
47      // 标题
48      TitleBar({ title: $r('app.string.napi_extended_error_info') })
49
50      Column() {
51        Column() {
52          TextArea({
53            text: this.textcont,
54            placeholder: '',
55          })
56            .placeholderFont({ size: 16, weight: 400 })
57            .width('90%')
58            .margin(10)
59            .fontSize(16)
60            .fontColor('#182431')
61            .backgroundColor('#FFFFFF')
62            .enabled(false)
63
64          TextArea({
65            text: this.testcont,
66            placeholder: '',
67          })
68            .placeholderFont({ size: 16, weight: 400 })
69            .width('90%')
70            .margin(10)
71            .fontSize(16)
72            .fontColor('#ff400336')
73            .backgroundColor(this.bgColor)
74            .enabled(false)
75        }
76        .width('100%')
77        .alignItems(HorizontalAlign.Center)
78        .justifyContent(FlexAlign.Start)
79
80        Row() {
81
82          Button($r('app.string.napi_extended_error_info'), { type: ButtonType.Capsule })
83            .backgroundColor(Color.Blue)
84            .width('80%')
85            .height(48)
86            .fontSize(16)
87            .fontWeight(500)
88            .fontColor(this.btnFontColor)
89            .margin({ left: 24 })
90            .id('napiexterrorinfo')
91            .onClick(() => {
92              try {
93                let result1 = testNapi.testExterrinfo(5, '10');
94              } catch (error) {
95                console.log(`Catch eror of testExterrinfo is: ${error.message}`);
96                this.testcont = this.testcont.replace('error.message', 'log(## '+error.message+' ##)');
97                this.bgColor = '#ffac08d4';
98              }
99            })
100        }
101        .width('100%')
102        .height(48)
103        .alignItems(VerticalAlign.Center)
104        .justifyContent(FlexAlign.SpaceBetween)
105      }
106      .width('100%')
107    }
108    .height('100%')
109    .width('100%')
110    .backgroundColor($r('app.color.background_shallow_grey'))
111  }
112}
113