Home WeChat Applet Mini Program Development Implementation of calendar sign-in applet

Implementation of calendar sign-in applet

Jan 26, 2021 am 09:36 AM
Applets calendar

Implementation of calendar sign-in applet

First let’s take a look at the final rendering:

(Learning video sharing: Introduction to Programming)

Implementation of calendar sign-in applet

Let’s introduce the implementation ideas:

First of all, what we want to obtain is nothing more than the data in each grid.

Get the month first, then click on the month to switch to another month. When it reaches the boundary line, it can reach the previous/next year.

So, how to get the monthly data? You can see that the first day of the month starts with 1, and then xx days, such as January 31, we enumerate it.

But the month is affected by the year, so the calculation is completed if it is a leap year.

Upload the code
Get the 7*5 list of this month

let getMothList = (year, month) => {
    var star = new Date(Date.UTC(year, month - 1, 1)).getDay()
    let mn = getMothNum(year)[month - 1]
    var res = []
    var row = []
    new Array(35)
        .fill('')
        .map((_, i) => i - star + 1)
        .map(e => 
            (e > 0 && e <= mn)
            ? ({
                date: `${year}/${month}/${e}`,
                number: e 
            })
            : (null)
        )
        .forEach((item, i) => {
            row.push(JSON.parse(JSON.stringify(item)))
            if((i + 1) % 7 == 0){
                res.push(row)
                row = []
            }
        })
    return res
}
Copy after login

Then get the month

var getMaxY = y =>  Boolean(
	y % 4 ==0 && y % 100 != 0 || y % 400==0
)
var getAugNum = n => getMaxY(n) ? 29 : 28
// --获取年对应的月份
var getMothNum = y => ([ 31, getAugNum(y), 31, 30,  31, 30, 31,31, 30, 31, 30, 31 ])
Copy after login

That’s all the js I have above (I still need to switch between the previous and next month) Haha)

But the Chinese month is missing. If necessary, this can be matched again

var mothZh = [&#39;一&#39;,&#39;二&#39;,&#39;三&#39;,&#39;四&#39;,&#39;五&#39;,&#39;六&#39;,&#39;七&#39;,&#39;八&#39;,&#39;九&#39;,&#39;十&#39;,&#39;十一&#39;,&#39;十二&#39;].map(e => e + &#39;月&#39;)
Copy after login

Then it is the upper and lower month

  up(e){
    var data = e.currentTarget.dataset
    if(data.data == &#39;上&#39;){
      if(this.data.dateM > 1){
        var dateM = this.data.dateM
        var dateY = this.data.dateY
        this.setDate(dateY, dateM - 1)
      }else{
        var dateY = this.data.dateY
        this.setDate(dateY - 1, 12)
      }
    }
  },
  down(e){
    var data = e.currentTarget.dataset
    if(data.data == &#39;下&#39;){
      if(this.data.dateM < 12){
        var dateM = this.data.dateM
        var dateY = this.data.dateY
        this.setDate(dateY, dateM + 1)
      }else{
        var dateY = this.data.dateY
        this.setDate(dateY + 1, 1)
      }
    }
  },
Copy after login

Update after the upper and lower month operation is completed When updating the data, because the applet cannot write logic in the view, we operate it in the mpa (this is my business logic, you don’t need to worry about it, I put it out so that everyone can view it)

  setDate(dateY, dateM){
    var date_list = getMothList(dateY, dateM)
    .map(e => !e ? e : e.map(day => {
      var cat_date = this.data.cat_date
      return !day ? day : {
        ...day,
        className: this.data.chckin_list.indexOf(day.date) != -1 ? &#39;checkin&#39; : &#39;&#39;,
        sign: day.date == [cat_date.y, cat_date.m, cat_date.d].join(&#39;/&#39;),
        maxToday: +(Date.UTC(day.date.split(&#39;/&#39;)[0], day.date.split(&#39;/&#39;)[1] - 1, +(day.date.split(&#39;/&#39;)[2])))
          > Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()),
      }
    }))
    this.setData(({
      dateY,
      dateM,
      date_list,
    }))
    // 获取月和修改的时候,获取签到列表
    this.setSign(dateY, dateM)
    // console.log(date_list)
  },
Copy after login

Then you will notice that there is a chckin_list here, which is what is to be rendered. view

<view class="week">
            <view class="flex" wx:for="{{date_list}}" wx:key="index" wx:for-item="row">
                <view 
                class="day {{day.maxToday ? &#39;maxToday&#39; : &#39;&#39;}}" 
                wx:for="{{row}}" wx:for-index="row_idx" wx:for-item="day" wx:key="row_idx"
                bind:tap="tapDay"
                data-day="{{day.date}}"
                >
                    <block wx:if="{{day}}">
                        <text class="block to_day_block  {{day.sign ? &#39;select_date&#39; : &#39;&#39;}}" wx:if="{{toDay == day.date}}">今</text>
                        <text class="block  {{day.sign ? &#39;select_date&#39; : &#39;&#39;}}" wx:else>{{day.number}}</text>
                    </block>
                    <view wx:if="{{day.className}}" class="{{day.className}}">已签</view>
                </view>
            </view>
        </view>
Copy after login

The above is my business logic. In fact, I only need if and day, because except for the empty ones, everything else needs to be rendered. But in general business, there is also whether to sign in. After today, the gray color is not clickable (there is no unclickability here because clicking is disabled with css)

Others

The reason why I didn’t put css is that everyone’s css is still my own Just write it, and if you really need it, leave a comment below.

Oh, if you want to see the effect, go to the mini program and search for "Memorizing Words on the Ninth Day of the Lunar New Year" and click on the calendar (one is the home page to complete today's task, and the other is my-> days to memorize words)

(If necessary, I can tell you how to do the sign-in backend, nodejs)

--Okay--

That's it, good night

- --Update part---

(Someone downstairs reminded me (Maomao Fan) that the last 31st in March is missing. I checked and found that it was cut, because 5 * 7 cannot Fully displayed)

The repaired picture

Implementation of calendar sign-in applet

The changed part is the dynamic loading line.

Based on the above code, add a judgment

Implementation of calendar sign-in applet

#First change the previous 35 to 6*7. Because one more line was added. Then determine whether there is any free space and remove it.

 row.map(e => e || &#39;&#39;).join(&#39;&#39;) !== &#39;&#39;
Copy after login

--End--

Related recommendations: 小program development tutorial

The above is the detailed content of Implementation of calendar sign-in applet. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if the win11 dual-screen calendar does not exist on the second monitor? What should I do if the win11 dual-screen calendar does not exist on the second monitor? Jun 12, 2024 pm 05:47 PM

An important tool for organizing your daily work and routine in Windows 11 is the display of time and date in the taskbar. This feature is usually located in the lower right corner of the screen and gives you instant access to the time and date. By clicking this area, you can bring up your calendar, making it easier to check upcoming appointments and dates without having to open a separate app. However, if you use multiple monitors, you may run into issues with this feature. Specifically, while the clock and date appear on the taskbar on all connected monitors, the ability to click the date and time on a second monitor to display the calendar is unavailable. As of now, this feature only works on the main display - it's unlike Windows 10, where clicking on any

Win10 calendar displays week numbers Win10 calendar displays week numbers Jan 04, 2024 am 08:41 AM

Many users want to use the win10 calendar tool to check the current number of days, but the calendar does not automatically display this function. In fact, we only need to make simple settings to see the cumulative number of weeks this year ~ win10 calendar displays weeks Digital setting tutorial: 1. Enter calendar in the search in the lower left corner of the desktop and open the application. 2. In the open calendar application, click the "gear" icon in the lower left corner, and the settings will pop up on the right. We click "Calendar Settings" 3. Continue in the open calendar settings, find "Week Number" and then change the week Just adjust the number option to "the first day of the year". 4. After completing the above settings, click "Week" to see this year's week number statistics.

Outlook calendar not syncing; Outlook calendar not syncing; Mar 26, 2024 am 09:36 AM

If your Outlook calendar cannot sync with Google Calendar, Teams, iPhone, Android, Zoom, Office account, etc., please follow the steps below to resolve the issue. The calendar app can be connected to other calendar services such as Google Calendar, iPhone, Android, Microsoft Office 365, etc. This is very useful because it can sync automatically. But what if OutlookCalendar fails to sync with third-party calendars? Possible reasons could be selecting the wrong calendar for synchronization, calendar not visible, background application interference, outdated Outlook application or calendar application, etc. Preliminary fix for Outlook calendar not syncing

Can't open the calendar in the lower right corner of win10 Can't open the calendar in the lower right corner of win10 Dec 26, 2023 pm 05:07 PM

Some friends who use the win0 system have encountered the situation where the win10 calendar cannot be opened. This is just a normal computer glitch. It can be solved in the privacy settings of the win10 system. Today, the editor has brought a detailed solution. Below Let’s take a look. Solution to the problem that the calendar cannot be opened in the lower right corner of win10 1. Click Start in the win10 system → click the program list button above → find Pinyin (Chinese) R → Calendar 2. When using it for the first time, new events may not be opened (mouse If you lean up, there will be no dark blue selected), you can set it in privacy. Click the three-bar icon in the upper left corner of the desktop → there will be a settings menu at the bottom; 3. Click Privacy in the pop-up interface; 4. If you have used settings before, you can click on the left

What should I do if there are no pop-up reminders for calendar events in Win10? How to recover if calendar event reminders are gone in Win10 What should I do if there are no pop-up reminders for calendar events in Win10? How to recover if calendar event reminders are gone in Win10 Jun 09, 2024 pm 02:52 PM

The calendar can help users record your schedule and even set reminders. However, many users are asking what to do if calendar event reminders do not pop up in Windows 10? Users can first check the Windows update status or clear the Windows App Store cache to perform the operation. Let this site carefully introduce to users the analysis of the problem of Win10 calendar event reminder not popping up. To add calendar events, click the "Calendar" program in the system menu. Click the left mouse button on a date in the calendar. Enter the event name and reminder time in the editing window, and click the "Save" button to add the event. Solving the problem of win10 calendar event reminder not popping up

No Period Lost Purchasing Office: New calendar and birthday series peripherals! No Period Lost Purchasing Office: New calendar and birthday series peripherals! Feb 29, 2024 pm 12:00 PM

The Lost Purchasing Office is confirmed to be updated at 11 am on February 28th. Players can go to Taobao to search the Purchasing Office and select the store category to purchase. This time we bring you the MBCC birthday party series and 2024 Desk Calendar peripherals. Come together. Take a look at the product details this time. No Period Lost Purchasing Office: New calendar and birthday series peripherals! There is something new in the Lost Procurement Office! - Pre-sale time: February 28, 2024 11:00 - March 13, 2024 23:59 Purchase address: Taobao search [Unexpected Lost Purchasing Office] Select [Store] category to enter the store for purchase; peripheral introduction: The new peripherals released this time are MBCC birthday party series and 2024 desk calendar peripherals. Please click on the long image for details. The Purchasing Office introduces new peripherals—MBCC students

Develop WeChat applet using Python Develop WeChat applet using Python Jun 17, 2023 pm 06:34 PM

With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine

How to solve the problem that the time in win11 is always inaccurate? Win11 time adjustment tutorial quickly solves the problem of inaccurate time How to solve the problem that the time in win11 is always inaccurate? Win11 time adjustment tutorial quickly solves the problem of inaccurate time Apr 19, 2024 am 09:31 AM

If your Windows 11 computer displays the wrong time, it can cause a lot of problems and even prevent you from connecting to the internet. In fact, some applications refuse to open or run when the system displays an incorrect date and time. So how should this problem be solved? Let’s take a look below! Method 1: 1. We first right-click on the blank space of the taskbar below and select Taskbar Settings 2. Find taskbarcorneroverflow3 on the right in the taskbar settings, then find clock or clock above it and select to turn it on. Method 2: 1. Press the keyboard shortcut win+r to call up run, enter regedit and press Enter to confirm. 2. Open the Registry Editor and find HKEY in it

See all articles