npmapps 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/app/calendar/README.md +329 -0
- package/app/calendar/customCalendar.vue +327 -0
- package/app/calendar/data.js +177 -0
- package/app/calendar/index.vue +116 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# Vue 年度日历组件
|
|
2
|
+
|
|
3
|
+
基于 Element UI Calendar 组件封装的年度日历组件,支持按年份查看所有月份的日历,并具有节假日显示、今日标记等功能。
|
|
4
|
+
|
|
5
|
+
## 功能特点
|
|
6
|
+
|
|
7
|
+
- 年度视图:一次性展示全年12个月的日历
|
|
8
|
+
- 节假日标记:支持显示法定节假日和调休工作日
|
|
9
|
+
- 今日标记:突出显示当前日期
|
|
10
|
+
- 日期选择:支持点击选择具体日期
|
|
11
|
+
- 响应式布局:自适应不同屏幕尺寸
|
|
12
|
+
- 优雅动效:悬浮效果和过渡动画
|
|
13
|
+
- 农历日期:支持显示农历日期信息
|
|
14
|
+
- 自定义样式:提供丰富的样式定制选项
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# 确保已安装Element UI
|
|
20
|
+
npm install element-ui --save
|
|
21
|
+
|
|
22
|
+
# 复制组件到你的项目中
|
|
23
|
+
cp -r calendar/ src/components/
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 使用方法
|
|
27
|
+
|
|
28
|
+
### 基础用法
|
|
29
|
+
|
|
30
|
+
最简单的使用方式,仅显示日历并处理日期点击事件:
|
|
31
|
+
|
|
32
|
+
```vue
|
|
33
|
+
<template>
|
|
34
|
+
<calendar @date-click="handleDateClick" />
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script>
|
|
38
|
+
import calendar from '@/components/calendar/index.vue'
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
components: {
|
|
42
|
+
calendar
|
|
43
|
+
},
|
|
44
|
+
methods: {
|
|
45
|
+
handleDateClick(date) {
|
|
46
|
+
console.log('选择的日期:', date)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 自定义节假日
|
|
54
|
+
|
|
55
|
+
使用自定义节假日数据,实现节假日和调休日的显示:
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<template>
|
|
59
|
+
<calendar
|
|
60
|
+
:holiday="holidayData"
|
|
61
|
+
@date-click="handleDateClick"
|
|
62
|
+
/>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<script>
|
|
66
|
+
import calendar from '@/components/calendar/index.vue'
|
|
67
|
+
|
|
68
|
+
export default {
|
|
69
|
+
components: {
|
|
70
|
+
calendar
|
|
71
|
+
},
|
|
72
|
+
data() {
|
|
73
|
+
return {
|
|
74
|
+
holidayData: [
|
|
75
|
+
{
|
|
76
|
+
type: 'holiday',
|
|
77
|
+
name: '元旦',
|
|
78
|
+
date: '2024-01-01',
|
|
79
|
+
lunarDate: '腊月十一'
|
|
80
|
+
},
|
|
81
|
+
// 更多节假日数据...
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
methods: {
|
|
86
|
+
handleDateClick(date) {
|
|
87
|
+
this.$message.success(`选择的日期:${date.day}`)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
</script>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 高级配置
|
|
95
|
+
|
|
96
|
+
展示如何使用更多配置选项来自定义日历的行为和外观:
|
|
97
|
+
|
|
98
|
+
```vue
|
|
99
|
+
<template>
|
|
100
|
+
<calendar
|
|
101
|
+
:holiday="holidayData"
|
|
102
|
+
:showWorkday="true"
|
|
103
|
+
:showToday="true"
|
|
104
|
+
:clickable="true"
|
|
105
|
+
:isNextOrPrevClick="false"
|
|
106
|
+
@date-click="handleDateClick"
|
|
107
|
+
>
|
|
108
|
+
<template #year-picker>
|
|
109
|
+
<div class="custom-year-picker">
|
|
110
|
+
<el-button @click="prevYear">上一年</el-button>
|
|
111
|
+
<span>{{ currentYear }}年</span>
|
|
112
|
+
<el-button @click="nextYear">下一年</el-button>
|
|
113
|
+
</div>
|
|
114
|
+
</template>
|
|
115
|
+
</calendar>
|
|
116
|
+
</template>
|
|
117
|
+
|
|
118
|
+
<script>
|
|
119
|
+
import calendar from '@/components/calendar/index.vue'
|
|
120
|
+
|
|
121
|
+
export default {
|
|
122
|
+
components: {
|
|
123
|
+
calendar
|
|
124
|
+
},
|
|
125
|
+
data() {
|
|
126
|
+
return {
|
|
127
|
+
currentYear: new Date().getFullYear(),
|
|
128
|
+
holidayData: []
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
methods: {
|
|
132
|
+
handleDateClick(date) {
|
|
133
|
+
this.$message.success(`选择的日期:${date.day}`)
|
|
134
|
+
},
|
|
135
|
+
prevYear() {
|
|
136
|
+
this.currentYear--
|
|
137
|
+
},
|
|
138
|
+
nextYear() {
|
|
139
|
+
this.currentYear++
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
</script>
|
|
144
|
+
|
|
145
|
+
<style scoped>
|
|
146
|
+
.custom-year-picker {
|
|
147
|
+
display: flex;
|
|
148
|
+
justify-content: center;
|
|
149
|
+
align-items: center;
|
|
150
|
+
gap: 10px;
|
|
151
|
+
margin-bottom: 20px;
|
|
152
|
+
}
|
|
153
|
+
</style>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## 组件 API
|
|
157
|
+
|
|
158
|
+
### Calendar Props
|
|
159
|
+
|
|
160
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
161
|
+
|------|------|------|--------|
|
|
162
|
+
| year | 当前显示的年份 | Date | new Date() |
|
|
163
|
+
| holiday | 节假日数据 | Array | [] |
|
|
164
|
+
| showWorkday | 是否显示工作日标记 | Boolean | true |
|
|
165
|
+
| showToday | 是否显示今日标记 | Boolean | true |
|
|
166
|
+
| clickable | 是否允许点击日期 | Boolean | true |
|
|
167
|
+
| isNextOrPrevClick | 是否禁用上下月份日期点击 | Boolean | false |
|
|
168
|
+
|
|
169
|
+
### Calendar Events
|
|
170
|
+
|
|
171
|
+
| 事件名 | 说明 | 回调参数 |
|
|
172
|
+
|--------|------|----------|
|
|
173
|
+
| date-click | 点击日期时触发 | data: { day: 'YYYY-MM-DD' } |
|
|
174
|
+
| year-change | 年份变化时触发 | year: Number |
|
|
175
|
+
|
|
176
|
+
### Calendar Slots
|
|
177
|
+
|
|
178
|
+
| 插槽名 | 说明 |
|
|
179
|
+
|--------|------|
|
|
180
|
+
| year-picker | 自定义年份选择器 |
|
|
181
|
+
| date-cell | 自定义日期单元格内容 |
|
|
182
|
+
|
|
183
|
+
### 节假日数据格式
|
|
184
|
+
|
|
185
|
+
```javascript
|
|
186
|
+
{
|
|
187
|
+
type: 'holiday', // 类型:holiday-节假日,workday-调休工作日
|
|
188
|
+
name: '春节', // 节日名称
|
|
189
|
+
date: '2024-02-10', // 日期,格式:YYYY-MM-DD
|
|
190
|
+
lunarDate: '正月初一' // 农历日期(可选)
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## 样式定制
|
|
195
|
+
|
|
196
|
+
### 基础样式覆盖
|
|
197
|
+
|
|
198
|
+
```css
|
|
199
|
+
/* 日历容器 */
|
|
200
|
+
.calendar-container {
|
|
201
|
+
padding: 20px;
|
|
202
|
+
background: #fff;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* 年份选择器 */
|
|
206
|
+
.year-picker {
|
|
207
|
+
margin-bottom: 20px;
|
|
208
|
+
text-align: center;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* 月份网格 */
|
|
212
|
+
.calendar-grid {
|
|
213
|
+
display: grid;
|
|
214
|
+
grid-template-columns: repeat(auto-fill, minmax(300px, 500px));
|
|
215
|
+
gap: 50px;
|
|
216
|
+
justify-content: center;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/* 单个月份容器 */
|
|
220
|
+
.calendar-item {
|
|
221
|
+
background-color: #fff;
|
|
222
|
+
border-radius: 8px;
|
|
223
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
|
224
|
+
transition: all 0.3s ease;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* 日期单元格 */
|
|
228
|
+
.calendar-cell {
|
|
229
|
+
height: 100%;
|
|
230
|
+
padding: 8px;
|
|
231
|
+
cursor: pointer;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* 今日标记 */
|
|
235
|
+
.today-mark {
|
|
236
|
+
background-color: #409EFF;
|
|
237
|
+
color: #fff;
|
|
238
|
+
border-radius: 50%;
|
|
239
|
+
padding: 2px;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/* 节假日信息 */
|
|
243
|
+
.holiday-info {
|
|
244
|
+
font-size: 12px;
|
|
245
|
+
color: #E6A23C;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### 主题定制
|
|
250
|
+
|
|
251
|
+
可以通过修改CSS变量来快速更改主题色:
|
|
252
|
+
|
|
253
|
+
```css
|
|
254
|
+
:root {
|
|
255
|
+
--calendar-primary-color: #409EFF;
|
|
256
|
+
--calendar-holiday-color: #E6A23C;
|
|
257
|
+
--calendar-workday-color: #67C23A;
|
|
258
|
+
--calendar-text-color: #303133;
|
|
259
|
+
--calendar-border-radius: 8px;
|
|
260
|
+
--calendar-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## 注意事项
|
|
265
|
+
|
|
266
|
+
1. 确保项目中已正确安装并配置 Element UI
|
|
267
|
+
2. 节假日数据需要按照指定格式提供,建议使用专门的节假日API或数据服务
|
|
268
|
+
3. 组件使用响应式布局,会根据屏幕尺寸自动调整显示方式
|
|
269
|
+
4. 如需禁用某些日期的选择,可以通过传入disabledDate函数来实现
|
|
270
|
+
5. 农历日期显示为可选功能,需要额外的农历转换库支持
|
|
271
|
+
|
|
272
|
+
## 常见问题
|
|
273
|
+
|
|
274
|
+
### Q: 如何禁用特定日期?
|
|
275
|
+
|
|
276
|
+
```vue
|
|
277
|
+
<template>
|
|
278
|
+
<calendar :disabled-date="disabledDate" />
|
|
279
|
+
</template>
|
|
280
|
+
|
|
281
|
+
<script>
|
|
282
|
+
export default {
|
|
283
|
+
methods: {
|
|
284
|
+
disabledDate(date) {
|
|
285
|
+
return date.getTime() < Date.now() - 8.64e7; // 禁用今天之前的日期
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
</script>
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Q: 如何自定义日期单元格的内容?
|
|
293
|
+
|
|
294
|
+
```vue
|
|
295
|
+
<template>
|
|
296
|
+
<calendar>
|
|
297
|
+
<template #date-cell="{ date, data }">
|
|
298
|
+
<div class="custom-cell">
|
|
299
|
+
<span>{{ data.day.split('-')[2] }}</span>
|
|
300
|
+
<small>{{ getCustomContent(date) }}</small>
|
|
301
|
+
</div>
|
|
302
|
+
</template>
|
|
303
|
+
</calendar>
|
|
304
|
+
</template>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Q: 如何添加自定义事件标记?
|
|
308
|
+
|
|
309
|
+
```vue
|
|
310
|
+
<template>
|
|
311
|
+
<calendar :events="eventList" />
|
|
312
|
+
</template>
|
|
313
|
+
|
|
314
|
+
<script>
|
|
315
|
+
export default {
|
|
316
|
+
data() {
|
|
317
|
+
return {
|
|
318
|
+
eventList: [
|
|
319
|
+
{
|
|
320
|
+
date: '2024-01-15',
|
|
321
|
+
type: 'meeting',
|
|
322
|
+
content: '项目会议'
|
|
323
|
+
}
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
</script>
|
|
329
|
+
```
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-calendar
|
|
3
|
+
v-model="value"
|
|
4
|
+
:class="[
|
|
5
|
+
{ 'hide-button-group': !showButtonGroup },
|
|
6
|
+
{ 'next-or-prev-click': !isNextOrPrevClick },
|
|
7
|
+
]"
|
|
8
|
+
:first-day-of-week="7"
|
|
9
|
+
>
|
|
10
|
+
<template slot="dateCell" slot-scope="{ date, data }">
|
|
11
|
+
<div
|
|
12
|
+
:class="[
|
|
13
|
+
'calendar-cell',
|
|
14
|
+
handleClass(date, data),
|
|
15
|
+
{ selected: isSelected(data.day) },
|
|
16
|
+
]"
|
|
17
|
+
@click="handleDateClick(data)"
|
|
18
|
+
>
|
|
19
|
+
<div class="date">
|
|
20
|
+
{{ parseInt(data.day.split("-")[2]) }}
|
|
21
|
+
<span v-if="isToday(data.day)" class="today-mark">今</span>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="holiday-info">{{ getHolidayInfo(data.day) }}</div>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
</el-calendar>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
/**
|
|
31
|
+
* @description 自定义日历组件,基于Element UI的Calendar组件封装
|
|
32
|
+
* 支持节假日显示、今日标记、日期选择等功能
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* <custom-calendar
|
|
36
|
+
* :date="new Date()"
|
|
37
|
+
* :holiday="holidayList"
|
|
38
|
+
* @date-click="handleDateClick"
|
|
39
|
+
* />
|
|
40
|
+
*/
|
|
41
|
+
export default {
|
|
42
|
+
data() {
|
|
43
|
+
return {
|
|
44
|
+
value: this.date,
|
|
45
|
+
selectedDate: null,
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
props: {
|
|
49
|
+
/**
|
|
50
|
+
* 日历当前显示的日期
|
|
51
|
+
* @type {Date}
|
|
52
|
+
* @default new Date()
|
|
53
|
+
*/
|
|
54
|
+
date: {
|
|
55
|
+
type: Date,
|
|
56
|
+
default: () => new Date(),
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* 是否显示日历顶部的按钮组(上个月、下个月等)
|
|
60
|
+
* @type {Boolean}
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
showButtonGroup: {
|
|
64
|
+
type: Boolean,
|
|
65
|
+
default: true,
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* 是否显示工作日标记
|
|
69
|
+
* @type {Boolean}
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
showWorkday: {
|
|
73
|
+
type: Boolean,
|
|
74
|
+
default: true,
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* 节假日数据数组
|
|
78
|
+
* @type {Array<{date: string, type: string, name: string, lunarDate: string}>}
|
|
79
|
+
* @default []
|
|
80
|
+
*/
|
|
81
|
+
holiday: {
|
|
82
|
+
type: Array,
|
|
83
|
+
default: () => [],
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* 是否允许点击日期
|
|
87
|
+
* @type {Boolean}
|
|
88
|
+
* @default true
|
|
89
|
+
*/
|
|
90
|
+
clickable: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
default: true,
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* 是否显示今日标记
|
|
96
|
+
* @type {Boolean}
|
|
97
|
+
* @default true
|
|
98
|
+
*/
|
|
99
|
+
showToday: {
|
|
100
|
+
type: Boolean,
|
|
101
|
+
default: true,
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
isNextOrPrevClick: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: false,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
methods: {
|
|
110
|
+
/**
|
|
111
|
+
* 处理日期单元格的样式类
|
|
112
|
+
* @param {Date} date - 日期对象
|
|
113
|
+
* @param {Object} data - 日期数据对象
|
|
114
|
+
* @returns {string} 样式类名
|
|
115
|
+
*/
|
|
116
|
+
handleClass(date, data) {
|
|
117
|
+
let classes = [];
|
|
118
|
+
const d = this.holiday.find((item) => item.date === data.day);
|
|
119
|
+
if (d) {
|
|
120
|
+
classes.push(d.type);
|
|
121
|
+
}
|
|
122
|
+
if (this.showToday && this.isToday(data.day)) {
|
|
123
|
+
classes.push("is-today");
|
|
124
|
+
}
|
|
125
|
+
return classes.join(" ");
|
|
126
|
+
},
|
|
127
|
+
/**
|
|
128
|
+
* 获取农历日期
|
|
129
|
+
* @param {string} day - 日期字符串 (YYYY-MM-DD)
|
|
130
|
+
* @returns {string} 农历日期
|
|
131
|
+
*/
|
|
132
|
+
getLunarDate(day) {
|
|
133
|
+
const d = this.holiday.find((item) => item.date === day);
|
|
134
|
+
return d ? d.lunarDate : "";
|
|
135
|
+
},
|
|
136
|
+
/**
|
|
137
|
+
* 获取节假日信息
|
|
138
|
+
* @param {string} day - 日期字符串 (YYYY-MM-DD)
|
|
139
|
+
* @returns {string} 节假日名称或工作日标记
|
|
140
|
+
*/
|
|
141
|
+
getHolidayInfo(day) {
|
|
142
|
+
const d = this.holiday.find((item) => item.date === day);
|
|
143
|
+
if (d) {
|
|
144
|
+
return d.name;
|
|
145
|
+
}
|
|
146
|
+
return this.showWorkday ? "班" : "";
|
|
147
|
+
},
|
|
148
|
+
/**
|
|
149
|
+
* 处理日期点击事件
|
|
150
|
+
* @param {string} day - 日期字符串 (YYYY-MM-DD)
|
|
151
|
+
* @fires date-click
|
|
152
|
+
*/
|
|
153
|
+
handleDateClick(data) {
|
|
154
|
+
if (!this.clickable) return;
|
|
155
|
+
this.selectedDate = data.day;
|
|
156
|
+
this.$emit("date-click", data);
|
|
157
|
+
},
|
|
158
|
+
/**
|
|
159
|
+
* 判断日期是否被选中
|
|
160
|
+
* @param {string} day - 日期字符串 (YYYY-MM-DD)
|
|
161
|
+
* @returns {boolean} 是否选中
|
|
162
|
+
*/
|
|
163
|
+
isSelected(day) {
|
|
164
|
+
return this.selectedDate === day;
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* 判断是否为今天
|
|
168
|
+
* @param {string} day - 日期字符串 (YYYY-MM-DD)
|
|
169
|
+
* @returns {boolean} 是否为今天
|
|
170
|
+
*/
|
|
171
|
+
isToday(day) {
|
|
172
|
+
const today = new Date();
|
|
173
|
+
const year = today.getFullYear();
|
|
174
|
+
const month = String(today.getMonth() + 1).padStart(2, "0");
|
|
175
|
+
const date = String(today.getDate()).padStart(2, "0");
|
|
176
|
+
const todayStr = `${year}-${month}-${date}`;
|
|
177
|
+
return day === todayStr;
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
computed: {},
|
|
181
|
+
mounted() {},
|
|
182
|
+
};
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<style scoped>
|
|
186
|
+
.next-or-prev-click :deep(.el-calendar-table__row td.prev) {
|
|
187
|
+
pointer-events: none;
|
|
188
|
+
}
|
|
189
|
+
.next-or-prev-click :deep(.el-calendar-table__row td.next) {
|
|
190
|
+
pointer-events: none;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* 隐藏日历顶部按钮组 */
|
|
194
|
+
.hide-button-group :deep(.el-calendar__button-group) {
|
|
195
|
+
display: none;
|
|
196
|
+
}
|
|
197
|
+
/* 日历单元格基础样式 */
|
|
198
|
+
:deep(.el-calendar-day) {
|
|
199
|
+
height: 60px;
|
|
200
|
+
padding: 2px;
|
|
201
|
+
}
|
|
202
|
+
:deep(.el-calendar-day) /* 日历单元格容器样式 */
|
|
203
|
+
.calendar-cell {
|
|
204
|
+
height: 100%;
|
|
205
|
+
display: flex;
|
|
206
|
+
flex-direction: column;
|
|
207
|
+
align-items: center;
|
|
208
|
+
justify-content: space-between;
|
|
209
|
+
box-sizing: border-box;
|
|
210
|
+
padding: 2px !important;
|
|
211
|
+
}
|
|
212
|
+
/* 日期数字样式 */
|
|
213
|
+
.calendar-cell .date {
|
|
214
|
+
font-size: 16px;
|
|
215
|
+
font-weight: bold;
|
|
216
|
+
transition: transform 0.3s ease;
|
|
217
|
+
display: flex;
|
|
218
|
+
align-items: center;
|
|
219
|
+
justify-content: center;
|
|
220
|
+
gap: 2px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/* 今日标记样式 */
|
|
224
|
+
.calendar-cell .today-mark {
|
|
225
|
+
font-size: 12px;
|
|
226
|
+
color: #409eff;
|
|
227
|
+
font-weight: normal;
|
|
228
|
+
}
|
|
229
|
+
.calendar-cell:hover .date {
|
|
230
|
+
transform: scale(1.3);
|
|
231
|
+
}
|
|
232
|
+
/* 农历日期样式 */
|
|
233
|
+
.calendar-cell .lunar-date {
|
|
234
|
+
font-size: 12px;
|
|
235
|
+
color: #666;
|
|
236
|
+
transition: transform 0.3s ease;
|
|
237
|
+
}
|
|
238
|
+
.calendar-cell:hover .lunar-date {
|
|
239
|
+
transform: scale(0.8);
|
|
240
|
+
}
|
|
241
|
+
/* 节假日信息样式 */
|
|
242
|
+
.calendar-cell .holiday-info {
|
|
243
|
+
font-size: 12px;
|
|
244
|
+
margin-top: 2px;
|
|
245
|
+
transition: transform 0.3s ease;
|
|
246
|
+
}
|
|
247
|
+
.calendar-cell:hover .holiday-info {
|
|
248
|
+
transform: scale(0.8);
|
|
249
|
+
}
|
|
250
|
+
/* 日历单元格容器样式 */
|
|
251
|
+
.calendar-cell {
|
|
252
|
+
transition: all 0.3s ease;
|
|
253
|
+
cursor: pointer;
|
|
254
|
+
position: relative;
|
|
255
|
+
padding: 4px;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* .calendar-cell:hover::after {
|
|
259
|
+
content: attr(data-tooltip);
|
|
260
|
+
position: absolute;
|
|
261
|
+
bottom: 100%;
|
|
262
|
+
left: 50%;
|
|
263
|
+
transform: translateX(-50%);
|
|
264
|
+
padding: 4px 8px;
|
|
265
|
+
background-color: rgba(0, 0, 0, 0.8);
|
|
266
|
+
color: white;
|
|
267
|
+
border-radius: 4px;
|
|
268
|
+
font-size: 12px;
|
|
269
|
+
white-space: nowrap;
|
|
270
|
+
z-index: 1000;
|
|
271
|
+
} */
|
|
272
|
+
|
|
273
|
+
/* 节假日背景样式 */
|
|
274
|
+
.holiday {
|
|
275
|
+
background-color: #e7f5ff;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
.holiday:hover {
|
|
279
|
+
background-color: #cce7ff;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/* 周末背景样式 */
|
|
283
|
+
.weekend {
|
|
284
|
+
background-color: #ebfbee;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.weekend:hover {
|
|
288
|
+
background-color: #d7f5dc;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* 选中日期样式 */
|
|
292
|
+
.calendar-cell.selected {
|
|
293
|
+
background-color: #e7f5ff !important;
|
|
294
|
+
/* color: white !important; */
|
|
295
|
+
}
|
|
296
|
+
/* .calendar-cell.selected .holiday-info {
|
|
297
|
+
transform: scale(0.8);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.calendar-cell.selected .date {
|
|
301
|
+
transform: scale(1.3);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.calendar-cell.selected .lunar-date {
|
|
305
|
+
transform: scale(0.8);
|
|
306
|
+
} */
|
|
307
|
+
|
|
308
|
+
.calendar-cell.selected .holiday-info {
|
|
309
|
+
/* color: white; */
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/* 今日单元格样式 */
|
|
313
|
+
.calendar-cell.is-today {
|
|
314
|
+
background-color: #f4fce3;
|
|
315
|
+
/* border: 1px solid #ffa940; */
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.calendar-cell.is-today:hover {
|
|
319
|
+
background-color: #e9fac8;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/* 覆盖Element UI默认的选中样式 */
|
|
323
|
+
:deep(.el-calendar-table td.is-selected) {
|
|
324
|
+
background-color: transparent;
|
|
325
|
+
color: inherit;
|
|
326
|
+
}
|
|
327
|
+
</style>
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
export const holiday = [
|
|
2
|
+
// 春节
|
|
3
|
+
{
|
|
4
|
+
type: 'holiday',
|
|
5
|
+
name: '春节',
|
|
6
|
+
date: '2024-02-10',
|
|
7
|
+
lunarDate: '正月初一'
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
type: 'holiday',
|
|
11
|
+
name: '春节',
|
|
12
|
+
date: '2024-02-11',
|
|
13
|
+
lunarDate: '正月初二'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
type: 'holiday',
|
|
17
|
+
name: '春节',
|
|
18
|
+
date: '2024-02-12',
|
|
19
|
+
lunarDate: '正月初三'
|
|
20
|
+
},
|
|
21
|
+
// 清明节
|
|
22
|
+
{
|
|
23
|
+
type: 'holiday',
|
|
24
|
+
name: '清明节',
|
|
25
|
+
date: '2024-04-04',
|
|
26
|
+
lunarDate: '二月廿五'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 'holiday',
|
|
30
|
+
name: '清明节',
|
|
31
|
+
date: '2024-04-05',
|
|
32
|
+
lunarDate: '二月廿六'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'holiday',
|
|
36
|
+
name: '清明节',
|
|
37
|
+
date: '2024-04-06',
|
|
38
|
+
lunarDate: '二月廿七'
|
|
39
|
+
},
|
|
40
|
+
// 劳动节
|
|
41
|
+
{
|
|
42
|
+
type: 'holiday',
|
|
43
|
+
name: '劳动节',
|
|
44
|
+
date: '2024-05-01',
|
|
45
|
+
lunarDate: '三月廿三'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
type: 'holiday',
|
|
49
|
+
name: '劳动节',
|
|
50
|
+
date: '2024-05-02',
|
|
51
|
+
lunarDate: '三月廿四'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: 'holiday',
|
|
55
|
+
name: '劳动节',
|
|
56
|
+
date: '2024-05-03',
|
|
57
|
+
lunarDate: '三月廿五'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: 'holiday',
|
|
61
|
+
name: '劳动节',
|
|
62
|
+
date: '2024-05-04',
|
|
63
|
+
lunarDate: '三月廿六'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
type: 'holiday',
|
|
67
|
+
name: '劳动节',
|
|
68
|
+
date: '2024-05-05',
|
|
69
|
+
lunarDate: '三月廿七'
|
|
70
|
+
},
|
|
71
|
+
// 端午节
|
|
72
|
+
{
|
|
73
|
+
type: 'holiday',
|
|
74
|
+
name: '端午节',
|
|
75
|
+
date: '2024-06-10',
|
|
76
|
+
lunarDate: '五月初三'
|
|
77
|
+
},
|
|
78
|
+
// 中秋节
|
|
79
|
+
{
|
|
80
|
+
type: 'holiday',
|
|
81
|
+
name: '中秋节',
|
|
82
|
+
date: '2024-09-15',
|
|
83
|
+
lunarDate: '八月初二'
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: 'holiday',
|
|
87
|
+
name: '中秋节',
|
|
88
|
+
date: '2024-09-16',
|
|
89
|
+
lunarDate: '八月初三'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: 'holiday',
|
|
93
|
+
name: '中秋节',
|
|
94
|
+
date: '2024-09-17',
|
|
95
|
+
lunarDate: '八月初四'
|
|
96
|
+
},
|
|
97
|
+
// 国庆节
|
|
98
|
+
{
|
|
99
|
+
type: 'holiday',
|
|
100
|
+
name: '国庆节',
|
|
101
|
+
date: '2024-10-01',
|
|
102
|
+
lunarDate: '八月十八'
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: 'holiday',
|
|
106
|
+
name: '国庆节',
|
|
107
|
+
date: '2024-10-02',
|
|
108
|
+
lunarDate: '八月十九'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
type: 'holiday',
|
|
112
|
+
name: '国庆节',
|
|
113
|
+
date: '2024-10-03',
|
|
114
|
+
lunarDate: '八月二十'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: 'holiday',
|
|
118
|
+
name: '国庆节',
|
|
119
|
+
date: '2024-10-04',
|
|
120
|
+
lunarDate: '八月廿一'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: 'holiday',
|
|
124
|
+
name: '国庆节',
|
|
125
|
+
date: '2024-10-05',
|
|
126
|
+
lunarDate: '八月廿二'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
type: 'holiday',
|
|
130
|
+
name: '国庆节',
|
|
131
|
+
date: '2024-10-06',
|
|
132
|
+
lunarDate: '八月廿三'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'holiday',
|
|
136
|
+
name: '国庆节',
|
|
137
|
+
date: '2024-10-07',
|
|
138
|
+
lunarDate: '八月廿四'
|
|
139
|
+
},
|
|
140
|
+
// 普通周末
|
|
141
|
+
{
|
|
142
|
+
type: 'weekend',
|
|
143
|
+
name: '周末',
|
|
144
|
+
date: '2024-01-06',
|
|
145
|
+
lunarDate: '十一月廿五'
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
type: 'weekend',
|
|
149
|
+
name: '周末',
|
|
150
|
+
date: '2024-01-07',
|
|
151
|
+
lunarDate: '十一月廿六'
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
type: 'weekend',
|
|
155
|
+
name: '周末',
|
|
156
|
+
date: '2024-01-13',
|
|
157
|
+
lunarDate: '十二月初二'
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
type: 'weekend',
|
|
161
|
+
name: '周末',
|
|
162
|
+
date: '2024-01-14',
|
|
163
|
+
lunarDate: '十二月初三'
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
type: 'weekend',
|
|
167
|
+
name: '周末',
|
|
168
|
+
date: '2024-01-20',
|
|
169
|
+
lunarDate: '十二月初九'
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: 'weekend',
|
|
173
|
+
name: '周末',
|
|
174
|
+
date: '2024-01-21',
|
|
175
|
+
lunarDate: '十二月初十'
|
|
176
|
+
}
|
|
177
|
+
]
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="calendar-container" style="margin-left: 120px;">
|
|
3
|
+
<div class="control-panel">
|
|
4
|
+
|
|
5
|
+
<el-date-picker v-model="year" type="year" placeholder="选择年" class="year-picker">
|
|
6
|
+
</el-date-picker>
|
|
7
|
+
<el-switch v-model="showButtonGroup" active-text="显示按钮组" inactive-text="隐藏按钮组" class="control-item"></el-switch>
|
|
8
|
+
<el-switch v-model="showWorkday" active-text="显示工作日" inactive-text="隐藏工作日" class="control-item"></el-switch>
|
|
9
|
+
<el-switch v-model="clickable" active-text="允许点击" inactive-text="禁止点击" class="control-item"></el-switch>
|
|
10
|
+
<!-- <el-switch v-model="showToday" active-text="显示今日标记" inactive-text="隐藏今日标记" class="control-item"></el-switch> -->
|
|
11
|
+
<el-switch v-model="isNextOrPrevClick" active-text="隔月点击时间" inactive-text="不可隔月点击时间" class="control-item"></el-switch>
|
|
12
|
+
</div>
|
|
13
|
+
<div :key="year+''" class="calendar-grid">
|
|
14
|
+
<div v-for="(item, index) in calendarDate" :key="index" class="calendar-item">
|
|
15
|
+
<customCalendar
|
|
16
|
+
@date-click="dataClick"
|
|
17
|
+
:holiday="holiday"
|
|
18
|
+
:date="item.date"
|
|
19
|
+
:showButtonGroup="showButtonGroup"
|
|
20
|
+
:showWorkday="showWorkday"
|
|
21
|
+
:clickable="clickable"
|
|
22
|
+
:showToday="showToday"
|
|
23
|
+
:isNextOrPrevClick="isNextOrPrevClick"
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<style scoped>
|
|
31
|
+
.calendar-container {
|
|
32
|
+
padding: 20px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.year-picker {
|
|
36
|
+
margin-bottom: 20px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.control-panel {
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-wrap: wrap;
|
|
42
|
+
gap: 20px;
|
|
43
|
+
margin-bottom: 20px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.control-item {
|
|
47
|
+
flex: 1;
|
|
48
|
+
min-width: 200px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.calendar-grid {
|
|
52
|
+
display: grid;
|
|
53
|
+
grid-template-columns: repeat(auto-fill, minmax(300px, 440px));
|
|
54
|
+
gap: 10px;
|
|
55
|
+
justify-content: space-between;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.calendar-item {
|
|
59
|
+
width: 100%;
|
|
60
|
+
background-color: #fff;
|
|
61
|
+
border-radius: 8px;
|
|
62
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
|
|
63
|
+
transition: all 0.3s ease;
|
|
64
|
+
padding: 15px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.calendar-item:hover {
|
|
68
|
+
transform: translateY(-5px);
|
|
69
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
|
70
|
+
}
|
|
71
|
+
</style>
|
|
72
|
+
<script>
|
|
73
|
+
import customCalendar from "./customCalendar.vue";
|
|
74
|
+
import {holiday} from "./data";
|
|
75
|
+
export default {
|
|
76
|
+
components: {
|
|
77
|
+
customCalendar,
|
|
78
|
+
},
|
|
79
|
+
data() {
|
|
80
|
+
return {
|
|
81
|
+
year: new Date('2024'),
|
|
82
|
+
showButtonGroup: false,
|
|
83
|
+
showWorkday: true,
|
|
84
|
+
clickable: true,
|
|
85
|
+
showToday: true,
|
|
86
|
+
isNextOrPrevClick: false,
|
|
87
|
+
holiday
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
methods: {
|
|
91
|
+
dataClick(data) {
|
|
92
|
+
console.log(data, "data");
|
|
93
|
+
this.$message.success("日期选择成功:" + data.day);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
computed: {
|
|
97
|
+
calendarDate: function () {
|
|
98
|
+
const selectedYear = this.year.getFullYear();
|
|
99
|
+
const list = Array.from({ length: 12 }, (_, index) => {
|
|
100
|
+
const month = String(index + 1).padStart(2, "0");
|
|
101
|
+
return {
|
|
102
|
+
month: month,
|
|
103
|
+
date: new Date(`${selectedYear}-${month}-01`),
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
console.log(list, "list");
|
|
107
|
+
|
|
108
|
+
return list;
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
mounted() {
|
|
112
|
+
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
};
|
|
116
|
+
</script>
|