uni-app实现可滑动日历

news2024/9/21 20:43:33

效果:
在这里插入图片描述
uni-calendar.vue

<template>
	<view class="uni-calendar">
		<view v-if="!insert&&show" class="uni-calendar__mask" :class="{'uni-calendar--mask-show':aniMaskShow}" @click="clean"></view>
		<view v-if="insert || show" class="uni-calendar__content" :class="{'uni-calendar--fixed':!insert,'uni-calendar--ani-show':aniMaskShow}">
			<view v-if="!insert" class="uni-calendar__header uni-calendar--fixed-top">
				<view class="uni-calendar__header-btn-box" @click="close">
					<text class="uni-calendar__header-text uni-calendar--fixed-width">{{cancelText}}</text>
				</view>
				<view class="uni-calendar__header-btn-box" @click="confirm">
					<text class="uni-calendar__header-text uni-calendar--fixed-width">{{okText}}</text>
				</view>
			</view>
			<view class="uni-calendar__header">
				<view class="uni-calendar__header-btn-box" @click.stop="pre" v-if="!disabled">
					<view class="uni-calendar__header-btn uni-calendar--left"></view>
				</view>
				<picker mode="date" :disabled="disabled" :value="date" fields="month" @change="bindDateChange">
					<text class="uni-calendar__header-text">{{ (nowDate.year||'') +' / '+( nowDate.month||'')}}</text>
				</picker>
				<view class="uni-calendar__header-btn-box" @click.stop="next" v-if="!disabled">
					<view class="uni-calendar__header-btn uni-calendar--right"></view>
				</view>
				<text class="uni-calendar__backtoday" @click="backtoday" v-if="!disabled">{{todayText}}</text>

			</view>
			<view class="uni-calendar__box">
				<view v-if="showMonth" class="uni-calendar__box-bg">
					<text class="uni-calendar__box-bg-text">{{nowDate.month}}</text>
				</view>
				<view class="uni-calendar__weeks">
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{SUNText}}</text>
					</view>
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{monText}}</text>
					</view>
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{TUEText}}</text>
					</view>
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{WEDText}}</text>
					</view>
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{THUText}}</text>
					</view>
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{FRIText}}</text>
					</view>
					<view class="uni-calendar__weeks-day">
						<text class="uni-calendar__weeks-day-text">{{SATText}}</text>
					</view>
				</view>
				<!-- <view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeks" :key="weekIndex">
					<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
						<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate" :disabled="disabled"></calendar-item>
					</view>
				</view> -->
				<swiper style="height: 345px" :current="current" circular @change="changeDate">
					<swiper-item v-if="!disableTouch">
						<view class="uni-calendar__weeks" v-for="(item,weekIndex) in preWeeksCpd" :key="weekIndex">
							<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
								<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate" :disabled="disabled" :ready="ready"></calendar-item>
							</view>
						</view>
					</swiper-item>
					<swiper-item>
						<view class="uni-calendar__weeks" v-for="(item,weekIndex) in weeksCpd" :key="weekIndex">
							<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
								<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate" :disabled="disabled" :ready="ready"></calendar-item>
							</view>
						</view>
					</swiper-item>
					<swiper-item v-if="!disableTouch">
						<view class="uni-calendar__weeks" v-for="(item,weekIndex) in nextWeeksCpd" :key="weekIndex">
							<view class="uni-calendar__weeks-item" v-for="(weeks,weeksIndex) in item" :key="weeksIndex">
								<calendar-item class="uni-calendar-item--hook" :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate" :disabled="disabled" :ready="ready"></calendar-item>
							</view>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
	</view>
</template>

<script>
	import Calendar from './util.js';
	import calendarItem from './uni-calendar-item.vue'
	import {
	initVueI18n
	} from '@dcloudio/uni-i18n'
	import messages from './i18n/index.js'
	const {	t } = initVueI18n(messages)
	/**
	 * Calendar 日历
	 * @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
	 * @tutorial https://ext.dcloud.net.cn/plugin?id=56
	 * @property {String} date 自定义当前时间,默认为今天
	 * @property {Boolean} lunar 显示农历
	 * @property {String} startDate 日期选择范围-开始日期
	 * @property {String} endDate 日期选择范围-结束日期
	 * @property {Boolean} range 范围选择
	 * @property {Boolean} insert = [true|false] 插入模式,默认为false
	 * 	@value true 弹窗模式
	 * 	@value false 插入模式
	 * @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
	 * @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
	 * @property {Boolean} showMonth 是否选择月份为背景
	 * @event {Function} change 日期改变,`insert :ture` 时生效
	 * @event {Function} confirm 确认选择`insert :false` 时生效
	 * @event {Function} monthSwitch 切换月份时触发
	 * @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
	 */
	export default {
		components: {
			calendarItem
		},
		emits:['close','confirm','change','monthSwitch'],
		props: {
			// 是否禁用滑动
			disableTouch: {
				type: Boolean,
				default: false
			},
			date: {
				type: String,
				default: ''
			},
			disabled: {
				type: Boolean,
				default: false
			},
			selected: {
				type: Array,
				default () {
					return []
				}
			},
			lunar: {
				type: Boolean,
				default: false
			},
			startDate: {
				type: String,
				default: ''
			},
			endDate: {
				type: String,
				default: ''
			},
			range: {
				type: Boolean,
				default: false
			},
			insert: {
				type: Boolean,
				default: true
			},
			showMonth: {
				type: Boolean,
				default: true
			},
			clearDate: {
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				ready: false, // 日历自定义渲染图文是否就绪
				calendarDirection: '',
				current: 1,
				lastCurrent: 1,
				show: false,
				preWeeks: [],
				weeks: [],
				nextWeeks: [],
				calendar: {},
				nowDate: '',
				aniMaskShow: false
			}
		},
		computed:{
			weeksCpd(){
				return this.weeks;
			},
			preWeeksCpd(){
				return this.preWeeks;
			},
			nextWeeksCpd(){
				return this.nextWeeks;
			},
			/**
			 * for i18n
			 */

			okText() {
				return t("uni-calender.ok")
			},
			cancelText() {
				return t("uni-calender.cancel")
			},
			todayText() {
				return t("uni-calender.today")
			},
			monText() {
				return t("uni-calender.MON")
			},
			TUEText() {
				return t("uni-calender.TUE")
			},
			WEDText() {
				return t("uni-calender.WED")
			},
			THUText() {
				return t("uni-calender.THU")
			},
			FRIText() {
				return t("uni-calender.FRI")
			},
			SATText() {
				return t("uni-calender.SAT")
			},
			SUNText() {
				return t("uni-calender.SUN")
			},
		},
		watch: {
			date(newVal) {
				// this.cale.setDate(newVal)
				this.init(newVal)
			},
			startDate(val){
				this.cale.resetSatrtDate(val)
				this.cale.setDate(this.nowDate.fullDate)
				this.weeks = this.cale.weeks
			},
			endDate(val){
				this.cale.resetEndDate(val)
				this.cale.setDate(this.nowDate.fullDate)
				this.weeks = this.cale.weeks
			},
			selected(newVal) {
				const _t = this;
				_t.cale.setSelectInfo(_t.nowDate.fullDate, newVal)
				// _t.calendarDirection = ''
				if(_t.calendarDirection === 'prev') {
					_t.nextWeeks = _t.cale.weeks;
					console.log("执行1");
				}else if(_t.calendarDirection === 'next'){
					_t.preWeeks = _t.cale.weeks;
					console.log("执行2");
				}else {
					_t.weeks = _t.cale.weeks
					console.log("执行3");
				}
				_t.ready = true;
			}
		},
		created() {
			// 获取日历方法实例
			this.cale = new Calendar({
				// date: new Date(),
				selected: this.selected,
				startDate: this.startDate,
				endDate: this.endDate,
				range: this.range,
			})
			// 选中某一天
			// this.cale.setDate(this.date)
			this.init(this.date)
			// this.setDay
		},
		methods: {
			changeDateNext(){
				const _t = this;
				const date = this.cale.getDate(this.nowDate.fullDate, 1, 'month').fullDate
				const theDate = this.cale.getDate(date).fullDate;
				const preDate = this.cale.getDate(theDate, -1, 'month').fullDate
				const nextDate = this.cale.getDate(theDate, +1, 'month').fullDate
				this.cale.setDate(preDate, "pre") // 初始上一月份
				this.cale.setDate(nextDate, "next") // 初始下一月份
				this.cale.setDate(date) // 初始当前月份
				this.weeks = this.cale.preWeeks
				this.preWeeks = this.cale.nextWeeks
				this.nextWeeks = this.cale.weeks
				this.nowDate = this.calendar = this.cale.getInfo(date)
				_t.monthSwitch()	
			},
			changeDatePre(){
				const _t = this;
				const date = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate
				const theDate = this.cale.getDate(date).fullDate;
				const preDate = this.cale.getDate(theDate, -1, 'month').fullDate
				const nextDate = this.cale.getDate(theDate, +1, 'month').fullDate
				this.cale.setDate(preDate, "pre") // 初始上一月份
				this.cale.setDate(nextDate, "next") // 初始下一月份
				this.cale.setDate(date) // 初始当前月份
				this.weeks = this.cale.nextWeeks
				this.preWeeks = this.cale.weeks
				this.nextWeeks = this.cale.preWeeks
				this.nowDate = this.calendar = this.cale.getInfo(date)
				_t.monthSwitch()		
			},
			updateMonth(){
				const _t = this;
				const theDate = _t.nowDate.fullDate;
				_t.cale.setDate(_t.cale.getDate(theDate, -1, 'month').fullDate, "pre")  
				_t.cale.setDate(_t.cale.getDate(theDate, +1, 'month').fullDate, "next") 
			},
			changeDate(e){
				const _t = this;
				const primaryCurrent = _t.lastCurrent
				let current = e.detail.current;
				_t.current = current;
				if(_t.touchTimer) {
					clearTimeout(_t.touchTimer)
					_t.touchTimer = null;
					_t.lastCurrent = current;
				}
				_t.touchTimer = setTimeout(() => {
					if(primaryCurrent - current == -1 || primaryCurrent - current == 2){
						_t.lastCurrent = current;
						const nextDate = _t.cale.getDate(_t.nowDate.fullDate, +1, 'month').fullDate
						console.log("左滑");
						_t.cale.setDate(nextDate)
						_t.nowDate = _t.calendar = _t.cale.getInfo(nextDate)
						_t.updateMonth();
						if(primaryCurrent - current == -1 && current != 1){
							_t.ready = false;
							_t.changeDateMonth('prev')
							_t.calendarDirection = 'prev'
						}else if(primaryCurrent - current == 2){
							_t.ready = false;
							_t.changeDateMonth('next')
							_t.calendarDirection = 'next'
						}else {
							_t.calendarDirection = ''
						}
					}else{
						console.log("右滑");
						_t.lastCurrent = current;
						const preDate = _t.cale.getDate(_t.nowDate.fullDate, -1, 'month').fullDate
						_t.cale.setDate(preDate)
						_t.nowDate = _t.calendar = _t.cale.getInfo(preDate)
						_t.updateMonth();
						if(primaryCurrent - current == 1 && current != 1){
							_t.ready = false;
							_t.changeDateMonth('next')
							_t.calendarDirection = 'next'
						}else if(primaryCurrent - current == -2){
							_t.ready = false;
							_t.changeDateMonth('prev')
							_t.calendarDirection = 'prev'
						}else {
							_t.calendarDirection = ''
						}
					}
					_t.monthSwitch()
					console.log("nowDate", _t.nowDate);
				},500)
			},
			// 取消穿透
			clean() {},
			bindDateChange(e) {
				const value = e.detail.value + '-1'
				// console.log(this.cale.getDate(value));
				this.init(value)
				this.setEmit('dateChange');
			},
			/**
			 * 初始化日期显示
			 * @param {Object} date
			 */
			init(date) {
				const _t = this;
				// 滑块归位
				const theDate = _t.cale.getDate(date).fullDate;
				const preDate = _t.cale.getDate(theDate, -1, 'month').fullDate
				const nextDate = _t.cale.getDate(theDate, +1, 'month').fullDate
				_t.cale.setDate(preDate, "pre") // 初始上一月份
				_t.cale.setDate(nextDate, "next") // 初始下一月份
				_t.cale.setDate(date) // 初始当前月份
				if(_t.calendarDirection) {
					 _t.changeDateMonth(_t.calendarDirection)
				}else {
					_t.weeks = _t.cale.weeks
					_t.preWeeks = _t.cale.preWeeks
					_t.nextWeeks = _t.cale.nextWeeks
				}
				_t.nowDate = _t.calendar = _t.cale.getInfo(date)
			},
			changeDateMonth(type){
				const _t = this;
				if(type == 'prev'){
					_t.weeks = _t.cale.preWeeks;
					_t.preWeeks = _t.cale.nextWeeks;
					_t.nextWeeks = _t.cale.weeks;
				}else if(type == 'next'){
					_t.weeks = _t.cale.nextWeeks;
					_t.nextWeeks = _t.cale.preWeeks;
					_t.preWeeks = _t.cale.weeks;
				}
			},
			/**
			 * 打开日历弹窗
			 */
			open() {
				// 弹窗模式并且清理数据
				if (this.clearDate && !this.insert) {
					this.cale.cleanMultipleStatus()
					// this.cale.setDate(this.date)
					this.init(this.date)
				}
				this.show = true
				this.$nextTick(() => {
					setTimeout(() => {
						this.aniMaskShow = true
					}, 50)
				})
			},
			/**
			 * 关闭日历弹窗
			 */
			close() {
				this.aniMaskShow = false
				this.$nextTick(() => {
					setTimeout(() => {
						this.show = false
						this.$emit('close')
					}, 300)
				})
			},
			/**
			 * 确认按钮
			 */
			confirm() {
				this.setEmit('confirm')
				this.close()
			},
			/**
			 * 变化触发
			 */
			change() {
				if (!this.insert) return
				this.setEmit('change')
			},
			/**
			 * 选择月份触发
			 */
			monthSwitch() {
				let {
					year,
					month
				} = this.nowDate
				this.$emit('monthSwitch', {
					year,
					month: Number(month)
				})
			},
			/**
			 * 派发事件
			 * @param {Object} name
			 */
			setEmit(name) {
				let {
					year,
					month,
					date,
					fullDate,
					lunar,
					extraInfo
				} = this.calendar
				this.$emit(name, {
					range: this.cale.multipleStatus,
					year,
					month,
					date,
					fulldate: fullDate,
					lunar,
					extraInfo: extraInfo || {}
				})
			},
			/**
			 * 选择天触发
			 * @param {Object} weeks
			 */
			choiceDate(weeks) {
				if (weeks.disable) return
				this.calendar = weeks
				// 设置多选
				this.cale.setMultiple(this.calendar.fullDate)
				this.weeks = this.cale.weeks
				this.change()
			},
			/**
			 * 回到今天
			 */
			backtoday() {
				let date = this.cale.getDate(new Date()).fullDate
				this.init(date)
				this.change()
			},
			/**
			 * 上个月
			 */
			pre() {
				// const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate
				// this.setDate(preDate)
				// this.monthSwitch()
				const _t = this;
				let current = _t.lastCurrent = _t.current;
				_t.current = --current < 0 ? 2 : current
				// console.log("_t.current", _t.current);
			},
			/**
			 * 下个月
			 */
			next() {
				// const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate
				// this.setDate(nextDate)
				// this.monthSwitch()
				const _t = this;
				let current = _t.lastCurrent = _t.current;
				_t.current = ++current > 2 ? 0 : current
				// console.log("_t.current", _t.current);
			},
			/**
			 * 设置日期
			 * @param {Object} date
			 */
			setDate(date) {
				this.cale.setDate(date)
				this.weeks = this.cale.weeks
				this.preWeeks = this.cale.preWeeks
				this.nextWeeks = this.cale.nextWeeks
				this.nowDate = this.cale.getInfo(date)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-calendar {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.uni-calendar__mask {
		position: fixed;
		bottom: 0;
		top: 0;
		left: 0;
		right: 0;
		background-color: $uni-bg-color-mask;
		transition-property: opacity;
		transition-duration: 0.3s;
		opacity: 0;
		/* #ifndef APP-NVUE */
		z-index: 99;
		/* #endif */
	}

	.uni-calendar--mask-show {
		opacity: 1
	}

	.uni-calendar--fixed {
		position: fixed;
		bottom: calc(var(--window-bottom));
		left: 0;
		right: 0;
		transition-property: transform;
		transition-duration: 0.3s;
		transform: translateY(460px);
		/* #ifndef APP-NVUE */
		z-index: 99;
		/* #endif */
	}

	.uni-calendar--ani-show {
		transform: translateY(0);
	}

	.uni-calendar__content {
		background-color: #fff;
	}

	.uni-calendar__header {
		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		align-items: center;
		height: 50px;
		border-bottom-color: $uni-border-color;
		border-bottom-style: solid;
		border-bottom-width: 1px;
	}

	.uni-calendar--fixed-top {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: space-between;
		border-top-color: $uni-border-color;
		border-top-style: solid;
		border-top-width: 1px;
	}

	.uni-calendar--fixed-width {
		width: 50px;
		// padding: 0 15px;
	}

	.uni-calendar__backtoday {
		position: absolute;
		right: 0;
		top: 25rpx;
		padding: 0 5px;
		padding-left: 10px;
		height: 25px;
		line-height: 25px;
		font-size: 12px;
		border-top-left-radius: 25px;
		border-bottom-left-radius: 25px;
		color: $uni-text-color;
		background-color: $uni-bg-color-hover;
	}

	.uni-calendar__header-text {
		text-align: center;
		width: 100px;
		font-size: $uni-font-size-base;
		color: $uni-text-color;
	}

	.uni-calendar__header-btn-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: center;
		width: 50px;
		height: 50px;
	}

	.uni-calendar__header-btn {
		width: 10px;
		height: 10px;
		border-left-color: $uni-text-color-placeholder;
		border-left-style: solid;
		border-left-width: 2px;
		border-top-color: $uni-color-subtitle;
		border-top-style: solid;
		border-top-width: 2px;
	}

	.uni-calendar--left {
		transform: rotate(-45deg);
	}

	.uni-calendar--right {
		transform: rotate(135deg);
	}


	.uni-calendar__weeks {
		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	.uni-calendar__weeks-item {
		flex: 1;
	}

	.uni-calendar__weeks-day {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 45px;
		border-bottom-color: #F5F5F5;
		border-bottom-style: solid;
		border-bottom-width: 1px;
	}

	.uni-calendar__weeks-day-text {
		font-size: 14px;
	}

	.uni-calendar__box {
		position: relative;
	}

	.uni-calendar__box-bg {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
	}

	.uni-calendar__box-bg-text {
		font-size: 200px;
		font-weight: bold;
		color: $uni-text-color-grey;
		opacity: 0.1;
		text-align: center;
		/* #ifndef APP-NVUE */
		line-height: 1;
		/* #endif */
	}
</style>

uni-calendar-item.vue

<template>
	<view class="uni-calendar-item__weeks-box" 
	:style="{ 'background-color': (ready && weeks.extraInfo.color && weeks.extraInfo.clickable) ? weeks.extraInfo.color : ''}"
	:class="{
		'uni-calendar-item--disable':weeks.disable,
		'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
		'uni-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay) ,
		'uni-calendar-item--before-checked':weeks.beforeMultiple,
		'uni-calendar-item--multiple': weeks.multiple,
		'uni-calendar-item--after-checked':weeks.afterMultiple,
		}"
	 @click="choiceDate(weeks)">
		<view class="uni-calendar-item__weeks-box-item" 
			:style="{ 'background-color': (ready && weeks.extraInfo && weeks.extraInfo.color && weeks.extraInfo.clickable) ? weeks.extraInfo.color : '' }">
		<!-- 	<view v-if="selected&&weeks.extraInfo" class="uni-calendar-item__weeks-box-circle" :style="{ 'background-color': '' }"> 
				<text class="uni-calendar-item__weeks-box-circle-label">{{ (weeks.extraInfo && weeks.extraInfo.triangleLabel) ? weeks.extraInfo.triangleLabel : '' }}</text>
			</view> -->
			<text class="uni-calendar-item__weeks-box-text" :class="{
				'uni-calendar-item--isDay-text': weeks.isDay,
				'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
				'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
				'uni-calendar-item--before-checked':weeks.beforeMultiple,
				'uni-calendar-item--multiple': weeks.multiple,
				'uni-calendar-item--after-checked':weeks.afterMultiple,
				'uni-calendar-item--disable':weeks.disable,
				}">{{weeks.date}}</text>
			<text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uni-calendar-item__weeks-lunar-text" :class="{
				'uni-calendar-item--isDay-text':weeks.isDay,
				'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
				'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
				'uni-calendar-item--before-checked':weeks.beforeMultiple,
				'uni-calendar-item--multiple': weeks.multiple,
				'uni-calendar-item--after-checked':weeks.afterMultiple,
				}">{{todayText}}</text>
			<text v-if="lunar&&!weeks.extraInfo" class="uni-calendar-item__weeks-lunar-text" :class="{
				'uni-calendar-item--isDay-text':weeks.isDay,
				'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
				'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
				'uni-calendar-item--before-checked':weeks.beforeMultiple,
				'uni-calendar-item--multiple': weeks.multiple,
				'uni-calendar-item--after-checked':weeks.afterMultiple,
				'uni-calendar-item--disable':weeks.disable,
				}">{{weeks.isDay ? todayText : (weeks.lunar.IDayCn === '初一'?weeks.lunar.IMonthCn:weeks.lunar.IDayCn)}}</text>
			<view v-if="weeks.extraInfo&&weeks.extraInfo.info&&!weeks.extraInfo.value.includes('_') " 
			class="uni-calendar-item__weeks-lunar-text" 
			:class="{
				'uni-calendar-item--extra':weeks.extraInfo.info,
				'uni-calendar-item--isDay-text':weeks.isDay,
				'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
				'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
				'uni-calendar-item--before-checked':weeks.beforeMultiple,
				'uni-calendar-item--multiple': weeks.multiple,
				'uni-calendar-item--after-checked':weeks.afterMultiple,
				'uni-calendar-item--disable':weeks.disable,
				}" style="display:flex; position: absolute; left: 0; bottom: 0px; top: 0; right: 0; justify-content: center; align-items: center;">
					<view class="power" style="display: flex; align-items: center; justify-content: center; color: #000">
						<text class="value">
							{{ weeks.extraInfo.value || '' }}
						</text>
						<text style="font-size: 9rpx;">
							{{ weeks.extraInfo.triangleLabel || '' }}
						</text>
					</view>
				</view>
		</view>
	</view>
</template>

<script>
	import {
	initVueI18n
	} from '@dcloudio/uni-i18n'
	import messages from './i18n/index.js'
	const {	t	} = initVueI18n(messages)
	export default {
		emits:['change'],
		data(){
			return {
				testColor: '#f40'
			}
		},
		props: {
			ready: {
				type: Boolean,
				default: false
			},
			disabled: {
				type: Boolean,
				default: false
			},
			weeks: {
				type: Object,
				default () {
					return {}
				}
			},
			calendar: {
				type: Object,
				default: () => {
					return {}
				}
			},
			selected: {
				type: Array,
				default: () => {
					return []
				}
			},
			lunar: {
				type: Boolean,
				default: false
			}
		},
		computed: {
			todayText() {
				return t("uni-calender.today")
			},
		},
		methods: {
			choiceDate(weeks) {
				console.log("选中得时间节点:", weeks)
				weeks.extraInfo && weeks.extraInfo.clickable && this.$emit('change', weeks)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-calendar-item__weeks-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		border: 0.1px solid #F0F0F0;
	}

	.uni-calendar-item__weeks-box-text {
		font-size: $uni-font-size-base;
		color: $uni-text-color;
	}

	.uni-calendar-item__weeks-lunar-text {
		font-size: $uni-font-size-sm;
		color: $uni-text-color;
	}

	.uni-calendar-item__weeks-box-item {
		position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		// flex-direction: column;
		// justify-content: center;
		// align-items: center;
		width: 100%;
		height: 55px;
		overflow: hidden;
	}

	.uni-calendar-item__weeks-box-circle {
		position: absolute;
		top: 0px;
		right: 0px;
		width: 30px;
		height: 30px;
		display: flex;
		align-items: flex-start;
		justify-content: flex-end;
		clip-path: polygon(0 0, 100% 0, 100% 100%);
		opacity: 0.8;
		
		&-label{
			color: #000;
			font-size: 12rpx;
			// transform: rotate(45deg);
			// position: absolute;
			white-space: nowrap;
			margin-top: 5rpx;
			margin-right: 5rpx;
		}
	}

	.uni-calendar-item--disable {
		// background-color: rgba(249, 249, 249, $uni-opacity-disabled);
		background-color: transparent;
		color: #000;
		// color: $uni-text-color-disable;
	}

	.uni-calendar-item--isDay-text {
		// color: $uni-color-primary;
	}

	.uni-calendar-item--isDay {
		// background-color: $uni-color-primary;
		background-color: transparent;
		opacity: 0.8;
		color: #fff;
	}

	.uni-calendar-item--extra {
		color: $uni-color-error;
		opacity: 0.8;
		.power{
			width:100%;
			display: flex;
			overflow: hidden;
			max-width:100rpx;
			.remark-common{
				max-width:100rpx;
				text-align: left;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
			.value{
				@extend .remark-common;
				// $charge: #53bf18;
				// $discharge: #f3a405;
				color: #000;
				font-size: 18rpx;
			}
		}
	}

	.uni-calendar-item--checked {
		// background-color: $uni-color-primary;
		color: #000;
		opacity: 0.8;
	}

	.uni-calendar-item--multiple {
		background-color: $uni-color-primary;
		color: #fff;
		opacity: 0.8;
	}
	.uni-calendar-item--before-checked {
		background-color: #ff5a5f;
		color: #fff;
	}
	.uni-calendar-item--after-checked {
		background-color: #ff5a5f;
		color: #fff;
	}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/377728.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

项目难点——【4】分布式事务

项目难点——【4】分布式事务 1 概述 我们想知道什么是分布式事务首先了解下什么是本地事务。 平常我们在程序中通过spring去控制事务是利用数据库本身的事务特性来实现的&#xff0c;因此叫数据 库事务&#xff0c;由于应用主要靠关系数据库来控制事务&#xff0c;而数据库通…

顺序表(2)

目录 1、线性表 2、顺序表 1、概念及结构 2、接口实现 1、SeqList.h 2、SeqList.c 3、练习 例1、移除元素 例2、删除有序数组中的重复项 例3、合并两个有序数组 1、线性表 线性表&#xff08;linear list&#xff09;是n个具有相同特性的数据元素的有限序列&#xff…

运行你的第一个 Django APP

Django 版本&#xff1a;4.1.7 Python 版本&#xff1a;3.9.13 目录一、运行 Django二、创建 APP一、运行 Django 1、新建项目&#xff08;Project&#xff09; 项目类型为 Django&#xff0c;选择虚拟环境&#xff0c;点击 Create 后就会自动下载并安装 Django。 如果你是在 …

机器学习——支持向量机学习

支持向量机(Support Vector Machine, SVM)不仅具有坚实的统计学理论基础,还可以很好地应用于高维数据、避免维度灾难问题&#xff0c;已经成为一种倍受关注的机器学习分类技术。为了解释SVM的基本思想,我们首先介绍一下最大边缘超平面(Maximal Margin Hyperplane)给定训练数据集…

C++STL详解(三)——vector的介绍和使用

文章目录vector的介绍vector的使用vector的定义方式vector的空间增长问题reserve和resizevector的迭代器使用begin 和endrbegin和rendinsert 和erasefind函数元素访问vector迭代器失效问题1&#xff1a;inserse插入扩容时空间销毁造成野指针问题2&#xff1a;erase删除或者inse…

什么是“奥卡姆剃刀”,如何用“奥卡姆剃刀”解决复杂问题?复杂问题简单化

什么是“奥卡姆剃刀”&#xff0c;如何用“奥卡姆剃刀”解决复杂问题&#xff1f;复杂问题简单化问题什么是“奥卡姆剃刀”?如何使用“奥卡姆剃刀”解决问题复杂问题简单化“汉隆剃刀”小结问题 假设你在夜空中看到一颗闪闪发光的「不明飞行物」&#xff0c;你认为这会是什么呢…

优秀的IC/FPGA开源项目(六)-手语字母翻译器

《优秀的IC/FPGA开源项目》是新开的系列&#xff0c;旨在介绍单一项目&#xff0c;会比《优秀的 Verilog/FPGA开源项目》内容介绍更加详细&#xff0c;包括但不限于综合、上板测试等。两者相辅相成&#xff0c;互补互充~一种智能手套&#xff0c;可将手语字母翻译成带显示器的书…

【分享】订阅集简云畅捷通T+cloud连接器自动同步财务费用单至畅捷通

方案场景 伴随公司发展和数字化水平提高&#xff0c;大量的财务单据需要手动审核和录入&#xff0c;这些重复机械的操作占据大量人力&#xff0c;同时极容易出现数据出错或丢失等情况&#xff0c;严重影响着企业经营效率。 使用集简云提供服务的畅捷通TCloud钉钉连接器完成财…

UML 类关系(详解)——依赖、关联、聚合、组合、泛化

概述 在学习面向对象设计时&#xff0c;类关系涉及依赖、关联、聚合、组合和泛化&#xff08;继承&#xff09;这五种关系&#xff0c;耦合度依次递增。关于耦合度&#xff0c;可以简单地理解为当一个类发生变更时&#xff0c;对其他类造成的影响程度&#xff0c;影响越小则耦…

电子发票打印工具 v2023.02.27 免费的PDF发票打印软件

电子发票打印工具一款PDF发票打印辅助软件,因为单位有很多电子发票需要打印,每次打印都要用reader阅读器打开,选打印,选份数,选纸张,选纸盒,当然,有些发票有清单页的,以上步骤请再重复一遍。多张发票请重复N遍,忍了多年,终于决心开发一款方便用于打印PDF发票的辅助工…

源码numpy笔记

参考文章 numpy学习 numpy中的浅复制和深复制的详细用法 numpy中的np.where torch.gather() Numpy的核心数据结构&#xff0c;就叫做array就是数组&#xff0c;array对象可以是一维数组&#xff0c;也可以是多维数组 array本身的属性 shape&#xff1a;返回一个元组&#xf…

【数据库增删查改进阶版】保姆级教程带大家去学习更加复杂的sql语句,各种各样的约束以及各种各样的查询

前言&#xff1a; 大家好&#xff0c;我是良辰丫&#x1f345;&#x1f345;&#x1f345;&#xff0c;上一篇数据库我们一起学习了基础版本的增删查改&#xff0c;今天我们将接触更高级的增删查改&#xff0c;主要是学习一些约束条件&#xff0c;你们准备好了嘛&#xff1f;开…

华为OD机试题,用 Java 解【流水线】问题

最近更新的博客 华为OD机试题,用 Java 解【停车场车辆统计】问题华为OD机试题,用 Java 解【字符串变换最小字符串】问题华为OD机试题,用 Java 解【计算最大乘积】问题华为OD机试题,用 Java 解【DNA 序列】问题华为OD机试 - 组成最大数(Java) | 机试题算法思路 【2023】使…

LearnOpenGL-入门-8.坐标系统

本人刚学OpenGL不久且自学&#xff0c;文中定有代码、术语等错误&#xff0c;欢迎指正 我写的项目地址&#xff1a;https://github.com/liujianjie/LearnOpenGLProject LearnOpenGL中文官网&#xff1a;https://learnopengl-cn.github.io/ 文章目录坐标系统概述局部空间世界空…

干货收藏|医疗数据安全、临床业务容灾、智能运维及数字化转型方案集锦

数智赋能&#xff0c;助力医院高质量发展&#xff01;历时三天的2022中华医院信息网络大会&#xff08;CHINC&#xff09;圆满落下帷幕&#xff0c;美创科技赴五年之约&#xff0c;与医疗行业用户朋友在深圳再聚交流&#xff0c;也带来关于“医疗行业数据安全、数字化转型”的新…

【再临数据结构】Day1. 稀疏数组

前言 这不单单是稀疏数组的开始&#xff0c;也是我重学数据结构的开始。因此&#xff0c;在开始说稀疏数组的具体内容之前&#xff0c;我想先说一下作为一个有着十余年“学龄”的学生&#xff0c;所一直沿用的一个学习方法&#xff1a;3W法。我认为&#xff0c;只有掌握了正确的…

react的严格模式 和 解决react useEffect执行两次

useEffect执行两次 这个问题&#xff0c;主要是刚接触react的时候发的问题&#xff0c;当时也没总结。现在回过头来再总结一次&#xff01;&#xff01;&#xff01; 文章目录useEffect执行两次前言一、为什么useEffect执行两次1.React的严格模式&#xff08;模版创建项目&…

Hadoop综合案例 - 聊天软件数据

目录1、聊天软件数据分析案例需求2、基于Hive数仓实现需求开发2.1 建库2.2 建表2.3 加载数据2.4 ETL数据清洗2.5 需求指标统计---都很简单3、FineBI实现可视化报表3.1 FineBI介绍3.2 FineBI配置数据3.3 构建可视化报表1、聊天软件数据分析案例需求 MR速度慢—引入hive 背景&a…

深度剖析指针(中)——“C”

各位CSDN的uu们你们好呀&#xff0c;今天小雅兰的内容仍旧是深度剖析指针噢&#xff0c;在上一篇博客中&#xff0c;我已经写过了字符指针、数组指针、指针数组、数组传参和指针传参的知识点&#xff0c;那么这篇博客小雅兰会讲解一下函数指针、函数指针数组 、指向函数指针数组…

【Spark分布式内存计算框架——Spark Streaming】8. Direct 方式集成底层原理 集成Kafka 0.10.x

Direct 方式集成底层原理 SparkStreaming集成Kafka采用Direct方式消费数据&#xff0c;如下三个方面优势&#xff1a; 第一、简单的并行度&#xff08;Simplified Parallelism&#xff09; 读取topics的总的分区数目 每批次RDD中分区数目&#xff1b;topic中每个分区数据 被…