因为项目需要,做了一个类似电商的时间预约功能,觉得有用,就独立出来成了个小插件。部分js代码(code)var that=this; function getThisMonthDays(year, month) { return new Date(year, month, 0)。getDate(); } // 计算每 。。
因为项目需要,做了一个类似电商的时间预约功能,觉得有用,就独立出来成了个小插件。
部分js代码(code)
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。
宁波小程序开发对于开发者而言,小程序开发门槛相对较低,难度不及APP,能够满足简单的基础应用,适合生活服务类线下商铺以及非刚需低频应用的转换。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 lt;=monthLength;i++){
//当循环(continue)完一周后,初始化再次循环(continue)
if(x gt;6){
x=0;
}
//利用构造函数创建对象
that。data。calendar[i] = new calendar(i, [weeks_ch[x]][0])
x++;
}
//限制要渲染的日历数据(data)天数为7天以内(用户访问体验)
var flag = that。宁波微信小程序开发其中,通过公众号关联,用户可以实现公众号与小程序之间相互跳转。小程序体现了“用完即走”的理念,用户不用关心是否安装太多应用的问题。应用将无处不在,随时可用,但又无需安装卸载。 data。calendar。splice(cur_date, that。data。calendar。length - cur_date lt;= 7 that。data。calendar。length:7)
that。setData({
calendar: flag
})
//设置scroll-view的子容器的宽度
that。setData({
width: 186 * parseInt(that。宁波小程序开发对于用户来说,能够节约使用时间成本和手机内存空间;对于开发者来说也能节约开发和推广成本。data。calendar。length - cur_date lt;= 7 ? that。data。calendar。length : 7)
})
源代码(code)httPHOTOSHOP://github。com/Dorr2333/calendar-and-order。git