diff --git a/packages/vant-cli/site/desktop/components/Container.vue b/packages/vant-cli/site/desktop/components/Container.vue
index 115adc150..86313a5ef 100644
--- a/packages/vant-cli/site/desktop/components/Container.vue
+++ b/packages/vant-cli/site/desktop/components/Container.vue
@@ -27,10 +27,6 @@ export default {
&--with-simulator {
padding-right: @van-doc-simulator-width + @van-doc-padding;
-
- @media (max-width: 1300px) {
- padding-right: @van-doc-simulator-small-width + @van-doc-padding;
- }
}
}
diff --git a/packages/vant-cli/site/desktop/components/Simulator.vue b/packages/vant-cli/site/desktop/components/Simulator.vue
index 50b4a8e38..0c59bf225 100644
--- a/packages/vant-cli/site/desktop/components/Simulator.vue
+++ b/packages/vant-cli/site/desktop/components/Simulator.vue
@@ -59,11 +59,6 @@ export default {
border-radius: 6px;
box-shadow: #ebedf0 0 4px 12px;
- @media (max-width: 1300px) {
- width: @van-doc-simulator-small-width;
- min-width: @van-doc-simulator-small-width;
- }
-
@media (max-width: 1100px) {
right: auto;
left: 750px;
diff --git a/src/calendar/README.zh-CN.md b/src/calendar/README.zh-CN.md
index 43df76f75..613c4c94b 100644
--- a/src/calendar/README.zh-CN.md
+++ b/src/calendar/README.zh-CN.md
@@ -120,6 +120,60 @@ export default {
/>
```
+### 自定义日期文案
+
+通过传入`formatter`函数来对日历上每一格的内容进行格式化
+
+```html
+
+```
+
+```js
+export default {
+ methods: {
+ formatter(day) {
+ const month = day.date.getMonth();
+ const date = day.date.getDate();
+
+ if (month === 4) {
+ if (date === 1) {
+ day.topInfo = '劳动节';
+ } else if (date === 4) {
+ day.topInfo = '五四青年节';
+ } else if (date === 11) {
+ day.text = '今天';
+ }
+ }
+
+ if (day.type === 'start') {
+ day.bottomInfo = '入住';
+ } else if (day.type === 'end') {
+ day.bottomInfo = '离店';
+ }
+
+ return day;
+ }
+ }
+}
+```
+
+### 平铺展示
+
+将`poppable`设置为`false`,日历会直接展示在页面内,而不是以弹层的形式出现
+
+```html
+
+```
+
## API
### Props
@@ -133,6 +187,7 @@ export default {
| max-date | 最大日期 | *Date* | 当前日期的六个月后 | - |
| default-date | 默认选中的日期 | *Date \| Date[]* | 今天 | - |
| row-height | 日期行高 | *number* | `64` | - |
+| formatter | 日期格式化函数 | *(day: Day) => Day* | - | - |
| poppable | 是否以弹层的形式展示日历 | *boolean* | `true` | - |
| show-mark | 是否显示月份背景水印 | *boolean* | `true` | - |
| show-confirm | 是否展示确认按钮 | *boolean* | `true` | - |
@@ -140,6 +195,19 @@ export default {
| confirm-text | 确认按钮的文字 | *string* | `确定` | - |
| confirm-disabled-text | 确认按钮处于禁用状态时的文字 | *string* | `确定` | - |
+### Day 数据结构
+
+日历中的每个日期都对应一个 Day 对象,通过`formatter`属性可以自定义 Day 对象的内容
+
+| 键名 | 说明 | 类型 |
+|------|------|------|
+| date | 日期对应的 Date 对象 | *Date* |
+| type | 日期类型,可选值为`selected`、`start`、`middle`、`end`、`disabled` | *string* |
+| text | 中间显示的文字 | *string* |
+| topInfo | 上方的提示信息 | *string* |
+| bottomInfo | 下方的提示信息 | *string* |
+| className | 额外类名 | *string* |
+
### Events
| 事件名 | 说明 | 回调参数 |
diff --git a/src/calendar/components/Month.js b/src/calendar/components/Month.js
index 4cbd844ac..41497dfd8 100644
--- a/src/calendar/components/Month.js
+++ b/src/calendar/components/Month.js
@@ -13,6 +13,7 @@ export default createComponent({
showMark: Boolean,
showTitle: Boolean,
rowHeight: Number,
+ formatter: Function,
currentDate: [Date, Array]
},
@@ -56,14 +57,22 @@ export default createComponent({
const year = this.date.getFullYear();
const month = this.date.getMonth();
- for (let i = 1; i <= this.totalDay; i++) {
- const date = new Date(year, month, i);
+ for (let day = 1; day <= this.totalDay; day++) {
+ const date = new Date(year, month, day);
+ const type = this.getDayType(date);
- days.push({
- day: i,
+ let config = {
date,
- type: this.getDayType(date)
- });
+ type,
+ text: day,
+ bottomInfo: this.getBottomInfo(type)
+ };
+
+ if (this.formatter) {
+ config = this.formatter(config);
+ }
+
+ days.push(config);
}
return days;
@@ -113,12 +122,12 @@ export default createComponent({
}
},
- getLabel(item) {
- if (item.type === 'start') {
+ getBottomInfo(type) {
+ if (type === 'start') {
return t('start');
}
- if (item.type === 'end') {
+ if (type === 'end') {
return t('end');
}
},
@@ -161,7 +170,7 @@ export default createComponent({
},
genDay(item, index) {
- const { type } = item;
+ const { type, topInfo, bottomInfo } = item;
const style = this.getDayStyle(index);
const onClick = () => {
@@ -173,18 +182,26 @@ export default createComponent({
if (type === 'selected') {
return (
-
{item.day}
+
{item.text}
);
}
- const label = this.getLabel(item);
- const Label = label && {label}
;
+ const TopInfo = topInfo && {topInfo}
;
+
+ const BottomInfo = bottomInfo && (
+ {bottomInfo}
+ );
return (
-
- {item.day}
- {Label}
+
+ {TopInfo}
+ {item.text}
+ {BottomInfo}
);
}
diff --git a/src/calendar/demo/index.vue b/src/calendar/demo/index.vue
index e1769345a..4f13b9216 100644
--- a/src/calendar/demo/index.vue
+++ b/src/calendar/demo/index.vue
@@ -46,6 +46,22 @@
:value="formatRange(date.customConfirm)"
@click="show('range', 'customConfirm')"
/>
+
+
+
+
+
+