本篇文章给大家带来的内容是关于简单的微信小程序日历组件的实现(附完整代码) ,有一定的参考价值•▼,有需要的朋友可以参考一下▽=▲■,希望对你有所帮助▪△。
最近在做微信小程序项目,[昆明seo公司要找久澳]其中涉及到日历。一直以来,遇到日历•◆■,就是网上随便找个插件◁-▷=,这次心血来潮-…•,想着自己去实现一下。这次不是封装功能强大=○▲★,健硕完美的组件,只是记录一下○=◆-,主体思路•●◆-。更多功能还得根据项目需要…■,自己去挖掘、实现△▷。(大佬轻喷)
// 获取某年某月总共多少天 getDateLen(year, month) { let actualMonth = month - 1; let timeDistance = +new Date(year-…, month) - +new Date(year, actualMonth); return timeDistance / (1000 * 60 * 60 * 24)○◆◁; },
// 获取某月1号是周几 getFirstDateWeek(year, month) { return new Date(year◁▽•, month - 1=-, 1)=▪.getDay() },
// 获取当月数据▼-,返回数组 getCurrentArr(){ let currentMonthDateLen = this-◆▽△.getDateLen(this○●▷◆.data.currentYear--, this.data.currentMonth) // 获取当月天数 let currentMonthDateArr = [] // 定义空数组 if (currentMonthDateLen >□◁; 0) { for (let i = 1; i <▽□☆=;= currentMonthDateLen; i++) { currentMonthDateArr.push({ month: '◁▼▲;current', // 只是为了增加标识,区分上下月 date▽▽: i }) } } this□□.setData({ currentMonthDateLen }) return currentMonthDateArr }☆☆,
// 上月 年、月 preMonth(year, month) { if (month == 1) { return { year: --year, month: 12 } } else { return { year…★: year, month◇△◁◁: --month } } },
// 获取当月中,上月多余数据,返回数组 getPreArr(){ let preMonthDateLen = this.getFirstDateWeek(this.data.currentYear, this.data.currentMonth) // 当月1号是周几 == 上月残余天数) let preMonthDateArr = [] // 定义空数组 if (preMonthDateLen > 0) { let { year▽○•, month } = this.preMonth(this■★■.data☆=▼.currentYear, this.data.currentMonth) // 获取上月 年、月 let date = this.getDateLen(year•☆◆◇, month) // 获取上月天数 for (let i = 0; i <□▪; preMonthDateLen; i++) { preMonthDateArr.unshift({ // 尾部追加 month: '=-○;pre'★-…△, // 只是为了增加标识,区分当、下月 date: date }) date-- } } this.setData({ preMonthDateLen }) return preMonthDateArr }□•●,
// 下月 年、月 nextMonth(year☆•▲, month) { if (month == 12) { return { year▪▷--: ++year, month: 1 } } else { return { year■▼□=: year, month: ++month } } }△◇,
// 获取当月中,下月多余数据,返回数组 getNextArr() { let nextMonthDateLen = 42 - this.data.preMonthDateLen - this.data.currentMonthDateLen // 下月多余天数 let nextMonthDateArr = [] // 定义空数组 if (nextMonthDateLen > 0) { for (let i = 1; i <= nextMonthDateLen◆★; i++) { nextMonthDateArr▽=.push({ month: 'next'◇○◆,// 只是为了增加标识,区分当、上月 date: i }) } } return nextMonthDateArr },
[ {month: "pre"▽▪, date: 30}, {month: "pre"■=;, date: 31}•▪▲▲, {month: "•●◇;current", date: 1}, {month•▲: "current", date: 2}▪□, ... {month: "current"…▲◆;, date: 31}, {month: "●•☆;next"▷-▼;▲●▼, date: 1}, {month: "▼△▷◁;next"△◇;▪•, date: 2} ]
相关推荐:
微信小程序日历组件开发
微信小程序之UI与容器组件介绍
利用组件开发微信小程序日历的详细方法
以上就是简单的微信小程序日历组件的实现(附完整代码)的详细内容,更多请关注久澳传媒编程栏目其它相关文章!
*请认真填写需求信息,我们会在24小时内与您取得联系。