微信小程序一周时间表功能实现微信小程序一周时间表功能实现
主要介绍了微信小程序一周时间表功能实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一
定的参考学习价值,需要的朋友可以参考下
这篇文章主要介绍了微信小程序一周时间表功能实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的
参考学习价值,需要的朋友可以参考下
wxml
<view class="dateView">
<image class="dateLeft" bindtap="prevWeek" src="../../res/imgs/dateLeft.png"></image>
<view>{{dateStart}} 至 {{dateEnd}}</view>
<image class="dateRight" bindtap="nextWeek" src="../../res/imgs/dateRight.png"></image>
</view>
wxss
.dateView{
padding:0 32rpx;
height:98rpx;
display: flex;
align-items: center;
background:#fff;
}
.dateView>image{
width:50rpx;
height:50rpx;
}
.dateView>view{
flex: 1;
text-align: center;
color:#333;
font-size: 34rpx;
}
js
const GetPeriod = require("../../utils/getperiod.js");
Page({
/**
* 页面的初始数据
*/
data: {
currentTab: 1,
dateStart:'2019-10-16',
dateEnd: '2019-10-16',
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
let that = this;
that.getWeekStartDate(0)
},
//获取本周的开始日期
getWeekStartDate(numDay) {
let that = this;
this.now = new Date();
this.nowYear = this.now.getYear(); //当前年
this.nowMonth = this.now.getMonth(); //当前月
this.nowDay = this.now.getDate(); //当前日
this.nowDayOfWeek = this.now.getDay(); //今天是本周的第几天
this.nowYear += (this.nowYear < 2000) ? 1900 : 0;
let dateStart = GetPeriod.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek + 1 + numDay));
let dateEnd = GetPeriod.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay - this.nowDayOfWeek + 7 + numDay));
// console.log(dateStart)
// 获取今天日期
let now = GetPeriod.formatDate(new Date(this.nowYear, this.nowMonth, this.nowDay));
now = now.replace(/-/g, "/");
now = now.substring(5);
this.setData({
dateStart: dateStart,
dateEnd: dateEnd,