# @wines/date-picker

> The date-picker @wines

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

## Install

```sh
npm install @wines/date-picker
pnpm add @wines/date-picker
yarn add @wines/date-picker
bun add @wines/date-picker
```

## 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 | 5 |
| Unpacked size | 25 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tianyingchun |

## Links

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

## Dependencies (5)

- [@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
- [@wines/picker-helpers](https://npm.io/package/@wines/picker-helpers.md) 2.0.0
- [@wines/date-picker-view](https://npm.io/package/@wines/date-picker-view.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/date-picker/versions

## README

# `@wines/date-picker`

# DatePicker 日期选择器

用于选择日期或者时间。

## 使用指南

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

```json
{
  "navigationBarTitleText": "DatePicker",
  "usingComponents": {
    "wux-segmented-control": "@wines/segmented-control",
    "wux-date-picker": "@wines/date-picker",
    "wux-cell-group": "@wines/cell-group",
    "wux-cell": "@wines/cell",
    "wux-button": "@wines/button"
  }
}
```

### 示例

```xml
<wux-date-picker
 visible="{{ visible }}"
 controlled
 mode="datetime"
 value="{{ value1 }}"
 lang="{{ lang }}"
 data-index="1"
 data-mode="datetime"
 bind:confirm="onConfirm"
 bind:visibleChange="onVisibleChange"
/>

<view class="page">
	<view class="page__hd">
		<view class="page__title">DatePicker</view>
		<view class="page__desc">日期选择器</view>
	</view>
	<view class="page__bd">
		<wux-segmented-control values="{{ ['zh_CN', 'zh_TW', 'en'] }}" bind:change="onChange" />
		<wux-cell-group title="Default">
			<wux-date-picker
			 mode="datetime"
			 value="{{ value1 }}"
			 lang="{{ lang }}"
			 data-index="1"
			 data-mode="datetime"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Datetime" is-link extra="{{ displayValue1 }}" />
			</wux-date-picker>
			<wux-date-picker
			 mode="date"
			 value="{{ value2 }}"
			 lang="{{ lang }}"
			 data-index="2"
			 data-mode="date"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Date" is-link extra="{{ displayValue2 }}" />
			</wux-date-picker>
			<wux-date-picker
			 mode="year"
			 value="{{ value3 }}"
			 lang="{{ lang }}"
			 data-index="3"
			 data-mode="year"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Year" is-link extra="{{ displayValue3 }}" />
			</wux-date-picker>
			<wux-date-picker
			 mode="month"
			 value="{{ value4 }}"
			 lang="{{ lang }}"
			 data-index="4"
			 data-mode="month"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Month" is-link extra="{{ displayValue4 }}" />
			</wux-date-picker>
			<wux-date-picker
			 mode="time"
			 value="{{ value5 }}"
			 lang="{{ lang }}"
			 data-index="5"
			 data-mode="time"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Time" is-link extra="{{ displayValue5 }}" />
			</wux-date-picker>
		</wux-cell-group>
		<wux-cell-group title="Use12Hours">
			<wux-date-picker
			 mode="datetime"
			 value="{{ value6 }}"
			 lang="{{ lang }}"
			 use12Hours
			 data-index="6"
			 data-mode="datetime"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Datetime" is-link extra="{{ displayValue6 }}" />
			</wux-date-picker>
			<wux-date-picker
			 mode="time"
			 value="{{ value7 }}"
			 lang="{{ lang }}"
			 use12Hours
			 data-index="7"
			 data-mode="time"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Time" is-link extra="{{ displayValue7 }}" />
			</wux-date-picker>
		</wux-cell-group>
		<wux-cell-group title="MinuteStep">
			<wux-date-picker
			 mode="datetime"
			 value="{{ value8 }}"
			 lang="{{ lang }}"
			 minuteStep="10"
			 data-index="8"
			 data-mode="datetime"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Datetime" is-link extra="{{ displayValue8 }}" />
			</wux-date-picker>
			<wux-date-picker
			 mode="time"
			 value="{{ value9 }}"
			 lang="{{ lang }}"
			 minuteStep="10"
			 data-index="9"
			 data-mode="time"
			 bind:confirm="onConfirm"
			>
				<wux-cell title="Time" is-link extra="{{ displayValue9 }}" />
			</wux-date-picker>
		</wux-cell-group>
		<view class="button-sp-area">
			<wux-button block type="light" bind:click="onClick">Button click - {{ displayValue1 }}</wux-button>
		</view>
	</view>
</view>

```

```ts
import './index.less';
import { DatePickerGetValue } from '@wines/date-picker';

Page({
  data: {
    value1: [],
    value2: [],
    value3: [],
    value4: [],
    value5: [],
    value6: [],
    value7: [],
    value8: [],
    value9: [],
    displayValue1: '请选择',
    displayValue2: '请选择',
    displayValue3: '请选择',
    displayValue4: '请选择',
    displayValue5: '请选择',
    displayValue6: '请选择',
    displayValue7: '请选择',
    displayValue8: '请选择',
    displayValue9: '请选择',
    lang: 'zh_CN',
  },
  onChange(e) {
    console.log(e);
    const { key, values } = e.detail;
    const lang = values[key];

    this.setData({
      lang,
    });
  },
  setValue(values: DatePickerGetValue, key: number, mode) {
    console.log(mode);
    this.setData({
      [`value${key}`]: values.value,
      [`displayValue${key}`]: values.label,
    });
  },
  onConfirm(e) {
    const { index, mode } = e.currentTarget.dataset;
    this.setValue(e.detail, index, mode);
    console.log(`onConfirm${index as number}`, e.detail);
  },
  onVisibleChange(e) {
    this.setData({ visible: e.detail.visible });
  },
  onClick() {
    this.setData({ visible: true });
  },
});
```

## API

### DatePicker props

| 参数                 | 类型            | 描述                                                                                                 | 默认值                |
| -------------------- | --------------- | ---------------------------------------------------------------------------------------------------- | --------------------- |
| prefixCls            | `string`        | 自定义类名前缀                                                                                       | wux-date-picker       |
| multiPickerPrefixCls | `string`        | multPicker 自定义类名前缀                                                                            | wux-picker            |
| pickerPrefixCls      | `string`        | picker 自定义类名前缀                                                                                | wux-picker-col        |
| value                | `any`           | 当前选中时间，例如字符串 `2000-02-01 00:00:00` 或时间戳 `949334400000` 或者数组 `[2000, 1, 1, 0, 0]` | -                     |
| itemHeight           | `number`        | 每列子元素的高度                                                                                     | 34                    |
| itemStyle            | `string,object` | 每列子元素的样式                                                                                     | -                     |
| indicatorStyle       | `string,object` | 设置选择器中间选中框的样式                                                                           | -                     |
| indicatorClass       | `string`        | 设置选择器中间选中框的类名                                                                           | -                     |
| maskStyle            | `string,object` | 设置蒙层的样式                                                                                       | -                     |
| maskClass            | `string`        | 设置蒙层的类名                                                                                       | -                     |
| labelAlign           | `string`        | 设置文本对齐方式，可选值为 right、center、left                                                       | center                |
| mode                 | `string`        | 日期选择的类型，可选值为 datetime、date、year、month、time                                           | datetime              |
| minuteStep           | `number`        | 分钟数递增步长                                                                                       | 1                     |
| use12Hours           | `boolean`       | 是否显示 12 小时制                                                                                   | false                 |
| minDate              | `any`           | 最小可选日期                                                                                         | `2000-02-01 00:00:00` |
| maxDate              | `any`           | 最大可选日期                                                                                         | `2030-02-01 23:59:59` |
| minHour              | `number`        | 最小可选小时                                                                                         | 0                     |
| maxHour              | `number`        | 最大可选小时                                                                                         | 23                    |
| minMinute            | `number`        | 最小可选分钟                                                                                         | 0                     |
| maxMinute            | `number`        | 最大可选分钟                                                                                         | 59                    |
| lang                 | `string`        | 返回文本的语言，可选值为 en、zh_CN、zh_TW                                                            | zh_CN                 |
| toolbar              | `object`        | 工具栏配置项                                                                                         | {}                    |
| toolbar.title        | `string`        | 标题的文字                                                                                           | 请选择                |
| toolbar.cancelText   | `string`        | 取消按钮的文字                                                                                       | 取消                  |
| toolbar.confirmText  | `string`        | 确定按钮的文字                                                                                       | 确定                  |
| trigger              | `string`        | 触发事件，当包裹的子元素为 `<wux-cell />` 时，点击控制组件显隐                                       | onClick               |
| defaultVisible       | `boolean`       | 默认是否显隐，当 `controlled` 为 `false` 时才生效                                                    | false                 |
| visible              | `boolean`       | 用于手动控制组件显隐，当 `controlled` 为 `true` 时才生效                                             | false                 |
| controlled           | `boolean`       | 是否受控 [说明文档](controlled.md)                                                                   | false                 |
| disabled             | `boolean`       | 是否禁用                                                                                             | false                 |
| bind:change          | `function`      | 选择完成后的回调函数                                                                                 | -                     |
| bind:confirm         | `function`      | 点击确定按钮时的回调函数                                                                             | -                     |
| bind:cancel          | `function`      | 点击取消按钮时的回调函数                                                                             | -                     |
| bind:visibleChange   | `function`      | 当显隐状态变化时的回调函数                                                                           | -                     |
| bind:valueChange     | `function`      | 每列数据选择变化后的回调函数                                                                         | -                     |

### DatePicker slot

| 名称 | 描述                         |
| ---- | ---------------------------- |
| -    | 建议包裹 `<wux-cell />` 组件 |

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