欢迎来到258分享网,纯净的网络源码分享基地!

258资源分享网

全部作品
全部作品
网站源码
微信源码
素材特效
源码插件
视频教程
建站学院
热门搜索: 织梦  农业种植  农业  安全设置  官方
258资源分享 > 建站学院 > 微信开发 > 微信小程序时间预约插件(包含日历)

推荐下载

HTML5响应式自适应网咯设计

2020-05-12   浏览:740

高端HTML5响应式企业通用网

2020-05-06   浏览:521

html5响应式外贸网站英文版

2020-05-08   浏览:510

HTML5自适应律师工作室类网

2020-04-04   浏览:504

HTML5影视传媒文化公司类网

2020-05-12   浏览:502

微信小程序时间预约插件(包含日历)

发布时间:2020-11-11  

因为项目需要,做了一个类似电商的时间预约功能,觉得有用,就独立出来成了个小插件。

 

微信小程序时间预约插件(包含日历)

部分js代码

 

var that=this;

function getThisMonthDays(year, month) {

return new Date(year, month, 0).getDate();

}

// 计算每月第一天是星期几

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 = ['日', '一', '二', '三', '四', '五', '六'];

//利用构造函数创建对象

function calendar(date,week){

this.date=cur_year+'-'+cur_month+'-'+date;

if(date==cur_date){

this.week = "今天";

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

this.week = "明天";

}else{

this.week = '星期' + week;

}

}

//当前月份的天数

var monthLength= getThisMonthDays(cur_year, cur_month)

//当前月份的第一天是星期几

var week = getFirstDayOfWeek(cur_year, cur_month)

var x = week;

for(var i=1;i<=monthLength;i++){

//当循环完一周后,初始化再次循环

if(x>6){

x=0;

}

//利用构造函数创建对象

that.data.calendar[i] = new calendar(i, [weeks_ch[x]][0])

x++;

}

//限制要渲染的日历数据天数为7天以内(用户体验)

var flag = that.data.calendar.splice(cur_date, that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length:7)

that.setData({

calendar: flag

})

//设置scroll-view的子容器的宽度

that.setData({

width: 186 * parseInt(that.data.calendar.length - cur_date <= 7 ? that.data.calendar.length : 7)

})

源代码地址https://github.com/Dorr2333/calendar-and-order.git