91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

微信小程序可滑動周日歷組件使用詳解

發布時間:2020-09-28 22:26:05 來源:腳本之家 閱讀:632 作者:康彥 欄目:web開發

微信小程序可滑動周日歷組件,供大家參考,具體內容如下

看網上周日歷組件比較少,自己弄了一個,和大家分享一下。

如果樣式變形,請檢查是否有共用樣式起沖突

展示一下效果圖

微信小程序可滑動周日歷組件使用詳解

在components組件文件夾下新建calendarWeek文件夾

直接上代碼吧:

index.wxml

<!--components/calendarWeek/index.wxml-->
<!-- 日歷 -->
<view class="date-choose shrink border-bottom10">

 <picker mode="date" bindchange="tiaotime"><view class="data-month">{{dateYear}}{{dateMonth}}</view></picker>
 <swiper class="date-choose-swiper" circular="true" 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}}">
 <!-- <view>{{day.ids}}</view> -->
 <view class="day" id="{{day.id}}" bindtap="chooseDate" >
 <text class="{{dateCurrentStr==day.id?'active':''}}{{today==day.id?' reds':''}}" >{{day.day}}</text>
 </view>
 </block>
 </view>
 </swiper-item>
 </block>
 </swiper>
</view>
<!-- 日歷 -->

index.wxss

/* components/calendarWeek/index.wxss */

.date-choose {
 background: #fff;
 overflow: hidden;
 height: auto;
}
.data-month {
 width: 100%;
 align-items: center;
 padding: .35rem .35rem;
 text-align: left;
 color: #333;
 font-size: 38rpx;
}
.date-choose-swiper {
 flex-grow: 1;
 height: 182rpx;
}
.swiper-item {
 display: flex;
 flex-direction: column;
}
.weekday, .dateday {
 display: flex;
 justify-content: space-between;
 align-items: center;
 text-align: center;
 flex-wrap: wrap;
 flex-grow: 1;
}
.week, .day {
 width: 14.286%;
 flex-basis: 14.286%;
}
.week{
 color: #999;
 font-size: 24rpx;
}
.day text {
 position: relative;
 color: #333333;
}
.day .active:before {/* 圈圈 */
 content: "";
 position: absolute;
 width: 76rpx;
 height: 76rpx;
 top: 50%;
 left: 50%;
 -webkit-transform: translate(-50%, -50%);
 transform: translate(-50%, -50%);
 border: 1px solid red;
 border-radius: 100%;
 background: red;
 opacity: 0.1;
 z-index: -1;
}
.day text.active {
 color: red
}
.day text.reds {
 color: #ff0000;
}
/*開始*/

.headerone {
 width: 100%;
 height: auto;
 font-size: 24rpx;
 /* margin: 0 30rpx; */
}
.headerone .ra {
 margin-right: 20rpx;

}
.headerone .radio-group{
 margin: 20rpx 0 20rpx 30rpx;
}
.headertwo {
 width: 100%;
 height: auto;
 font-size: 24rpx;
 margin-top: 10rpx;
 margin-bottom: 26rpx;
}
.headertwo .le image {
 width: 70rpx;
 height: 70rpx;
 border-radius: 10px;
 margin-left: 30rpx;
 margin-right: 20rpx
}
.headertwo .ri {
 flex: 1;
 margin-right: 30rpx;
 border-radius: 6px;
 box-shadow:0px 1px 6px 0px rgba(198,198,198,0.5);
}
.headertwo .ri .one{
 width: 100%;
 padding-top: 24rpx;
 padding-bottom :24rpx
}
.headertwo .ri .one view .jiao {
 margin: 0 16rpx;
 border:15rpx solid;
 /* margin-top: 15rpx; */
 border-color: #ffffff #ffffff #b3b3b3 #ffffff;
}
.xi {
 background: red;
 color: #ffffff;
 padding:3px 10px;
 border-radius: 6px 0px 0 6px;

}
.headertwo .ri .one view view.jiaos {
 margin: 0 16rpx;
 border:15rpx solid;
 margin-top: 14rpx;
 border-color:#b3b3b3 #ffffff #ffffff #ffffff;
}
.headertwo .ri .two{
 width: 100%;
 overflow: hidden;
 transition: all 0.5s
}
.headertwo .ri .two .body{
 width: 100%;
 /* padding-left: 60rpx; */
 /* padding-right: 22rpx; */
 padding-top: 24rpx;
 padding-bottom :24rpx;

}

index.js

// components/calendarWeek/index.js
var utils = require('./util.js')
Component({
 /**
 * 組件的屬性列表
 */
 properties: {

 },

 /**
 * 組件的初始數據
 */
 data: {
 valtime: 8,
 dateList: [], // 日歷數據數組
 swiperCurrent: 0, // 日歷輪播正處在哪個索引位置
 dateCurrent: new Date(), // 正選擇的當前日期
 dateCurrentStr: '', // 正選擇日期的 id
 dateMonth: '1月', // 正顯示的月份
 dateListArray: ['日', '一', '二', '三', '四', '五', '六'],
 },
 ready: function () {
 var that = this;
 var today = utils.formatTime2(new Date());
 this.setData({
 today,
 });
 var d = new Date();
 this.initDate(-5, 2, d); // 日歷組件程序 -4左表示過去4周 右1表示過去一周

 },
 /**
 * 組件的方法列表
 */
 methods: {
 tiaotime(e) {
 let data = e.detail.value.split("-")
 var d = new Date(Number(data[0]), Number(data[1]) - 1, Number(data[2]));
 this.setData({
 dateList: []
 })
 this.initDate(-5, 2, d); // 日歷組件程序 -4左表示過去4周 右1表示過去一周
 },
 onShow: function (e) {
 wx.getSystemInfo({
 success: (res) => {
 this.setData({
 windowHeight: res.windowHeight,
 windowWidth: res.windowWidth,
 });
 }
 });
 },

 // 日歷組件部分
 // ----------------------------
 initDate(left, right, d) {
 var month = utils.addZero(d.getMonth() + 1),
 year = utils.addZero(d.getFullYear()),
 day = utils.addZero(d.getDate());
 for (var i = left; i <= right; i++) {
 this.updateDate(utils.DateAddDay(d, i * 7));//多少天之后的
 }
 
 this.setData({
 swiperCurrent: 5,
 dateCurrent: d,
 dateCurrentStr: d.getFullYear() + '-' + month + '-' + day,
 dateMonth: month + '月',
 dateYear: year + '年',
 dateCurrentStr: year + "-" + month + "-" + day,
 });
 },
 // 獲取這周從周日到周六的日期
 calculateDate(_date) {
 var first = utils.FirstDayInThisWeek(_date);
 var d = {
 'month': first.getMonth() + 1,
 'days': [],

 };
 for (var i = 0; i < 7; i++) {
 var dd = utils.DateAddDay(first, i);
 var day = utils.addZero(dd.getDate()),
 year = utils.addZero(dd.getFullYear()),
 month = utils.addZero(dd.getMonth() + 1);

 d.days.push({
 'day': day,
 'id': dd.getFullYear() + '-' + month + '-' + day,
 'ids': dd.getFullYear() + ',' + month + ',' + day,
 });
 }
 return d;
 },
 // 更新日期數組數據
 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) {
 const lastIndex = this.data.swiperCurrent
 , currentIndex = e.detail.current
 , dateList = this.data.dateList
 , dateListlen = this.data.dateList.length
 let flag = false
 , key = 'lastMonth' //判斷是左劃還是右
 // console.log(lastIndex , currentIndex)
 if (lastIndex > currentIndex) {
 lastIndex === 7 && currentIndex === 0
 ? flag = true
 : null

 } else {
 lastIndex === 0 && currentIndex === 7
 ? null
 : flag = true
 }
 if (flag) {
 key = 'nextMonth'
 }
 if (key == 'lastMonth') {
 let nowindex = currentIndex - 3;
 let uptime = currentIndex - 4;
 let a = 0;
 if (nowindex < 0) { nowindex = nowindex + 8; a = 0 }
 if (uptime < 0) { uptime = uptime + 8 }

 let seltime = dateList[nowindex].days[a].ids
 var week = this.calculateDate(utils.formatTime(utils.DateAddDay(seltime, -1)));

 dateList[uptime] = week
 this.setData({
 dateList: dateList
 })

 }
 if (key == 'nextMonth') {
 let indexne = 0
 let aa = 0
 if (currentIndex == 7) { //要更新的下標
 indexne = 0
 aa = 1
 } else {
 indexne = currentIndex + 1
 aa = currentIndex + 2
 }
 if (aa == 8) {
 aa = 0
 }
 //aa 要更新的數組下標 datanex要往后查詢一周的日期
 let datanex = dateList[indexne].days[6].ids
 //獲取下一周的
 var week = this.calculateDate(utils.formatTime(utils.DateAddDay(datanex, 1)));
 dateList[aa] = week
 
 this.setData({
 dateList: dateList
 })
 }

 var d = this.data.dateList[currentIndex];
 let da = new Date(d.days[0].ids)
 this.setData({
 swiperCurrent: currentIndex,
 dateMonth: d.month + '月',
 dateYear: da.getFullYear()+"年"
 })

 },
 // 獲得日期字符串
 getDateStr: function (arg) {
 if (utils.type(arg) == 'array') {
 return arr[0] + '-' + arr[1] + '-' + arr[2] + ' 00:00:00';
 } else if (utils.type(arg) == 'date') {
 return arg.getFullYear() + '-' + (arg.getMonth() + 1) + '-' + arg.getDate() + ' 00:00:00';
 } else if (utils.type(arg) == 'object') {
 return arg.year + '-' + arg.month + '-' + arg.day + ' 00:00:00';
 }
 },

 // 點擊日歷某日
 chooseDate(e) {
 var str = e.currentTarget.id;
 // console.log(str);
 this.setData({ dateCurrentStr: str });
 this.triggerEvent('mydata', { data: str })
 },
 }
})

要引入util.js

// 時間格式轉換 yyyy/mm/dd
function formatTime(date) {
 var year = date.getFullYear()
 var month = date.getMonth() + 1
 var day = date.getDate()

 var hour = date.getHours()
 var minute = date.getMinutes()
 var second = date.getSeconds()


 return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
// 時間格式轉換 yyyy-mm-dd
function formatTime2(date) {
 var year = date.getFullYear()
 var month = date.getMonth() + 1
 var day = date.getDate()

 var hour = date.getHours()
 var minute = date.getMinutes()
 var second = date.getSeconds()


 return [year, month, day].map(formatNumber).join('-') 
}

function formatDate(date, split) {
 var year = date.getFullYear()
 var month = date.getMonth() + 1
 var day = date.getDate()
 return [year, month, day].map(formatNumber).join(split || '')
}

// 兩位數自動補零
function formatNumber(n) {
 n = n.toString()
 return n[1] ? n : '0' + n
}

// 兩位數以內的數字自動補零
function formatNumber(n) {
 n = n.toString()
 return n[1] ? n : '0' + n
}


// 計算變化多少天后的日期
function DateAddDay(d, days) {
 
 var d = new Date(d);
 return new Date(d.setDate(d.getDate() + days));
}
// 獲得本周周日的日期
function FirstDayInThisWeek(d) {
 
 var d = new Date(d);
 // console.log(formatTime(DateAddDay(d, 0 - d.getDay())));
 return DateAddDay(d, 0 - d.getDay());
}

// 判斷類型
function Type(obj) {
 var typeStr = Object.prototype.toString.call(obj).split(" ")[1];
 return typeStr.substr(0, typeStr.length - 1).toLowerCase();
}

module.exports = {
 formatTime: formatTime,
 formatDate: formatDate,
 formatTime2,
 DateAddDay: DateAddDay,
 FirstDayInThisWeek: FirstDayInThisWeek,
 type: Type,
 addZero: formatNumber,
}

調用組件

//json文件調用
"usingComponents": {
 "calendarMonth": "../../components/calendarWeek/index"
}

頁面調用組件

//mydata觸發的點擊日期時觸發的事件 可獲取當前點擊的日期
 <calendarMonth bindmydata="mydata"></calendarMonth>

當前頁面js

//js里的事件
 mydata(e){ //可獲取日歷點擊事件
 let data = e.detail.data
 console.log(data)
}

更多精彩的日歷效果請學習參考專題:javascript日歷插件

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

八宿县| 三穗县| 徐州市| 滨海县| 苍溪县| 治多县| 金坛市| 唐河县| 萝北县| 东乡| 专栏| 万荣县| 萨迦县| 互助| 宾川县| 永福县| 夏津县| 海兴县| 呼图壁县| 马鞍山市| 南召县| 梧州市| 卓尼县| 太仆寺旗| 闽侯县| 武宁县| 嘉定区| 扬中市| 靖宇县| 正镶白旗| 桃园县| 海南省| 大冶市| 河西区| 嘉义县| 沂南县| 安图县| 贞丰县| 东台市| 柳州市| 志丹县|