You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 KiB

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