mirror of
https://gitee.com/ElemeFE/element.git
synced 2024-12-05 05:38:24 +08:00
5493a13523
unify N/A marks in docs
262 lines
7.7 KiB
Markdown
262 lines
7.7 KiB
Markdown
<script>
|
||
module.exports = {
|
||
data() {
|
||
return {
|
||
pickerOptions1: {
|
||
shortcuts: [{
|
||
text: '今天',
|
||
onClick(picker) {
|
||
picker.$emit('pick', new Date());
|
||
}
|
||
}, {
|
||
text: '昨天',
|
||
onClick(picker) {
|
||
const date = new Date();
|
||
date.setTime(date.getTime() - 3600 * 1000 * 24);
|
||
picker.$emit('pick', date);
|
||
}
|
||
}, {
|
||
text: '一周前',
|
||
onClick(picker) {
|
||
const date = new Date();
|
||
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
|
||
picker.$emit('pick', date);
|
||
}
|
||
}]
|
||
},
|
||
pickerOptions2: {
|
||
shortcuts: [{
|
||
text: '最近一周',
|
||
onClick(picker) {
|
||
const end = new Date();
|
||
const start = new Date();
|
||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
|
||
picker.$emit('pick', [start, end]);
|
||
}
|
||
}, {
|
||
text: '最近一个月',
|
||
onClick(picker) {
|
||
const end = new Date();
|
||
const start = new Date();
|
||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
|
||
picker.$emit('pick', [start, end]);
|
||
}
|
||
}, {
|
||
text: '最近三个月',
|
||
onClick(picker) {
|
||
const end = new Date();
|
||
const start = new Date();
|
||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
|
||
picker.$emit('pick', [start, end]);
|
||
}
|
||
}]
|
||
},
|
||
value1: '',
|
||
value2: '',
|
||
value3: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
|
||
value4: '',
|
||
value5: '',
|
||
value6: '',
|
||
value7: '',
|
||
value8: '',
|
||
value9: '',
|
||
value10: '',
|
||
value11: '',
|
||
value12: '',
|
||
value13: '',
|
||
value14: '',
|
||
value15: '',
|
||
value16: ''
|
||
};
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style>
|
||
.demo-block.demo-datetime-picker .source {
|
||
padding: 0;
|
||
display: flex;
|
||
}
|
||
|
||
.demo-datetime-picker .block {
|
||
padding: 30px 0;
|
||
text-align: center;
|
||
border-right: solid 1px #EFF2F6;
|
||
flex: 1;
|
||
&:last-child {
|
||
border-right: none;
|
||
}
|
||
}
|
||
|
||
.demo-datetime-picker .demonstration {
|
||
display: block;
|
||
color: #8492a6;
|
||
font-size: 14px;
|
||
margin-bottom: 20px;
|
||
}
|
||
</style>
|
||
|
||
## DateTimePicker 日期时间选择器
|
||
|
||
在同一个选择器里选择日期和时间
|
||
|
||
### 日期和时间点
|
||
|
||
:::demo 通过设置`type`属性为`datetime`,即可在同一个选择器里同时进行日期和时间的选择。快捷选项的使用方法与 Date Picker 相同。
|
||
```html
|
||
<template>
|
||
<div class="block">
|
||
<span class="demonstration">默认</span>
|
||
<el-date-picker
|
||
v-model="value1"
|
||
type="datetime"
|
||
placeholder="选择日期时间">
|
||
</el-date-picker>
|
||
</div>
|
||
<div class="block">
|
||
<span class="demonstration">带快捷选项</span>
|
||
<el-date-picker
|
||
v-model="value2"
|
||
type="datetime"
|
||
placeholder="选择日期时间"
|
||
align="right"
|
||
:picker-options="pickerOptions1">
|
||
</el-date-picker>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
pickerOptions1: {
|
||
shortcuts: [{
|
||
text: '今天',
|
||
onClick(picker) {
|
||
picker.$emit('pick', new Date());
|
||
}
|
||
}, {
|
||
text: '昨天',
|
||
onClick(picker) {
|
||
const date = new Date();
|
||
date.setTime(date.getTime() - 3600 * 1000 * 24);
|
||
picker.$emit('pick', date);
|
||
}
|
||
}, {
|
||
text: '一周前',
|
||
onClick(picker) {
|
||
const date = new Date();
|
||
date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
|
||
picker.$emit('pick', date);
|
||
}
|
||
}]
|
||
},
|
||
value1: '',
|
||
value2: ''
|
||
};
|
||
}
|
||
};
|
||
</script>
|
||
```
|
||
:::
|
||
|
||
### 日期和时间范围
|
||
|
||
:::demo 设置`type`为`datetimerange`即可选择日期和时间范围
|
||
```html
|
||
<template>
|
||
<div class="block">
|
||
<span class="demonstration">默认</span>
|
||
<el-date-picker
|
||
v-model="value3"
|
||
type="datetimerange"
|
||
placeholder="选择时间范围">
|
||
</el-date-picker>
|
||
</div>
|
||
<div class="block">
|
||
<span class="demonstration">带快捷选项</span>
|
||
<el-date-picker
|
||
v-model="value4"
|
||
type="datetimerange"
|
||
:picker-options="pickerOptions2"
|
||
placeholder="选择时间范围"
|
||
align="right">
|
||
</el-date-picker>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
pickerOptions2: {
|
||
shortcuts: [{
|
||
text: '最近一周',
|
||
onClick(picker) {
|
||
const end = new Date();
|
||
const start = new Date();
|
||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
|
||
picker.$emit('pick', [start, end]);
|
||
}
|
||
}, {
|
||
text: '最近一个月',
|
||
onClick(picker) {
|
||
const end = new Date();
|
||
const start = new Date();
|
||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
|
||
picker.$emit('pick', [start, end]);
|
||
}
|
||
}, {
|
||
text: '最近三个月',
|
||
onClick(picker) {
|
||
const end = new Date();
|
||
const start = new Date();
|
||
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
|
||
picker.$emit('pick', [start, end]);
|
||
}
|
||
}]
|
||
},
|
||
value3: [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)],
|
||
value4: ''
|
||
};
|
||
}
|
||
};
|
||
</script>
|
||
```
|
||
:::
|
||
|
||
### Attributes
|
||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
||
| readonly | 完全只读 | boolean | — | false |
|
||
| disabled | 禁用 | boolean | — | false |
|
||
| editable | 文本框可输入 | boolean | — | true |
|
||
| clearable | 是否显示清除按钮 | boolean | — | true |
|
||
| size | 输入框尺寸 | string | large, small, mini | — |
|
||
| placeholder | 占位内容 | string | — | — |
|
||
| type | 显示类型 | string | year/month/date/week/ datetime/datetimerange/daterange | date |
|
||
| format | 时间日期格式化 | string | 年 `yyyy`,月 `MM`,日 `dd`,小时 `HH`,分 `mm`,秒 `ss` | yyyy-MM-dd |
|
||
| align | 对齐方式 | string | left, center, right | left |
|
||
| popper-class | DateTimePicker 下拉框的类名 | string | — | — |
|
||
| picker-options | 当前时间日期选择器特有的选项参考下表 | object | — | {} |
|
||
|
||
### Picker Options
|
||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
||
| shortcuts | 设置快捷选项,需要传入 { text, onClick } 对象用法参考 demo 或下表 | Object[] | — | — |
|
||
| disabledDate | 设置禁用状态,参数为当前日期,要求返回 Boolean | Function | — | — |
|
||
|
||
### Shortcuts
|
||
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|
||
|---------- |-------------- |---------- |-------------------------------- |-------- |
|
||
| text | 标题文本 | string | — | — |
|
||
| onClick | 选中后的回调函数,参数是 vm,可通过触发 'pick' 事件设置选择器的值。例如 vm.$emit('pick', new Date()) | function | — | — |
|
||
|
||
|
||
### Events
|
||
| Event Name | Description | Parameters |
|
||
|---------|--------|---------|
|
||
| change | 当 input 的值改变时触发,返回值和文本框一致 | formatted value |
|
||
|
||
|