HarmonyOS NEXT-使用和定义封装类

封装类定义

/**
 * 识别结果封装
 * 必须进行初始赋值
 */
class IdcardResult {
  code: number = 0; // 识别码 0成功 其他为识别失败
  msg: string = ''; // 错误信息
  name: string = ''; // 姓名
  id: string = ''; // 身份证号
  sex: string = ''; // 性别
  nation: string = ''; // 民族
  birth: string = ''; // 出生日期
  address: string = ''; // 住址
}

使用封装类

// 结果封装
  let result: IdcardResult;  // 定义封装对象

  public static async picSIDCardRecog(path: string): Promise<IdcardResult> {
    try {
      result = new IdcardResult();
      if (path == "") {
        result.code = -1;
        return result;
      }
      console.error(IdcardConfig.SDK_TAG, `importOcrRecog_path: ${JSON.stringify(path)}`);
      result.code = 0;
    } catch (error) {
      let err = error as BusinessError;
      console.error(IdcardConfig.SDK_TAG + 'Failed picSIDCardRecog. errorCode = ' + err.code);
    }
    return result;
  }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容