Skip to content

Commit f2e8fda

Browse files
feat: ✨ DatetimePicker 支持time和date-time类型下配置选择到秒 (#1117)
✅ Closes: #844
1 parent 6026137 commit f2e8fda

18 files changed

Lines changed: 544 additions & 140 deletions

File tree

‎docs/component/datetime-picker-view.md‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,29 @@ const value = ref<number>(Date.now())
6464
const value4 = ref<string>('11:12')
6565
```
6666

67-
## 修改内部格式
67+
## time 类型(带秒)
68+
69+
`time` 类型设置 `use-second` 属性可以展示时分秒,绑定值为 `HH:mm:ss` 格式。
70+
71+
```html
72+
<wd-datetime-picker-view type="time" v-model="value" label="时分秒" use-second />
73+
```
74+
```typescript
75+
const value = ref<string>('11:12:30')
76+
```
77+
78+
## datetime 类型(带秒)
6879

80+
`datetime` 类型设置 `use-second` 属性可以展示年月日时分秒,绑定值为时间戳。
6981

82+
```html
83+
<wd-datetime-picker-view type="datetime" v-model="value" label="年月日时分秒" use-second />
84+
```
85+
```typescript
86+
const value = ref<number>(Date.now())
87+
```
88+
89+
## 修改内部格式
7090

7191
给 `formatter` 属性传入一个函数,接收 `type` 和 `value` 值,返回展示的文本内容。`type` 有 `year`、`month`、`date`、`hour`、`minute` 类型,`value` 为 `number` 类型。
7292
使用自定义`formatter`会关闭内置的默认`display-format`函数。
@@ -133,6 +153,8 @@ const filter = (type, values) => {
133153
| minMinute | 最小分钟,time类型时生效 | number | - | 0 | - |
134154
| maxMinute | 最大分钟,time类型时生效 | number | - | 59 | - |
135155
| immediate-change | 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。 | boolean | - | false | 1.2.25 |
156+
| use-second | 是否显示秒选择,仅在 time 和 datetime 类型下生效 | boolean | - | false | $LOWEST_VERSION$ |
157+
136158
## Events
137159

138160
| 事件名称 | 说明 | 参数 | 最低版本 |

‎docs/component/datetime-picker.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ const value = ref<number>(Date.now())
7878
const value4 = ref<string>('09:20')
7979
```
8080

81+
## time 类型(带秒)
82+
83+
`time` 类型设置 `use-second` 属性可以展示时分秒,绑定值为 `HH:mm:ss` 格式。
84+
85+
```html
86+
<wd-datetime-picker type="time" v-model="value" label="时分秒" use-second />
87+
```
88+
```typescript
89+
const value = ref<string>('09:20:30')
90+
```
91+
92+
## datetime 类型(带秒)
93+
94+
`datetime` 类型设置 `use-second` 属性可以展示年月日时分秒,绑定值为时间戳。
95+
96+
```html
97+
<wd-datetime-picker type="datetime" v-model="value" label="年月日时分秒" use-second />
98+
```
99+
```typescript
100+
const value = ref<number>(Date.now())
101+
```
102+
81103
## 修改展示格式
82104

83105

@@ -295,6 +317,7 @@ const displayFormatTabLabel = (items) => {
295317
| prop | 表单域 `model` 字段名,在使用表单校验功能的情况下,该属性是必填的 | string | - | - | - |
296318
| rules | 表单验证规则,结合`wd-form`组件使用 | `FormItemRule []` | - | `[]` | - |
297319
| immediate-change | 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。 | boolean | - | false | 1.2.25 |
320+
| use-second | 是否显示秒选择,仅在 time 和 datetime 类型下生效 | boolean | - | false | $LOWEST_VERSION$ |
298321

299322
### FormItemRule 数据结构
300323

‎docs/en-US/component/datetime-picker-view.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ const value = ref<number>(Date.now())
6565
const value4 = ref<string>('11:12')
6666
```
6767

68+
## Time Type (with Seconds)
69+
70+
`time` type with `use-second` property displays hour, minute and second, the binding value is in `HH:mm:ss` format.
71+
72+
```html
73+
<wd-datetime-picker-view type="time" v-model="value" label="Hour Minute Second" use-second />
74+
```
75+
```typescript
76+
const value = ref<string>('11:12:30')
77+
```
78+
79+
## Datetime Type (with Seconds)
80+
81+
`datetime` type with `use-second` property displays year, month, day, hour, minute and second, the binding value is timestamp.
82+
83+
```html
84+
<wd-datetime-picker-view type="datetime" v-model="value" label="Year Month Day Hour Minute Second" use-second />
85+
```
86+
```typescript
87+
const value = ref<number>(Date.now())
88+
```
89+
6890
## Modify Internal Format
6991

7092
Pass a function to the `formatter` property, which receives `type` and `value` values and returns the display text content. `type` can be `year`, `month`, `date`, `hour`, `minute`, and `value` is of type `number`.
@@ -131,6 +153,7 @@ const filter = (type, values) => {
131153
| minMinute | Minimum minute, effective for time type | number | - | 0 | - |
132154
| maxMinute | Maximum minute, effective for time type | number | - | 59 | - |
133155
| immediate-change | Whether to trigger the picker-view's change event immediately when the finger is released. If not enabled, the change event will be triggered after the scrolling animation ends. Available from version 1.2.25, only supported on WeChat Mini Program and Alipay Mini Program. | boolean | - | false | 1.2.25 |
156+
| use-second | Whether to display the second selection, only effective for time and datetime types | boolean | - | false | $LOWEST_VERSION$ |
134157

135158
## Events
136159

‎docs/en-US/component/datetime-picker.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ const value = ref<number>(Date.now())
7878
const value4 = ref<string>('09:20')
7979
```
8080

81+
## Time Type (with Seconds)
82+
83+
`time` type with `use-second` property displays hour, minute and second, the binding value is in `HH:mm:ss` format.
84+
85+
```html
86+
<wd-datetime-picker type="time" v-model="value" label="Hour Minute Second" use-second />
87+
```
88+
```typescript
89+
const value = ref<string>('09:20:30')
90+
```
91+
92+
## Datetime Type (with Seconds)
93+
94+
`datetime` type with `use-second` property displays year, month, day, hour, minute and second, the binding value is timestamp.
95+
96+
```html
97+
<wd-datetime-picker type="datetime" v-model="value" label="Year Month Day Hour Minute Second" use-second />
98+
```
99+
```typescript
100+
const value = ref<number>(Date.now())
101+
```
102+
81103
## Modify Display Format
82104

83105
Pass a function to the `display-format` property, which receives an array of all selected items and returns the display text content.
@@ -290,6 +312,7 @@ const displayFormatTabLabel = (items) => {
290312
| prop | Form field `model` field name, required when using form validation | string | - | - | - |
291313
| rules | Form validation rules, used with `wd-form` component | `FormItemRule []` | - | `[]` | - |
292314
| immediate-change | Whether to trigger the picker-view's change event immediately when the finger is released. If not enabled, the change event will be triggered after the scrolling animation ends. Available from version 1.2.25, only supported on WeChat Mini Program and Alipay Mini Program. | boolean | - | false | 1.2.25 |
315+
| use-second | Whether to display the second selection, only effective for time and datetime types | boolean | - | false | $LOWEST_VERSION$ |
293316

294317
### FormItemRule Data Structure
295318

‎src/locale/en-US.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@
969969
"ri-qi-xuan-ze-1": "Date selection",
970970
"ri-qi-xuan-ze-2": "Date selection",
971971
"ri-qi-xuan-ze-3": "Date selection",
972+
"ri-qi-xuan-ze-dai-miao": "Date selection (with seconds)",
972973
"ri-zhou-yue-qie-huan": "Day Week Month Switching",
973974
"ring-lei-xing-loading": "Ring type loading",
974975
"ru-ding-dan-chu-yu-zan-ting-zhuang-tai-jin-ru-wo-de-ding-dan-ye-mian-zhao-dao-yao-qu-xiao-de-ding-dan-dian-ji-qu-xiao-ding-dan-an-niu-xuan-ze-ding-dan-qu-xiao-yuan-yin-hou-dian-ji-xia-yi-bu-ti-jiao-shen-qing-ji-ke": "If the order is in a suspended state, go to the \"My Orders\" page, find the order you want to cancel, and click the \"Cancel Order\" button; After selecting the reason for canceling the order, click \"Next\" to submit the application.",
@@ -1035,6 +1036,7 @@
10351036
"shi-jian-fan-wei-yi-nian": "Time Range: One Year",
10361037
"shi-jian-he-di-zhi": "Time and Address",
10371038
"shi-jian-lei-xing": "TIME",
1039+
"shi-jian-xuan-ze-dai-miao": "Time selection (with seconds)",
10381040
"shi-jiao-xiao-yan": "Out of focus verification",
10391041
"shi-jiao-xiao-yan-0": "Out of focus verification",
10401042
"shi-jing-shan-qu": "SHIJINGSHAN",

‎src/locale/zh-CN.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@
969969
"ri-qi-xuan-ze-1": "日期选择",
970970
"ri-qi-xuan-ze-2": "日期选择",
971971
"ri-qi-xuan-ze-3": "日期选择",
972+
"ri-qi-xuan-ze-dai-miao": "日期选择(带秒)",
972973
"ri-zhou-yue-qie-huan": "日周月切换",
973974
"ring-lei-xing-loading": "ring类型loading",
974975
"ru-ding-dan-chu-yu-zan-ting-zhuang-tai-jin-ru-wo-de-ding-dan-ye-mian-zhao-dao-yao-qu-xiao-de-ding-dan-dian-ji-qu-xiao-ding-dan-an-niu-xuan-ze-ding-dan-qu-xiao-yuan-yin-hou-dian-ji-xia-yi-bu-ti-jiao-shen-qing-ji-ke": "如订单处于暂停状态,进入“我的订单”页面,找到要取消的订单,点击“取消订单”按钮;选择订单取消原因后,点击“下一步”提交申请即可。",
@@ -1035,6 +1036,7 @@
10351036
"shi-jian-fan-wei-yi-nian": "时间范围一年",
10361037
"shi-jian-he-di-zhi": "时间和地址",
10371038
"shi-jian-lei-xing": "时间类型",
1039+
"shi-jian-xuan-ze-dai-miao": "时间选择(带秒)",
10381040
"shi-jiao-xiao-yan": "失焦校验",
10391041
"shi-jiao-xiao-yan-0": "失焦校验",
10401042
"shi-jing-shan-qu": "石景山区",

‎src/subPages/datetimePicker/Index.vue‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
<demo-block transparent>
55
<wd-cell-group border>
66
<wd-datetime-picker :label="$t('ri-qi-xuan-ze')" v-model="value1" @confirm="handleConfirm1" />
7+
<wd-datetime-picker :label="$t('ri-qi-xuan-ze-dai-miao')" use-second v-model="value18" />
78
<wd-datetime-picker :label="$t('nian-yue-ri')" v-model="value2" type="date" @confirm="handleConfirm2" />
89
<wd-datetime-picker :label="$t('nian-yue')" v-model="value3" type="year-month" @confirm="handleConfirm3" />
910
<wd-datetime-picker :label="$t('nian')" v-model="value16" type="year" @confirm="handleConfirm16" />
1011
<wd-datetime-picker :label="$t('shi-fen')" v-model="value4" type="time" @confirm="handleConfirm4" />
12+
<wd-datetime-picker :label="$t('shi-jian-xuan-ze-dai-miao')" v-model="value19" type="time" use-second />
1113
<wd-datetime-picker :label="$t('zhan-shi-ge-shi')" v-model="value5" :display-format="displayFormat" @confirm="handleConfirm5" />
1214
<wd-datetime-picker :label="$t('nei-bu-ge-shi')" v-model="value6" :formatter="formatter" @confirm="handleConfirm6" />
1315
<wd-datetime-picker :label="$t('guo-lv-xuan-xiang')" v-model="value7" :filter="filter" @confirm="handleConfirm7" />
@@ -34,7 +36,13 @@
3436
<wd-datetime-picker :label="$t('ri-qi-xuan-ze-1')" align-right v-model="value13" @confirm="handleConfirm13" />
3537
</demo-block>
3638
<demo-block :title="$t('qu-yu-xuan-ze')" transparent>
37-
<wd-datetime-picker :label="$t('ri-qi-xuan-ze-2')" :title="$t('qing-xuan-ze-qu-jian')" v-model="value14" @confirm="handleConfirm14" />
39+
<wd-datetime-picker
40+
:label="$t('ri-qi-xuan-ze-2')"
41+
:title="$t('qing-xuan-ze-qu-jian')"
42+
v-model="value14"
43+
use-second
44+
@confirm="handleConfirm14"
45+
/>
3846
</demo-block>
3947
<demo-block :title="$t('fan-wei-tab-zhan-shi-ge-shi')" transparent>
4048
<wd-datetime-picker
@@ -76,7 +84,8 @@ const value14 = ref<any[]>(['', ''])
7684
const value15 = ref<any[]>(['', Date.now()])
7785
const value16 = ref(Date.now())
7886
const value17 = ref(Date.now())
79-
87+
const value18 = ref(Date.now())
88+
const value19 = ref('09:20:26')
8089
const minDate = ref<number>(Date.now())
8190
const maxDate = ref<number>(new Date(new Date().getFullYear() + 1, new Date().getMonth(), new Date().getDate()).getTime())
8291

‎src/subPages/datetimePickerView/Index.vue‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<wd-datetime-picker-view v-model="value1" @change="onChange1" />
66
</demo-block>
77

8+
<demo-block :title="$t('ri-qi-xuan-ze-dai-miao')" transparent>
9+
<wd-datetime-picker-view v-model="value8" use-second />
10+
</demo-block>
11+
812
<demo-block :title="$t('nian-yue-ri')" transparent>
913
<wd-datetime-picker-view type="date" v-model="value2" @change="onChange2" />
1014
</demo-block>
@@ -21,6 +25,10 @@
2125
<wd-datetime-picker-view type="time" v-model="value4" @change="onChange4" />
2226
</demo-block>
2327

28+
<demo-block :title="$t('shi-jian-xuan-ze-dai-miao')" transparent>
29+
<wd-datetime-picker-view type="time" v-model="value9" use-second @change="onChange4" />
30+
</demo-block>
31+
2432
<demo-block :title="$t('nei-bu-ge-shi')" transparent>
2533
<wd-datetime-picker-view v-model="value5" :formatter="formatter" @change="onChange5" />
2634
</demo-block>
@@ -44,6 +52,9 @@ const value4 = ref<string>('11:12')
4452
const value5 = ref<number>(Date.now())
4553
const value6 = ref<number>(Date.now())
4654
const value7 = ref<string>('')
55+
const value8 = ref<number>(Date.now())
56+
const value9 = ref<string>('11:12:13')
57+
4758
const formatter: DatetimePickerViewFormatter = (type, value) => {
4859
switch (type) {
4960
case 'year':

‎src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ $-fw-semibold: var(--wot-fw-semibold, 600) !default; // PingFangSC-Semibold
8484

8585
/* 尺寸 */
8686
$-size-side-padding: var(--wot-size-side-padding, 15px) !default; // 屏幕两边留白
87+
$-size-side-padding-small: var(--wot-size-side-padding-small, 6px) !default; // 屏幕两边留白小值
8788

8889
/*-------------------------------- Theme color application size. end --------------------------------*/
8990

@@ -438,7 +439,7 @@ $-picker-column-height: var(--wot-picker-column-height, 210px) !default; // 列
438439
$-picker-column-item-height: var(--wot-picker-column-item-height, 35px) !default; // 列高 滚筒外部的高度
439440
$-picker-column-select-bg: var(--wot-picker-column-select-bg, #f5f5f5) !default;
440441
$-picker-loading-button-color: var(--wot-picker-loading-button-color, rgba(0, 0, 0, 0.25)) !default; // loading 背景颜色
441-
$-picker-column-padding: var(--wot-picker-column-padding, 0 $-size-side-padding) !default; // 选项内间距
442+
$-picker-column-padding: var(--wot-picker-column-padding, 0 $-size-side-padding-small) !default; // 选项内间距
442443

443444
$-picker-column-disabled-color: var(--wot-picker-column-disabled-color, rgba(0, 0, 0, 0.25)) !default; // 选择器选项禁用的颜色
444445
$-picker-mask: var(--wot-picker-mask, linear-gradient(180deg, hsla(0, 0%, 100%, 0.9), hsla(0, 0%, 100%, 0.25)))

‎src/uni_modules/wot-design-uni/components/wd-datetime-picker-view/index.scss‎

Whitespace-only changes.

0 commit comments

Comments
 (0)