The school calendar component can be used as a plugin for campus mini-programs. If you find it useful, give it a star :-)
Github: https://github.com/WindrunnerMax/SCalendar
SHST Mini-program at Shanshui University: https://github.com/WindrunnerMax/SHST
Import into WeChat Developer Tools to test the demo
This is the time operation utility class written in my mini-program (SHST). It is referenced in the component.
First of all, we need to print out the calendar for the current month based on the year and month. We can use util.formatDate("yyyy-MM-01", date)
to get the Date
object for the 1st
of the current month, then calculate which day of the week this falls on. We can use Date.addDate()
to move the date to the Monday of the week that contains the 1st
of the month, which will be the first day to print on the calendar for the current month. Since the school calendar usually starts the week on a Monday, we need to adjust this slightly and cannot simply subtract the week count to point the Date
object to the first day of the calendar.
Since a calendar month can have at most five weeks, we can directly print the time for five weeks using Date.addDate()
to increment the date day by day, and then save the data.
As for the date styles, I used a relatively simple method. I used an if
statement to determine the date and assign specific styles to it. I concatenated different class
as a string and assigned it to unitObj
. As for the display color, I controlled the priority of the CSS to make the unit styles inherit from the container. For styles that need specific display, I provided a detach
field to save them.
To jump to a specific date, we can directly get the time to concatenate the month and then call the calendar month handling method.
The view is just used to create a calendar using loops