lyears 是所有的年份列表, months 是选中的年份的月份列表, days 是选中的月份的天数列表
首先先获取 lyears
1 2 3 4 5 6 7
functionlyearList() { var list = []; for (var i = 1900; i <= 2100; i++) { list.push(i + calendar.toGanZhiYear(i)) } return list }
根据年份获取 months:
1 2 3 4 5 6 7 8 9 10 11
functionlmonthList(y) { var monthList = []; for (var i = 1; i <= 12; i++) { monthList.push(calendar.toChinaMonth(i)) } let leapMonth = calendar.leapMonth(y); if (leapMonth) { monthList.splice(leapMonth, 0, "闰" + calendar.toChinaMonth(leapMonth)) } return monthList }
根据月份和年份,以及月份是否为闰月来计算当前月的天数,可以得到 days:
1 2 3 4 5 6 7 8
functionldaysList(y, m, isLeap) { var dayList = []; let dayCount = isLeap ? calendar.leapDays(y) : calendar.monthDays(y, m) for (var i = 1; i <= dayCount; i++) { dayList.push(calendar.toChinaDay(i)) } return dayList }