# @wines/keyboard

> The keyboard @wines

Latest version **2.0.0** (published 2025-04-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wines/keyboard
pnpm add @wines/keyboard
yarn add @wines/keyboard
bun add @wines/keyboard
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-04-01 |
| First published | 2021-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >=16.0.0 |
| Dependencies | 3 |
| Unpacked size | 35.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tianyingchun |

## Links

- npm: https://www.npmjs.com/package/@wines/keyboard
- Repository: https://gitlab.itcjf.com/wines/keyboard
- npm.io page: https://npm.io/package/@wines/keyboard

## Dependencies (3)

- [@wines/core](https://npm.io/package/@wines/core.md) 2.0.0
- [@wines/popup](https://npm.io/package/@wines/popup.md) 2.0.0
- [@wines/styles](https://npm.io/package/@wines/styles.md) 2.0.0

## Recent versions

- 2.0.0 (latest) — 2025-04-01
- 2.0.0-next.7 (next) — 2025-04-01
- 2.0.0-next.6 — 2025-03-06
- 2.0.0-next.5 — 2025-03-05
- 2.0.0-next.4 — 2025-03-05
- 2.0.0-next.3 — 2025-03-04
- 2.0.0-next.2 — 2025-02-28
- 2.0.0-next.1 — 2025-02-27
- 2.0.0-next.0 — 2025-02-27
- 1.5.1 — 2023-03-07
- 1.5.0 — 2022-11-22
- 1.4.0 — 2022-02-23
- 1.3.5 — 2021-12-03
- 1.3.4 — 2021-09-26
- 1.3.2 — 2021-09-24
- … 2 more at https://npm.io/package/@wines/keyboard/versions

## README

# `@wines/keyboard`

# KeyBoard 数字键盘

用于展现数字键盘。

## 使用指南

### 在 page.json 中引入组件

```json
{
  "navigationBarTitleText": "wux-keyboard",
  "usingComponents": {
    "wux-keyboard": "@wines/keyboard"
  }
}
```

### 示例

> 该组件主要依靠 JavaScript 主动调用，所以一般只需在 wxml 中添加一个组件，并设置 id 为 `#wux-keyboard` 或其他，之后在 page.js 中调用 `$wuxKeyBoard(this, id)` 获取匹配到的第一个组件实例对象。

```xml
<wux-keyboard id="wux-keyboard" />
<view class="page">
	<view class="page__hd">
		<view class="page__title">KeyBoard</view>
		<view class="page__desc">数字键盘</view>
	</view>
	<view class="page__bd page__bd_spacing">
		<wux-button block type="light" bind:click="open">Open KeyBoard</wux-button>
		<wux-button block type="light" bind:click="openWitdhDisorder">
			Open a disorderly KeyBoard
		</wux-button>
		<wux-button block type="light" bind:click="openWithPromiseCallback">
			Open KeyBoard with promise callback
		</wux-button>
		<wux-button block type="light" bind:click="openPlain">Plain theme</wux-button>
		<wux-button block type="light" bind:click="openTimed">Open and close</wux-button>
	</view>
</view>

```

```ts
import './index.less';
import { $wuxKeyBoard } from '@wines/keyboard';
import { PageCustom, PageData } from '@wines/core';

Page<PageData, PageCustom>({
  data: {},
  onLoad() {
    /** */
  },
  open() {
    $wuxKeyBoard().show({
      callback(value: string) {
        console.log(`输入的密码是：${value}`);
        return true;
      },
    });
  },
  openWitdhDisorder() {
    $wuxKeyBoard().show({
      disorder: true,
      callback(value: string) {
        console.log(`输入的密码是：${value}`);
        return false;
      },
    });
  },
  openWithPromiseCallback() {
    const http = (obj) => {
      return new Promise((resolve, reject) => {
        obj.success = (res) => resolve(res);
        obj.fail = (res) => reject(res);
        wx.request(obj);
      });
    };

    $wuxKeyBoard().show({
      closeOnReject: true,
      callback(value: string) {
        console.log(`输入的密码是：${value}`);

        void wx.showLoading({
          title: '验证支付密码',
        });

        return http({
          url: 'https://www.skyvow.cn/api/user/sign/in',
          method: 'POST',
          data: {
            username: 'admin',
            password: value,
          },
        })
          .then((res) => {
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            const data = (res as any).data;

            console.log(data);

            void wx.hideLoading();

            void wx.showToast({
              title: data.meta.message,
              duration: 3000,
            });

            if (data.meta.code !== 0) {
              return Promise.reject(data.meta.message);
            }
            return Promise.resolve();
          })
          .catch((err) => {
            void wx.hideLoading();
            return Promise.reject(err);
          });
      },
    });
  },
  openPlain() {
    const fn = (title) => {
      void wx.hideLoading();
      void wx.showToast({
        title,
        duration: 3000,
      });
    };

    $wuxKeyBoard().show({
      className: 'className',
      titleText: '安全键盘',
      cancelText: '取消',
      inputText: '输入数字密码',
      showCancel: true,
      disorder: false,
      maxlength: 4,
      closeOnReject: false,
      callback(value: string) {
        console.log(`输入的密码是：${value}`);
        void wx.showLoading({
          title: '验证支付密码',
        });

        return new Promise((resolve, reject) => {
          setTimeout(
            () =>
              Math.ceil(Math.random() * 10) >= 6
                ? resolve(fn('密码正确'))
                : reject(fn('密码错误')),
            3000
          );
        });
      },
    });
  },
  openTimed() {
    clearTimeout(this.timeout);
    const hide = $wuxKeyBoard().show({
      password: false,
      maxlength: -1,
      onChange(value: string) {
        console.log(`输入的密码是：${value}`);
      },
      onClose() {
        return false;
      },
    });

    this.timeout = setTimeout(() => {
      hide();
    }, 3000);
  },
});
```

## API

| 参数                  | 类型            | 描述                                         | 默认值       |
| --------------------- | --------------- | -------------------------------------------- | ------------ |
| options               | `object`        | 配置项                                       | -            |
| options.prefixCls     | `string`        | 自定义类名前缀                               | wux-keyboard |
| options.className     | `string`        | 自定义类名                                   | -            |
| options.titleText     | `string`        | 标题                                         | 安全键盘     |
| options.cancelText    | `string`        | 取消按钮的文字                               | 取消         |
| options.inputText     | `string`        | 提示文本                                     | 输入数字密码 |
| options.showCancel    | `boolean`       | 是否显示取消按钮                             | true         |
| options.disorder      | `boolean`       | 是否打乱键盘                                 | false        |
| options.password      | `boolean`       | 是否密码类型                                 | true         |
| options.maxlength     | `number,string` | 最大输入长度，设置为 -1 的时候不限制最大长度 | 6            |
| options.closeOnReject | `boolean`       | Promise 返回 reject 时关闭组件               | true         |
| options.onChange      | `function`      | change 事件触发的回调函数                    | -            |
| options.callback      | `function`      | 输入完成后的回调函数                         | -            |
| options.onClose       | `function`      | 输入完成后的回调函数，优先级高于 callback    | -            |

---
_Source: https://npm.io/package/@wines/keyboard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
