HarmonyOS NEXT-使用和定义封装类

2024-09-25  本文已影响0人  Gavin_2020

封装类定义

/**
 * 识别结果封装
 * 必须进行初始赋值
 */
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;
  }
上一篇 下一篇

猜你喜欢

热点阅读