# yhzx-ecc-web-sdk

银湖中学班牌web应用对接sdk

## 使用方法

### js或ts调用

```js
import {requestAuth} from 'yhzx-ecc-web-sdk'

requestAuth()
```

### 直接html引入

```html

<script src="./dist/yhzx-ecc-web-sdk.umd.js"></script>
<script>
    window.yhzxEccWebSdk.requestAuth().then(({code}) => {
        console.log(code)
    })
</script>
```

## 接口说明

### requestAuth

```ts
/**
 * 请求授权
 * @returns Promise<{
 *      //状态码
 *      status: number;
 *      message: string;
 *      //临时授权码
 *      code?: string;
 * }>
 */
declare function requestAuth(): Promise<string>

/**
 * 返回状态说明
 */
declare const AuthStatus: {
    SUCCESS: {
        status: 1,
        message: "认证成功",
    },
    FAIL: {
        status: 2,
        message: "认证失败",
    },
    //超时
    TIMEOUT: {
        status: 3,
        message: "认证超时",
    },
    CANCEL: {
        status: 4,
        message: "取消认证",
    },
    //正在授权
    AUTHORIZING: {
        status: 5,
        message: "正在授权",
    },
    ENV_ERROR: {
        status: 6,
        message: "运行环境异常，请检查是否在班牌中运行",
    },
};
```

### addEventListenerReadCard

```ts
/**
 * 添加读卡回调监听
 * @param cb 读卡回调
 */
declare function addEventListenerReadCard(cb: (code: string) => void): void
```

### removeEventListenerReadCard
```ts
/**
 * 移除读卡回调监听
 * @param cb 读卡回调,注意有添加必须有移除,移除必须和addEventListenerReadCard添加的是同一个函数,否则无法移除
 */
declare function removeEventListenerReadCard(cb: (code: string) => void): void
```
