代码地址如下:
http://www.demodashi.com/demo/14243.html

一、前期准备工作

软件环境:微信开发者工具

官方下载地址:https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

1、基本需求。
  • 实现横版日历,tab栏
  • 可控制显示时间
2、案例目录结构

二、程序实现具体步骤

1.index.wxml代码
<!--index.wxml-->
<view class="container">
<view class="header shrink">
<view class="activity-or-brand">
<text id="activity-btn" class="{{activityOrBrand==true?'active':''}}" bindtap="choose1">商场活动</text>
<text id="brand-btn" class="{{activityOrBrand==false?'active':''}}" bindtap="choose1">品牌优惠</text>
</view>
</view>
<view class="date-choose shrink">
<view class="data-month">{{dateMonth}}</view>
<swiper class="date-choose-swiper" indicator-dots="{{false}}" current="{{swiperCurrent}}" bindchange="dateSwiperChange">
<block wx:for="{{dateList}}" wx:for-item="date" wx:key="date.id">
<swiper-item class="swiper-item">
<view class="weekday">
<block wx:for-item="weekday" wx:for="{{dateListArray}}" wx:key="{{index}}">
<text class="week">{{weekday}}</text>
</block>
</view>
<view class="dateday">
<block wx:for="{{date.days}}" wx:for-item="day" wx:key="{{day.id}}">
<text class="day" id="{{day.id}}" bindtap="chooseDate">
<text class="{{dateCurrentStr==day.id?'active':''}}">{{day.day}}</text>
</text>
</block>
</view>
</swiper-item>
</block>
</swiper>
</view>
</view>
2.index.wxss代码
/**index.wxss**/
.header {
padding: .5rem 0;
}
.activity-or-brand {
display: -webkit-box;
display: flex;
background: #fff;
justify-content: space-around;
}
.activity-or-brand > text {
position: relative;
padding: .5rem 1rem;
width: 45%;
text-align: center;
margin: 0 1rem;
}
.activity-or-brand > text:after {
content: "";
position: absolute;
left: 50%;
width: 0;
bottom: 0;
border-bottom: 2px solid #666666;
-webkit-transition: .3s;
transition: .3s;
}
.activity-or-brand > .active {
font-weight: bold;
}
.activity-or-brand > .active:after {
left: 0;
width: 100%;
} .date-choose {
display: flex;
background: #fff;
overflow: hidden;
font-size: .8em;
}
.data-month {
width: 2.6em;
align-items: center;
padding: .5rem .5rem;
text-align: center;
box-shadow: 2px 0 5px rgba(0,0,0,.4);
}
.date-choose-swiper {
flex-grow: 1;
height: 4em;
}
.swiper-item {
display: flex;
flex-direction: column;
}
.weekday, .dateday {
display: flex;
justify-content: space-between;
align-items: center;
text-align: center;
flex-grow: 1;
}
.week, .day {
width: 14.286%;
flex-basis: 14.286%;
}
.day text {
position: relative;
}
.day .active:before {
content: "";
position: absolute;
width: 1.4em;
height: 1.4em;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
border: 2px solid #000;
border-radius: 100%;
} .main-list {
background: #fff;
margin-top: .5rem;
padding: .5rem;
}
.main-list .list-item {
border: 1px solid #ddd;
}
.main-list .list-item:not(:first-child) {
margin-top: .5rem;
}
.main-list .list-content {
position: relative;
padding: .3rem .5rem;
}
.main-list .list-title {
word-wrap: normal;
font-weight: bold;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
padding-right: 7.5rem;
}
.main-list .list-time {
font-size: .8em;
margin-top: .2em;
text-align: right;
position: absolute;
right: .5rem;
bottom: .3rem;
width: 12em;
}
3.index.js逻辑代码

a.数据部分的功能实现

data: {
loading: false, // 加载中 list: {
activity: {pageNo: 1, data: []},
brand: {pageNo: 1, data: []},
}, dateList: [], // 日历数据数组
swiperCurrent: 0, // 日历轮播正处在哪个索引位置
dateCurrent: new Date(), // 正选择的当前日期
dateCurrentStr: '', // 正选择日期的 id
dateMonth: '1月', // 正显示的月份
dateListArray: ['日','一','二','三','四','五','六'],
},

b.日历组件部分

initDate () {
var d = new Date();
var month = utils.addZero(d.getMonth()+1),
day = utils.addZero(d.getDate());
for(var i=-3; i<=3; i++) {
this.updateDate(utils.DateAddDay(d, i*7));
}
this.setData({
swiperCurrent: 3,
dateCurrent: d,
dateCurrentStr: d.getFullYear() + '-' + month + '-' + day,
dateMonth: month + '月',
});
},
// 更新日期数组数据
updateDate (_date, atBefore) {
var week = this.calculateDate(_date);
if (atBefore) {
this.setData({
dateList: [week].concat(this.data.dateList),
});
} else {
this.setData({
dateList: this.data.dateList.concat(week),
});
}
},
// 日历组件轮播切换
dateSwiperChange (e) {
var index = e.detail.current;
var d = this.data.dateList[index];
this.setData({
swiperCurrent: index,
dateMonth: d.month + '月',
});
},

三、案例运行效果图

四、总结与备注

暂无微信小程序横版日历,tab栏

代码地址如下:
http://www.demodashi.com/demo/14243.html

注:本文著作权归作者,由demo大师代发,拒绝转载,转载需要作者授权

微信小程序横版日历,tab栏的更多相关文章

  1. 微信小程序的wx-charts插件-tab选项卡

    微信小程序的wx-charts插件-tab选项卡 效果: //index.js var wxCharts = require('../../utils/wxcharts-min.js'); const ...

  2. 解决微信小程序的wx-charts插件tab切换时的显示会出现位置移动问题-tab切换时,图表显示错乱-实现滑动tab

    解决Echarts在微信小程序tab切换时的显示会出现位置移动问题 tab切换时,图表显示错乱 <canvas class="kcanvas" canvas-id=" ...

  3. 微信小程序~TabBar底部导航切换栏

    底部导航栏这个功能是非常常见的一个功能,基本上一个完成的app,都会存在一个导航栏,那么微信小程序的导航栏该怎么实现呢?经过无数的踩坑,终于实现了,好了,先看看效果图. 对于底部导航栏,小程序上给出的 ...

  4. 发布微信小程序体验版

    小程序这么火,一直没有做过.因为公司有个业务需要做小程序就顺带学习了一把. 1)本次是采用<微信开发者工具 Stable v1.02.1904090>进行的开发: 2)前端使用的是微信官方 ...

  5. 初尝微信小程序2-Swiper组件、导航栏标题配置

    swiper 滑块视图容器. 很多网页的首页都会有一个滚动的图片模块,比如天猫超市首页,滚动着很多优惠活动的图片,用来介绍优惠内容,以及供用户点击快速跳转到相应页面. Swiper不仅可以滚动图片,也 ...

  6. 微信小程序之 SideBar(侧栏分类)

    项目目录: 模拟数据: utils / data.js function getSData() { var data = [ { "id": 1, "tree" ...

  7. 微信小程序之滑动日历展示

    滑动日历效果 效果预览 实现要求:顶部固定悬浮的是获取未来一周的日期,分为上下两部分,上面部分显示星期,下面则显示具体日期.今天则显示今天,可点击头部具体日期,可向左向右滑动. 实现代码 顶部日历 页 ...

  8. 微信小程序:实现日历功能

    一.功能描述 实现日历功能 二. 代码实现 1. index.wxml <view class='wrap'> <view> <view class='date-show ...

  9. 微信小程序点击顶部导航栏切换样式

    类似这样的效果 <view class='helpCateList'> <!-- 类别 --> <scroll-view class='scroll-view' scro ...

随机推荐

  1. arcgis runtime 100 Create geometries

    1 /* Copyright 2016 EsriEsri 2 * 3 * Licensed under the Apache License, Version 2.0 (the "Licen ...

  2. CLR查找和加载程序集 z

    C#开发者在开发WinForm程序.Asp.Net Web(MVC)程序等,不可避免的在项目中引用许多第三方的DLL程序集, 编译后引用的dll都放在根目录下.以我个人作品 AutoProject S ...

  3. 算法:快速排序(Quick Sort)

    算法定义 目前学习是五种排序(冒泡.插入.选择.合并.快速)中,快速排序是最让我喜欢的算法(因为我想不到),其定义如下: 随机的从数组中选择一个元素,如:item. 对数组进行分区,将小于等于 ite ...

  4. .NET:CLR via C# Thread Basics

    A thread is a Windows concept whose job is to virtualize the CPU. Thread Overhead Thread kernel obje ...

  5. pytest文档18-配置文件pytest.ini

    前言 pytest配置文件可以改变pytest的运行方式,它是一个固定的文件pytest.ini文件,读取配置信息,按指定的方式去运行. ini配置文件 pytest里面有些文件是非test文件 py ...

  6. Mantis的config_inc.php的各配置项的作用及其修改

    Mantis的设置是这样保存的:在 config_defaults_inc.php中保存Mantis的默认设置,用户自己的设置信息保存在config_inc.php中.如果某个选项在config_in ...

  7. 【BZOJ】【1006】【HNOI2008】神奇的国度

    弦图最小染色/MCS算法 Orz PoPoQQQ  (UPD:ydc的写法好像更熟悉一些……(类似堆优化的Dij啊~ 先留个坑……明天再看一看……感觉好神奇>_<(完美消除序列之于弦图 就 ...

  8. 混沌数学之Baker模型

    相关DEMO参见:混沌数学之离散点集图形DEMO 相关代码: // http://wenku.baidu.com/view/ac9b57ea172ded630b1cb65b.html class Ba ...

  9. rotate-function

    https://leetcode.com/problems/rotate-function/ public class Solution { public int maxRotateFunction( ...

  10. html5游戏驴子跳

    在线演示 免费下载 分享一款HTML5开发的游戏,放松一下吧大家吧