js文件

'use strict';
let choose_year = null,
choose_month = null;
const conf = {
data: {
hasEmptyGrid: false,
showPicker: false
},
onLoad() {
const date = new Date();
const cur_year = date.getFullYear();
const cur_month = date.getMonth() + 1;
const weeks_ch = [ '日', '一', '二', '三', '四', '五', '六' ];
this.calculateEmptyGrids(cur_year, cur_month);
this.calculateDays(cur_year, cur_month);
this.setData({
cur_year,
cur_month,
weeks_ch
});
},
getThisMonthDays(year, month) {
return new Date(year, month, 0).getDate();
},
getFirstDayOfWeek(year, month) {
console.log(new Date(Date.UTC(year, month - 1, 1)).getDay())
return new Date(Date.UTC(year, month - 1, 1)).getDay();
},
calculateEmptyGrids(year, month) {
const firstDayOfWeek = this.getFirstDayOfWeek(year, month);
let empytGrids = [];
if (firstDayOfWeek > 0) {
for (let i = 0; i < firstDayOfWeek; i++) {
empytGrids.push(i);
}
this.setData({
hasEmptyGrid: true,
empytGrids
});
} else {
this.setData({
hasEmptyGrid: false,
empytGrids: []
});
}
},
calculateDays(year, month) {
let days = [];
const thisMonthDays = this.getThisMonthDays(year, month);
for (let i = 1; i <= thisMonthDays; i++) {
days.push({
day: i,
choosed: false
});
}
this.setData({
days
});
},
// 顶部年月选择控制函数
handleCalendar(e) {
const handle = e.currentTarget.dataset.handle;
const cur_year = this.data.cur_year;
const cur_month = this.data.cur_month;
if (handle === 'prev') {
let newMonth = cur_month - 1;
let newYear = cur_year;
if (newMonth < 1) {
newYear = cur_year - 1;
newMonth = 12;
}
this.calculateDays(newYear, newMonth);
this.calculateEmptyGrids(newYear, newMonth);
this.setData({
cur_year: newYear,
cur_month: newMonth
});
} else {
let newMonth = cur_month + 1;
let newYear = cur_year;
if (newMonth > 12) {
newYear = cur_year + 1;
newMonth = 1;
}
this.calculateDays(newYear, newMonth);
this.calculateEmptyGrids(newYear, newMonth);
this.setData({
cur_year: newYear,
cur_month: newMonth
});
}
},
tapDayItem(e) {
const idx = e.currentTarget.dataset.idx;
const days = this.data.days;
days[ idx ].choosed = !days[ idx ].choosed;
this.setData({
days,
});
},
chooseYearAndMonth() {
const cur_year = this.data.cur_year;
const cur_month = this.data.cur_month;
let picker_year = [],
picker_month = [];
for (let i = 1900; i <= 2100; i++) {
picker_year.push(i);
}
for (let i = 1; i <= 12; i++) {
picker_month.push(i);
}
const idx_year = picker_year.indexOf(cur_year);
const idx_month = picker_month.indexOf(cur_month);
this.setData({
picker_value: [ idx_year, idx_month ],
picker_year,
picker_month,
showPicker: true,
});
},
pickerChange(e) {
const val = e.detail.value;
choose_year = this.data.picker_year[val[0]];
choose_month = this.data.picker_month[val[1]];
},
tapPickerBtn(e) {
const type = e.currentTarget.dataset.type;
const o = {
showPicker: false,
};
if (type === 'confirm') {
o.cur_year = choose_year;
o.cur_month = choose_month;
this.calculateEmptyGrids(choose_year, choose_month);
this.calculateDays(choose_year, choose_month);
}
this.setData(o);
},
onShareAppMessage() {
return {
title: '小程序日历',
desc: '还是新鲜的日历哟',
path: 'pages/index/index'
};
}
};
Page(conf);
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

wxml

<view class="flex box box-tb box-align-center">
<view class="calendar pink-color box box-tb">
<view class="top-handle fs28 box box-lr box-align-center box-pack-center">
<view class="prev box box-rl" bindtap="handleCalendar" data-handle="prev">
<view class="prev-handle box box-lr box-align-center box-pack-center">《</view>
</view>
<view bindtap="chooseYearAndMonth" class="date-area box box-lr box-align-center box-pack-center">{{cur_year || "--"}} 年 {{cur_month || "--"}} 月</view>
<view class="next box box-lr" bindtap="handleCalendar" data-handle="next">
<view class="next-handle box box-lr box-align-center box-pack-center">》</view>
</view>
</view>
<view class="weeks box box-lr box-pack-center box-align-center">
<view class="flex week fs28" wx:for="{{weeks_ch}}" wx:key="week{{index}}" data-idx="{{index}}">{{item}}</view>
</view>
<view class="days box box-lr box-wrap">
<view wx:if="{{hasEmptyGrid}}" class="grid white-color box box-align-center box-pack-center" wx:for="{{empytGrids}}" wx:key="day{{index}}" data-idx="{{index}}">
</view>
<view class="grid white-color box box-align-center box-pack-center" wx:for="{{days}}" wx:key="days{{index}}" data-idx="{{index}}" bindtap="tapDayItem">
<view class="day {{item.choosed ? 'border-radius pink-bg' : ''}} box box-align-center box-pack-center">{{item.day}}</view>
</view>
</view>
</view>
</view>
<view wx:if="{{showPicker}}" class="box box-tb">
<view class="picker-btns box box-lr box-pack-between box-align-center">
<view class="picker-btn picker-cancel" data-type="cancel" bindtap="tapPickerBtn">取消</view>
<view class="picker-btn picker-confirm" data-type="confirm" bindtap="tapPickerBtn">确定</view>
</view>
<picker-view class="flex" indicator-style="height: 50px;" style="width: 100%; height: 150px;" value="{{picker_value}}" bindchange="pickerChange">
<picker-view-column>
<view class="picker-view" wx:key="years{{index}}" wx:for="{{picker_year}}" style="line-height: 50px">{{item}}年</view>
</picker-view-column>
<picker-view-column>
<view class="picker-view" wx:key="months{{index}}" wx:for="{{picker_month}}" style="line-height: 50px">{{item}}月</view>
</picker-view-column>
</picker-view>
</view>
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------

wxss

/* pages/calendar/calendar.wxss */
.top-handle {
height: 80rpx;
}
.prev {
text-align: right;
height: 80rpx;
}
.next {
height: 80rpx;
}
.prev-handle {
width: 80rpx;
height: 100%;
}
.next-handle {
width: 80rpx;
height: 100%;
}
.date-area {
width: 50%;
height: 80rpx;
text-align: center;
}
.weeks {
height: 50rpx;
line-height: 50rpx;
opacity: 0.5
}
.week {
text-align: center;
}
.days {
height: 500rpx;
}
.grid {
width: 107.1428571429rpx;
}
.day {
width: 60rpx;
height: 60rpx;
color: #88d2ac;
font-size: 26rpx;
font-weight: 200;
}
.border-radius {
border-radius: 50%;
position: relative;
left: 0;
top: 0;
color: #fff;
}
.pink-bg {
">#ff629a;
}
.purple-bg {
">#b8b8f1;
}
.right-triangle::after {
content: "";
display: block;
width: 0;
height: 0;
border: 15rpx solid transparent;
border-left-color: #ff629a;
position: absolute;
right: -22rpx;
top: 18rpx;
}
.left-triangle::before {
content: "";
display: block;
width: 0;
height: 0;
border: 15rpx solid transparent;
border-right-color: #ff629a;
position: absolute;
left: -22rpx;
top: 18rpx;
}
.tips {
text-align: center;
margin-top: 20rpx;
margin-bottom: 20rpx;
}
.types {
">#ffedf4;
height: 50rpx;
}
.type-dot {
width: 25rpx;
height: 25rpx;
border-radius: 50%;
margin-right: 10rpx;
}
.type-dot-ymq {
color:#FF7CA0;
">#FF7CA0;
}
.type-dot-ycq {
color: rgb(255, 200, 202);
">rgb(255, 200, 202);
}
.type-dot-aqq {
color: rgb(118, 191, 92);
">rgb(118, 191, 92);
}
.type-dot-yyq {
color: #FF7CA0;
">#FF7CA0;
}
.type-dot-plr {
color: rgb(211, 189, 215);
">rgb(211, 189, 215);
}
.types-desc {
padding: 0 20rpx;
}
.type-name {
margin-top: 50rpx;
margin-bottom: 30rpx;
}
.type-desc {
padding: 0 35rpx;
line-height: 38rpx;
}
.explain {
border-top: 1px solid #eee;
width: 90%;
margin: 20rpx 5% 20rpx 5%;
padding: 20rpx 0;
}
.explain-title {
font-weight: bold;
margin-bottom: 15rpx;
}
.explain-item {
padding: 8rpx 20rpx;
color: #fff;
}
.left-border-radius {
border-top-left-radius: 20rpx;
border-bottom-left-radius: 20rpx;
}
.right-border-radius {
border-top-right-radius: 20rpx;
border-bottom-right-radius: 20rpx;
}
.picker-btns {
height: 120rpx;
line-height: 120rpx;
border-bottom: 1rpx solid #FF7CA0;
}
.picker-confirm {
margin-right: 50rpx;
}
.picker-cancel {
margin-left: 50rpx;
}
.picker-view {
color:#FF7CA0;
text-align: center;
}

转载于:https://www.cnblogs.com/dianzan/p/7908670.html

微信小程序组件 日历相关推荐

  1. 微信小程序自定义日历组件

    微信小程序自定义日历组件 wxml <view class="maskWrap" bindtap="close"></view>< ...

  2. 微信小程序 引入日历组件

    GitHub - treadpit/wx_calendar: 微信小程序-日历组件

  3. android img标签属性_微信小程序 组件叠加效果(如 Android 中的添加蒙层)

    实现的效果如下: 可以看出这是由image组件和text组件叠加到一块组成的蒙层效果. 在小程序中实现这个效果主要用到z-index属性和position属性 z-index的使用必须是双方组件都设置 ...

  4. 微信小程序组件间通信(二)

    2019独角兽企业重金招聘Python工程师标准>>> 一.微信小程序中通过事件,实现子组件向父组件中传递数据或操作 注:子组件向父组件中传递通过事件传递操作 通过事件参数对象det ...

  5. 微信小程序组件、路由、组件通信、侦听器

    一.微信小程序组件 组件就是小程序页面的组成结构,与html在web网页开发中的作用一样,铺设页面.可以参考其他UI库,像elementUI,vantUI组件 组件是视图层的基本组成单元. 组件自带一 ...

  6. 【微信小程序】三、微信小程序组件的基本使用

    五.微信小程序组件 微信小程序框架为开发者提供了一系列组件,开发者可以通过组合这些组件进行快速开发. (1)微信小程序组件基础概念 什么是组件? 组件是视图层的基本组成单元. 组件自带一些功能与微信风 ...

  7. 微信小程序 - 组件化开发

    微信小程序 -- 组件化开发,总结一下开发思路及过程: 组件,类似于页面,一个自定义组件由 json wxml wxss js 4个文件组成. 1.首先,在 miniprogram 文件夹下,创建一个 ...

  8. 微信小程序组件 —— 带搜索功能的选择器

    微信小程序组件 -- 带搜索功能的选择器 效果 组件 search-picker 文件 wxml 文件: <view class="search-picker">< ...

  9. 微信小程序组件(标签)—码虫带你飞

    微信小程序组件(标签) 组件文档:https://mp.weixin.qq.com/debug/wxadoc/dev/component/ 常用布局标签 <view></view&g ...

最新文章

  1. 打印机在计算机里被删掉,不小心把设置里打印机删掉了怎么办
  2. outlook 2010 记忆式键入不工作的解决办法
  3. bzoj 3223: Tyvj 1729 文艺平衡树
  4. java中bubblesort是什么意思_排序--冒泡排序BubbleSort(Java)
  5. 基于DDDLite的权限管理OpenAuth.net 1.0版正式发布
  6. JQ实现情人节表白程序
  7. 即时通讯领域必将最终由XMPP协议一统天下
  8. Android Studio 使用魅族手机调试时,不显示 Log 的解决方法
  9. python爬取网页美文网文章内容
  10. 浩方对战平台原理初步分析
  11. 计算机主机故障有哪些,电脑硬件常见故障有哪些
  12. USB转RS485代替PC/PPI通讯电缆
  13. 浅谈计算机领域及职业憧憬
  14. 【第五章】综合实例:实现图片传送带
  15. 通过分析134家企业征信牌照机构可见企业征信备案之难
  16. 线性代数学习笔记——行列式的性质及拉普拉斯定理——10. k阶子式、余子式、代数余子式
  17. 《狂人日记》 解读|读后感
  18. 高通平台开发系列讲解(充电篇)充电底层驱动 power_supply 子系统
  19. NOJ 2094 以撒的谜题 (费用流)
  20. Linux usb 1. 总线简介

热门文章

  1. Ubuntu 查看磁盘空间大小命令转
  2. linux tc打造ip流量限制
  3. php mysql 备注_php,mysql备注信息1
  4. 适合初学者的数据结构_数据结构101:图-初学者的直观介绍
  5. Windows下的DNS命令用法
  6. 参加web前端培训需要注意什么
  7. PMP®考试是什么机构
  8. selenium--iframe之模拟qq空间登录
  9. 报错:该字符串未被识别为有效的DateTime
  10. C++语言学习(十二)——C++语言常见函数调用约定