废话不多说,咱就是直接上代码:
wxml 代码:
<!--pages/rili/rili.wxml-->
<view class="scroll-view">
<scroll-view scroll-left="{
{scrollLeftIndex*itemWidth}}" scroll-x scroll-with-animation>
<view class='item {
{index==0?"lef":""}}' style='width:{
{
itemWidth}}px' wx:for="{
{dateList}}" wx:key="key" data-index='{
{index}}' bindtap='clickDate'>
<view class='text-view {
{index==clickIndex?"all-choose":""}}'>
<text class='week {
{index==clickIndex?"week-choose":""}}'>{
{item.week}}</text>
<view class='day {
{index==clickIndex?"day-choose":""}}'>{
{item.day}}</view>
<!-- <text class='month'>{
{item.month}}月</text> -->
<!-- <view wx:if="{
{item.month == sysmonth && item.day == nowDate}}">
<text class='week'>今日</text>
</view>
<view wx:else>
<text class='week'>{
{item.week}}</text>
</view> -->
</view>
</view>
</scroll-view>
</view>
js代码:
// pages/rili/rili.js
Page({
/**
* 页面的初始数据
*/
data: {
dateList: [], //存放日期的数组
nowDate: '', //系统当前日期
},
// 格式化日期,时间
formatTime(date) {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(this.formatNumber).join('/') + ' ' + [hour, minute, second].map(this.formatNumber).join(':')
},
// 格式化数字
formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
},