WeChat Mini Program-Calendar
Idea analysis
To implement a calendar, you need to know several values:
How many days are there in the month
What day of the week is the first day of the month
According to common sense, we know that a month has a maximum of 31 days and a minimum of 28 days. If the calendar has 7 grids in a row, there will be 5 rows. However, if the first day of the month is a Saturday, there will be six rows of grids.
The applet has no concept of DOM operations, so it cannot dynamically insert the number of empty cells into the first day of the month. It can only be controlled by adding a loop of empty cells in front. For details, refer to the wxml file.
Calendar template introduction
The calendar template panel supports sliding left and right gestures;
Provides jumpToToday method to jump to today;
Set date to-do labels setTodoLabels;
Delete to-do labels for the specified date deleteTodoLabels;
Clear all date to-do labels clearTodoLabels;
Provide template template introduction
Introduce wxml and wxss
// example.wxml
<import src="../../template/calendar/index.wxml"/>
<view class="calendar-wrap">
<template is="calendar" data="{{...calendar}}" />
</view>
/* example.wxss */ @import '../../template/calendar/index.wxss';
Calendar component initialization
import initCalendar, { getSelectedDay, jumpToToday, setTodoLabels, deleteTodoLabels, clearTodoLabels } from '../../template/calendar/index'; const conf = { onShow: function() { initCalendar({ // multi: true, // Whether to enable multi-selection, // disablePastDay: true, // Whether to disable past dates/** * Events executed after selecting a date * @param { object } currentSelect The currently clicked date * @param { array } allSelectedDays All selected dates (The allSelectedDays parameter is only available when mulit is true) */ afterTapDay: (currentSelect, allSelectedDays) => { console.log('==================== ==========='); console.log('The current clicked date', currentSelect); console.log('Whether the current clicked date has an event mark: ', currentSelect.hasTodo || false );
allSelectedDays && console.log('all selected dates', allSelectedDays); console.log('getSelectedDay method', getSelectedDay());
}, /** * Date click event (this event will completely take over the click event) * @param { object } currentSelect The date of the current click * @param { object } event Date click event object */ // onTapDay(currentSelect, event) { // console.log(currentSelect); // console.log(event); // }, /** * Events are triggered after the initial rendering of the calendar, such as setting event markers */ afterCalendarRender() { setTodoLabels({
pos: 'bottom',
dotColor: '#40',
days: [{
Year: 2018,
month: 5,
day: 12,
}, {
Year: 2018,
month: 5,
day: 15,
}],
});
},
});
}, deleteTodo() { // Specify the date when the to-do label needs to be deleted deleteTodoLabels([{
Year: 2018,
month: 5,
day: 12,
}, {
Year: 2018,
month: 5,
day: 15,
}]); // clearTodoLabels(); }, /** * Jump to today */ jump() { jumpToToday();
},
}; Page(conf);
All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn
Related Article

04 Mar 2025
This article discusses WeChat Mini Program navigation, focusing on managing gesture-back actions for order details pages. It explains that directly using gesture-back to navigate to a specific page isn't supported; instead, proper navigation using w

30 Nov 2024
Recovering Lost C Source Code: Exploring Decompilation OptionsLosing the source code to a C program can be frustrating, but it's not...

21 Dec 2024
VS Code Builds C Programs with Multiple .cpp Source FilesWhen building a C program with multiple .cpp source files in Visual Studio Code, it's...

12 Nov 2024
Can I Decompile a Compiled Go Program?No, it is not possible to decompile a compiled Go program back into its original Go source code. Here's a...

03 Jan 2025
VS Code Unable to Build C Program with Multiple .cpp Source FilesOne of the common challenges in using VS Code for C development is building...

13 Jul 2016
New here - smarty, new here. First time here----smarty, first time here Smarty Day01-----Usage of smarty Function: Separate php html, program and art Usage: 1. Download the source code package 2. Directory structure libs source code file

19 Nov 2024
Reverse Engineering Compiled Go ProgramsDecompiling a compiled program to its original source code is a challenging task. In the case of Go, the...

06 Mar 2025
Discover Pilet: A Retro-Futuristic, Open-Source Mini-Computer Looking for a mini-computer that blends classic style with cutting-edge technology? Meet Pilet, a modular, open-source marvel powered by the Raspberry Pi 5. Boasting a 7-hour battery life

24 Jun 2016
Can anyone recommend an open source program with visual editing tools?


Hot Tools

WeChat mini program demo: imitation mall
WeChat mini program demo: imitating a mall, easy to get started, and has a good introduction to some basic functions of the mall

Takeaway: Implement anchor-like functionality
It is the similar anchor function that everyone needs. In addition, it also implements the typical ordering functions of some takeout apps. It is recommended to study and study;

WeChat mini program demo: Lezhu
WeChat mini program demo: Lezhu: similar to location-based; helpful application, somewhat similar to the spirit of Zhang Xiaolong’s mini program.

WeChat mini program game demo selects different color blocks
WeChat mini program game demo selects different color blocks

WeChat applet demo: carousel image transformation
Carousel chart style change, a simple carousel chart implemented with a small program, easy to write
