展示星期+日期的组件(自己封装一下)

12 篇文章 0 订阅
12 篇文章 0 订阅

 效果图

 

<template>
	<view>
		<view class="app">
			<view class="head">
				<view class="cander">
					<view class="week">
						<view :class="currentDay == 1 ?'fontW':'day' ">
							 {{currentDay == 1 ?'今日':'一'}}
						</view>
						<view :class="currentDay == 1 ?'bgColor':'num' ">
							{{week.Mon}}
						</view>
					</view>
					<view class="week">
						<view :class="currentDay ==2 ?'fontW':'day' ">
						 {{currentDay == 2 ?'今日':'二'}}
						</view>
						<view :class="currentDay == 2 ?'bgColor':'num' ">
							{{week.Tues}}
						</view>
					</view>
					<view class="week">
						<view :class="currentDay == 3 ?'fontW':'day' ">
						 {{currentDay == 3 ?'今日':'三'}}
						</view>
						<view :class="currentDay == 3 ?'bgColor':'num' ">
							{{week.Wed}}
						</view>
					</view>
					<view class="week">
						<view :class="currentDay == 4 ?'fontW':'day' ">
							{{currentDay == 4 ?'今日':'四'}}
						</view>
						<view :class="currentDay == 4 ?'bgColor':'num' ">
							{{week.Thur}}
						</view>
					</view>
					<view class="week">
						<view :class="currentDay == 5 ?'fontW':'day' ">
							{{currentDay == 5 ?'今日':'五'}}
						</view>
						<view :class="currentDay == 5 ?'bgColor':'num' ">
							{{week.Fri}}
						</view>
					</view>
					<view class="week">
						<view :class="currentDay == 6 ?'fontW':'day' ">
							{{currentDay == 6?'今日':'六'}}
						</view>
						<view :class="currentDay == 6 ?'bgColor':'num' ">
							{{week.Sat}}
						</view>
					</view>
					<view class="week">
						<view :class="currentDay == 7 ?'fontW':'day' ">
							{{currentDay == 7 ?'今日':'日'}}
						</view>
						<view :class="currentDay == 7 ?'bgColor':'num' ">
							{{week.Sun}}
						</view>
					</view>
				</view>
			</view>
		</view>
		  
	</view>
</template>

<script>
	var that 
	export default {
		data() {
			return {
				currentDay:0,
				week:{},
				tabbar:tabbar,
				currentList:1,
			}
		},
		onLoad() {
			that = this
		},
		onShow() {
			let date = new Date()
			let t = date.getTime()
			let d = date.getDay()
			if(d == 0){
				d = 7
			}
			that.currentDay = d
			let oneDayt = 24*60*60*1000
			console.log(t,d)
			let Mon = new Date(t -(oneDayt * (d-1))).getDate()
			let Tues = new Date(t -(oneDayt * (d-2))).getDate()
			let Wed = new Date(t -(oneDayt * (d-3))).getDate()
			let Thur = new Date(t -(oneDayt * (d-4))).getDate()
			let Fri = new Date(t -(oneDayt * (d-5))).getDate()
			let Sat = new Date(t -(oneDayt * (d-6))).getDate()
			let Sun = new Date(t -(oneDayt * (d-7))).getDate()
			that.week = {Mon ,Tues ,Wed,Thur ,Fri ,Sat ,Sun}
 
		}
	}
</script>

<style lang="scss">
	
	
	.head {
		padding: 20rpx 0;
		border: 1px solid;
		box-shadow: 0 9rpx 8rpx -2rpx rgba(0,0,0,0.2);
		.cander {
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			.week {
				text-align: center;
				
				.fontW {
					font-weight: 700;
					font-size: 28rpx;
					margin-bottom: 10rpx;
				}
				.day {
					font-size: 28rpx;
					margin-bottom: 10rpx;
				}
				.num {
					border: 1px solid;
					width: 60rpx;
					height: 60rpx;
					border-radius: 50%;
					text-align: center;
					line-height: 60rpx;
				}
				.bgColor {
					background-color: $main;
					border: 1px solid;
					width: 60rpx;
					height: 60rpx;
					border-radius: 50%;
					text-align: center;
					line-height: 60rpx;
					color: $white;
				}
			}
		}
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

栈狮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值