mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-10 14:59:46 +08:00
feat(Calendar): add popable prop
This commit is contained in:
parent
f49c21a7ca
commit
39179c2336
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### 介绍
|
### 介绍
|
||||||
|
|
||||||
日历组件用于选择日期或日期区间,可以与 [弹出层](#/zh-CN/popup)、[单元格](#/zh-CN/cell)、[输入框](#/zh-CN/field) 等组件配合使用
|
日历组件用于选择日期或日期区间
|
||||||
|
|
||||||
### 引入
|
### 引入
|
||||||
|
|
||||||
@ -17,26 +17,19 @@ Vue.use(Calendar);
|
|||||||
|
|
||||||
### 选择单个日期
|
### 选择单个日期
|
||||||
|
|
||||||
下面演示了结合单元格、弹出层来使用日历组件的用法。
|
下面演示了结合单元格来使用日历组件的用法,点击单元格后唤起日历组件。
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<!-- 点击单元格后唤起日历组件 -->
|
|
||||||
<van-cell
|
<van-cell
|
||||||
title="选择单个日期"
|
title="选择单个日期"
|
||||||
:value="selectedDate"
|
:value="selectedDate"
|
||||||
@click="showCalendar = true"
|
@click="showCalendar = true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 使用弹出层组件作为日历的容器 -->
|
<van-calendar
|
||||||
<van-popup
|
|
||||||
v-model="showCalendar"
|
v-model="showCalendar"
|
||||||
round
|
@select="onSelect"
|
||||||
closeable
|
/>
|
||||||
position="bottom"
|
|
||||||
style="height: 80vh;"
|
|
||||||
>
|
|
||||||
<van-calendar @select="onSelect" />
|
|
||||||
</van-popup>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -87,6 +80,7 @@ export default {
|
|||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
|
| v-model | 是否显示日历弹窗 | *boolean* | `false` | - |
|
||||||
| type | 选择类型,`single`表示选择单个日期,<br>`range`表示选择日期区间 | *string* | `single` | - |
|
| type | 选择类型,`single`表示选择单个日期,<br>`range`表示选择日期区间 | *string* | `single` | - |
|
||||||
| title | 日历标题 | *string* | `日期选择` | - |
|
| title | 日历标题 | *string* | `日期选择` | - |
|
||||||
| min-date | 最小日期 | *Date* | 当前日期 | - |
|
| min-date | 最小日期 | *Date* | 当前日期 | - |
|
||||||
@ -95,6 +89,7 @@ export default {
|
|||||||
| row-height | 日期所在行的高度 | *number* | `64` | - |
|
| row-height | 日期所在行的高度 | *number* | `64` | - |
|
||||||
| button-text | 确认按钮的文字 | *string* | `确定` | - |
|
| button-text | 确认按钮的文字 | *string* | `确定` | - |
|
||||||
| button-disabled-text | 确认按钮处于禁用状态时的文字 | *string* | `确定` | - |
|
| button-disabled-text | 确认按钮处于禁用状态时的文字 | *string* | `确定` | - |
|
||||||
|
| poppable | 是否以弹层的形式展示日历 | *boolean* | `true` | - |
|
||||||
| show-mark | 是否显示月份背景水印 | *boolean* | `true` | - |
|
| show-mark | 是否显示月份背景水印 | *boolean* | `true` | - |
|
||||||
| safe-area-inset-bottom | 是否开启底部安全区适配,[详细说明](#/zh-CN/quickstart#di-bu-an-quan-qu-gua-pei) | *boolean* | `true` | - |
|
| safe-area-inset-bottom | 是否开启底部安全区适配,[详细说明](#/zh-CN/quickstart#di-bu-an-quan-qu-gua-pei) | *boolean* | `true` | - |
|
||||||
|
|
||||||
|
@ -8,15 +8,11 @@
|
|||||||
@click="toggle('selectSingleDate', true)"
|
@click="toggle('selectSingleDate', true)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<van-popup
|
<van-calendar
|
||||||
v-model="show.selectSingleDate"
|
v-model="show.selectSingleDate"
|
||||||
round
|
:poppable="false"
|
||||||
closeable
|
@select="onSelect($event, 'selectSingleDate')"
|
||||||
position="bottom"
|
/>
|
||||||
style="height: 80vh;"
|
|
||||||
>
|
|
||||||
<van-calendar @select="onSelect($event, 'selectSingleDate')" />
|
|
||||||
</van-popup>
|
|
||||||
|
|
||||||
<van-cell
|
<van-cell
|
||||||
is-link
|
is-link
|
||||||
@ -25,18 +21,11 @@
|
|||||||
@click="toggle('selectDateRange', true)"
|
@click="toggle('selectDateRange', true)"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<van-popup
|
|
||||||
v-model="show.selectDateRange"
|
|
||||||
round
|
|
||||||
closeable
|
|
||||||
position="bottom"
|
|
||||||
style="height: 80vh;"
|
|
||||||
>
|
|
||||||
<van-calendar
|
<van-calendar
|
||||||
|
v-model="show.selectDateRange"
|
||||||
type="range"
|
type="range"
|
||||||
@select="onSelect($event, 'selectDateRange')"
|
@select="onSelect($event, 'selectDateRange')"
|
||||||
/>
|
/>
|
||||||
</van-popup>
|
|
||||||
</demo-block>
|
</demo-block>
|
||||||
</demo-section>
|
</demo-section>
|
||||||
</template>
|
</template>
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
RENDER_OFFSET
|
RENDER_OFFSET
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
|
import Popup from '../popup';
|
||||||
import Button from '../button';
|
import Button from '../button';
|
||||||
import Month from './components/Month';
|
import Month from './components/Month';
|
||||||
import Header from './components/Header';
|
import Header from './components/Header';
|
||||||
@ -18,6 +19,7 @@ import Header from './components/Header';
|
|||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
title: String,
|
title: String,
|
||||||
|
value: Boolean,
|
||||||
buttonText: String,
|
buttonText: String,
|
||||||
defaultDate: [Date, Array],
|
defaultDate: [Date, Array],
|
||||||
buttonDisabledText: String,
|
buttonDisabledText: String,
|
||||||
@ -42,6 +44,10 @@ export default createComponent({
|
|||||||
type: Number,
|
type: Number,
|
||||||
default: ROW_HEIGHT
|
default: ROW_HEIGHT
|
||||||
},
|
},
|
||||||
|
poppable: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
|
},
|
||||||
showMark: {
|
showMark: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
@ -76,17 +82,31 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
value(val) {
|
||||||
|
if (val) {
|
||||||
|
this.initRect();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
defaultDate(val) {
|
defaultDate(val) {
|
||||||
this.currentDate = val;
|
this.currentDate = val;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.bodyHeight = this.$refs.body.getBoundingClientRect().height;
|
if (!this.poppable) {
|
||||||
this.onScroll();
|
this.initRect();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
initRect() {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.bodyHeight = this.$refs.body.getBoundingClientRect().height;
|
||||||
|
this.onScroll();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getInitialDate() {
|
getInitialDate() {
|
||||||
const { type, defaultDate, minDate } = this;
|
const { type, defaultDate, minDate } = this;
|
||||||
|
|
||||||
@ -155,6 +175,10 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
togglePopup(val) {
|
||||||
|
this.$emit('input', val);
|
||||||
|
},
|
||||||
|
|
||||||
onConfirmRange() {
|
onConfirmRange() {
|
||||||
this.$emit('select', this.currentDate);
|
this.$emit('select', this.currentDate);
|
||||||
},
|
},
|
||||||
@ -213,10 +237,9 @@ export default createComponent({
|
|||||||
{this.genFooterContent()}
|
{this.genFooterContent()}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
genCalendar() {
|
||||||
return (
|
return (
|
||||||
<div class={bem()}>
|
<div class={bem()}>
|
||||||
<Header
|
<Header
|
||||||
@ -233,4 +256,24 @@ export default createComponent({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
if (this.poppable) {
|
||||||
|
return (
|
||||||
|
<Popup
|
||||||
|
round
|
||||||
|
closeable
|
||||||
|
value={this.value}
|
||||||
|
position="bottom"
|
||||||
|
class={bem('popup')}
|
||||||
|
onInput={this.togglePopup}
|
||||||
|
>
|
||||||
|
{this.genCalendar()}
|
||||||
|
</Popup>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.genCalendar();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,11 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
background-color: @white;
|
||||||
|
|
||||||
|
&__popup {
|
||||||
|
height: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
&__header {
|
&__header {
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user