commit | author | age
|
e3ba12
|
1 |
export default { |
Z |
2 |
methods: { |
|
3 |
// 设置月份数据 |
|
4 |
setMonth() { |
|
5 |
// 月初是周几 |
|
6 |
const day = dayjs(this.date).date(1).day() |
|
7 |
const start = day == 0 ? 6 : day - 1 |
|
8 |
|
|
9 |
// 本月天数 |
|
10 |
const days = dayjs(this.date).endOf('month').format('D') |
|
11 |
|
|
12 |
// 上个月天数 |
|
13 |
const prevDays = dayjs(this.date).endOf('month').subtract(1, 'month').format('D') |
|
14 |
|
|
15 |
// 日期数据 |
|
16 |
const arr = [] |
|
17 |
// 清空表格 |
|
18 |
this.month = [] |
|
19 |
|
|
20 |
// 添加上月数据 |
|
21 |
arr.push( |
|
22 |
...new Array(start).fill(1).map((e, i) => { |
|
23 |
const day = prevDays - start + i + 1 |
|
24 |
|
|
25 |
return { |
|
26 |
value: day, |
|
27 |
disabled: true, |
|
28 |
date: dayjs(this.date).subtract(1, 'month').date(day).format('YYYY-MM-DD') |
|
29 |
} |
|
30 |
}) |
|
31 |
) |
|
32 |
|
|
33 |
// 添加本月数据 |
|
34 |
arr.push( |
|
35 |
...new Array(days - 0).fill(1).map((e, i) => { |
|
36 |
const day = i + 1 |
|
37 |
|
|
38 |
return { |
|
39 |
value: day, |
|
40 |
date: dayjs(this.date).date(day).format('YYYY-MM-DD') |
|
41 |
} |
|
42 |
}) |
|
43 |
) |
|
44 |
|
|
45 |
// 添加下个月 |
|
46 |
arr.push( |
|
47 |
...new Array(42 - days - start).fill(1).map((e, i) => { |
|
48 |
const day = i + 1 |
|
49 |
|
|
50 |
return { |
|
51 |
value: day, |
|
52 |
disabled: true, |
|
53 |
date: dayjs(this.date).add(1, 'month').date(day).format('YYYY-MM-DD') |
|
54 |
} |
|
55 |
}) |
|
56 |
) |
|
57 |
|
|
58 |
// 分割数组 |
|
59 |
for (let n = 0; n < arr.length; n += 7) { |
|
60 |
this.month.push( |
|
61 |
arr.slice(n, n + 7).map((e, i) => { |
|
62 |
e.index = i + n |
|
63 |
|
|
64 |
// 自定义信息 |
|
65 |
const custom = this.customList.find((c) => c.date == e.date) |
|
66 |
|
|
67 |
// 农历 |
|
68 |
if (this.lunar) { |
|
69 |
const { |
|
70 |
IDayCn, |
|
71 |
IMonthCn |
|
72 |
} = this.getLunar(e.date) |
|
73 |
e.lunar = IDayCn == '初一' ? IMonthCn : IDayCn |
|
74 |
} |
|
75 |
|
|
76 |
return { |
|
77 |
...e, |
|
78 |
...custom |
|
79 |
} |
|
80 |
}) |
|
81 |
) |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
} |