Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement the Mini Program order Calendar plug-in

Shulou Source: shulou.com Published: 2022-06-01 06:46:01 10月03日 Update

Today, the editor will share with you the relevant knowledge points about how to achieve the Mini Program order Calendar plug-in. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article, let's take a look at it.

The plug-in is divided into two parts, the top is the tab bar, will automatically locate the current date according to the current date, and display the date of the next 7 days, the following is the content display, changing with the tab bar.

Train of thought:

First initialize the time with the new Data () time object, get the current date, and use new Date (Date.UTC (year, month-1, 1). GetDay () to get what day the first day of each month is.

/ / calculate what day the first day of each month is

Function getFirstDayOfWeek (year, month) {

Return new Date (Date.UTC (year, month-1,1). GetDay ()

}

Const date = new Date ()

Const cur_year = date.getFullYear ()

Const cur_month = date.getMonth () + 1

Const cur_date=date.getDate ()

Const weeks_ch = ['Day', 'one', 'two', 'three', 'four', 'five', 'six']

Use the constructor to generate data, which will be used later.

/ / create an object using the constructor

Function calendar (date,week) {

This.date=cur_year+'-'+cur_month+'-'+date

If (date==cur_date) {

This.week = "Today"

} else if (date==cur_date+1) {

This.week = "tomorrow"

} else {

This.week = 'week' + week

}

}

Use for loops to generate json data:

For (var iTunes 1 Ten i6) {

Xerox 0

}

/ / create an object using the constructor

That.data.calendar [I] = new calendar (I, [weeks_ ch [x]] [0])

Xerox +

}

Here, because there are 7 days in a week, when x > 6, reset to 0.

Finally, part of the source code is shown.

Var that=this

Function getThisMonthDays (year, month) {

Return new Date (year, month, 0). GetDate ()

}

/ / calculate what day the first day of each month is

Function getFirstDayOfWeek (year, month) {

Return new Date (Date.UTC (year, month-1,1). GetDay ()

}

Const date = new Date ()

Const cur_year = date.getFullYear ()

Const cur_month = date.getMonth () + 1

Const cur_date=date.getDate ()

Const weeks_ch = ['Day', 'one', 'two', 'three', 'four', 'five', 'six']

/ / create an object using the constructor

Function calendar (date,week) {

This.date=cur_year+'-'+cur_month+'-'+date

If (date==cur_date) {

This.week = "Today"

} else if (date==cur_date+1) {

This.week = "tomorrow"

} else {

This.week = 'week' + week

}

}

/ / number of days in the current month

Var monthLength= getThisMonthDays (cur_year, cur_month)

/ / what day is the first day of the current month?

Var week = getFirstDayOfWeek (cur_year, cur_month)

Var x = week

For (var iTunes 1 Ten i6) {

Xerox 0

}

/ / create an object using the constructor

That.data.calendar [I] = new calendar (I, [weeks_ ch [x]] [0])

Xerox +

}

/ / limit the number of calendar data days to be rendered within 7 days (user experience)

Var flag = that.data.calendar.splice (cur_date, that.data.calendar.length-cur_date

Tags: Week function object loop knowledge article plug-in calendar content data date program order again number of days time month part change generation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Xiaomi Docker Shulou Information Shulou Technology