Skip to content

Commit b37d771

Browse files
committed
feat: 新增 自定义重要节日
1 parent 68db579 commit b37d771

File tree

6 files changed

+47
-10
lines changed

6 files changed

+47
-10
lines changed

src/components/date-picker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- [x] 年月选择器
77
- [x] 自定义日期格式
88
- [x] 公历节日
9-
- [ ] 自定义重要日子
9+
- [x] 自定义重要日子
1010
- [ ] 限制可选日期
1111
- [ ] 限制日期前后几天
1212
- [ ] 日期多选

src/components/date-picker/src/content/date-table.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
>
3030
<span
3131
:class="{
32-
'laydate-day-mark': festival && date.festival
32+
'laydate-day-mark': (festival || importantDays) && date.festival
3333
}"
34-
>{{ festival && date.festival || date.day }}</span>
34+
>{{ (festival || importantDays) && date.festival || date.day }}</span>
3535
</td>
3636
</tr>
3737
</tbody>
@@ -56,7 +56,11 @@ export default {
5656
type: Number,
5757
required: true
5858
},
59-
festival: Boolean
59+
festival: Boolean,
60+
importantDays: {
61+
type: Object,
62+
default: () => {}
63+
}
6064
},
6165
data () {
6266
return {
@@ -125,9 +129,8 @@ export default {
125129
month: _month,
126130
day: _day,
127131
key: `${_year}/${_month + 1}/${_day}`,
128-
festival: this.festival ? getFestival(_month, _day) : ''
132+
festival: this.festival || this.importantDays ? getFestival(_month, _day, this.importantDays) : ''
129133
});
130-
131134
}
132135
this.days = _days;
133136
},

src/components/date-picker/src/date-picker.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export default {
5656
default: 0
5757
},
5858
number: Boolean,
59-
festival: Boolean
59+
festival: Boolean,
60+
importantDays: {
61+
type: Object,
62+
default: () => {}
63+
}
6064
},
6165
destroyed () {
6266
this.handleHide();
@@ -76,6 +80,7 @@ export default {
7680
this.main.$props.type = this.type;
7781
this.main.$props.format = this.format;
7882
this.main.$props.festival = this.festival;
83+
this.main.$props.importantDays = this.importantDays;
7984
this.main.$mount();
8085
this.main.$on('change', this.emitChange);
8186
this.main.$on('close', () => {

src/components/date-picker/src/main/index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
:month="selectedMonth"
1717
:day="selectedDay"
1818
:festival="festival"
19+
:important-days="importantDays"
1920
@change="handerDateTableChange"
2021
/>
2122
<month-table
@@ -86,7 +87,11 @@ export default {
8687
type: String,
8788
default: ''
8889
},
89-
festival: Boolean
90+
festival: Boolean,
91+
importantDays: {
92+
type: Object,
93+
default: () => {}
94+
}
9095
},
9196
data () {
9297
return {

src/components/date-picker/src/utils/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
2+
// TODO: 待补充,按招 https://github.com/sentsin/laydate/blob/master/src/laydate.js
23
const FESTIVAL = {
34
'1-1': '元旦',
45
'2-14': '情人节',
@@ -40,7 +41,7 @@ export const getPrevDaysInMonth = (year, month) => {
4041
return getDaysInMonth(year, month);
4142
};
4243

43-
// 获得公历节日
44+
// 获得公历节日和自定义节日
4445
export const getFestival = (month, day, festival = FESTIVAL) => {
4546
return festival[`${month + 1}-${day}`];
4647
};

src/views/DatePicker.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
format="YYYY年MM月DD日"
2929
placeholder="节日">
3030
</lay-date-picker>
31+
<lay-date-picker
32+
v-model="value6"
33+
format="YYYY年MM月DD日"
34+
:important-days="importantDays"
35+
placeholder="自定义重要日子">
36+
</lay-date-picker>
37+
38+
3139

3240
<script>
3341
export default {
@@ -38,7 +46,22 @@ export default {
3846
value2: '',
3947
value3: '',
4048
value4: '',
41-
value5: ''
49+
value5: '',
50+
value6: '',
51+
importantDays: {
52+
'1-10': '测试',
53+
'2-11': '测试',
54+
'3-12': '测试',
55+
'4-13': '测试',
56+
'5-14': '测试',
57+
'6-15': '测试',
58+
'7-16': '测试',
59+
'8-17': '测试',
60+
'9-18': '测试',
61+
'10-19': '测试',
62+
'11-9': '测试',
63+
'12-8': '测试'
64+
}
4265
}
4366
}
4467
};

0 commit comments

Comments
 (0)