---
name: "onAddUnlockMethod"
mode: "api"
versionRequirements:
  - { name: "@ray-js/lock-sdk", version: "1.0.0" }
title: "onAddUnlockMethod - 注册开锁方式步骤监听器。"
summary: "注册开锁方式步骤监听器。用于监听添加开锁方式时的录入进度。"
---

## onAddUnlockMethod

> [VERSION] @ray-js/lock-sdk >= 1.0.0

### 描述

注册开锁方式步骤监听器

### 参数

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `listener` | `(event: StepEvent \| SuccessEvent \| ErrorEvent) => void` | 是 | 事件监听 |

### 返回值

无


### 引用对象

##### `interface` StepEvent

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `type` | `"finger" \| "face" \| "password" \| "card" \| "fingerVein" \| "hand" \| "eye"` |  |
| `lockUserId` | `number` |  |
| `stage` | `"step"` |  |
| `step` | `number` |  |
| `total` | `number` |  |

##### `interface` SuccessEvent

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `type` | `"finger" \| "face" \| "password" \| "card" \| "fingerVein" \| "hand" \| "eye"` |  |
| `id` | `number` |  |
| `name` | `string` |  |
| `stage` | `"success"` |  |

##### `interface` ErrorEvent

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `type` | `"finger" \| "face" \| "password" \| "card" \| "fingerVein" \| "hand" \| "eye"` |  |
| `lockUserId` | `number` |  |
| `stage` | `"fail"` |  |
| `error` | `ErrorData` |  |

##### `type` UnlockMethodType

开锁方式业务类型字面量

```typescript
export type UnlockMethodType =
  | "finger"
  | "face"
  | "password"
  | "card"
  | "fingerVein"
  | "hand"
  | "eye";
```

##### `type` ErrorData

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorCode` | `number` | 错误码 |
| `errorMsg` | `string` | 错误文案（多为英文） |


### 示例代码

#### 示例

```ts
import { onAddUnlockMethod } from '@ray-js/lock-sdk';
onAddUnlockMethod((event) => {
  console.log(event);
});
```
