基本信息
源码名称:vue日历插件源码
源码大小:21.09M
文件格式:.zip
开发语言:js
更新时间:2020-01-07
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<template> <div class="cal-wrapper"> <div class="cal-header"> <div class="l" @click="preMonth"> <div class="arrow-left icon"> </div> </div> <div class="title">{{curYearMonth}}</div> <div class="r" @click="nextMonth"> <div class="arrow-right icon"> </div> </div> </div> <div class="cal-body"> <div class="weeks"> <span v-for="(dayName, dayIndex) in i18n[calendar.options.locale].dayNames" class="item" :key="dayIndex" >{{i18n[calendar.options.locale].dayNames[(dayIndex calendar.options.weekStartOn) % 7]}}</span> </div> <div class="dates"> <div v-for="date in dayList" class="item" :class="[{ today: date.status ? (today == date.date) : false, event: date.status ? (date.title != undefined) : false, [calendar.options.className] : (date.date == selectedDay) }, ...date.customClass]" :key="date.date" > <template v-if="isSunday(date)"> <p class="date-num" @click="handleChangeCurday(date)" :style="{color: date.title != undefined ? ((date.date == selectedDay) ? '#fff' : customColor) : 'inherit'}" >{{date.status ? date.date.split('/')[2] : ' '}}</p> <i class="is-sunday"></i> </template> <template v-else> <p class="date-num" @click="handleChangeCurday(date)" :style="{color: date.title != undefined ? ((date.date == selectedDay) ? '#fff' : customColor) : 'inherit'}" >{{date.status ? date.date.split('/')[2] : ' '}}</p> </template> <span v-if="date.status ? (today == date.date) : false" class="is-today" :style="{backgroundColor: customColor }" ></span> <span v-if="date.status ? (date.title != undefined) : false" class="is-event" :style="{borderColor: customColor, backgroundColor: (date.date == selectedDay) ? customColor : 'inherit'}" ></span> </div> </div> </div> </div> </template> <script> import i18n from '../i18n.js' import { dateTimeFormatter, isEqualDateStr } from '../tools.js' // 引入时间格式化插件 import moment from 'moment'; const inBrowser = typeof window !== 'undefined' export default { name: 'cal-panel', data() { return { i18n } }, props: { events: { type: Array, required: true }, calendar: { type: Object, required: true }, selectedDay: { type: String, required: false } }, computed: { dayList() { let firstDay = new Date( this.calendar.params.curYear, this.calendar.params.curMonth, 1 ) let dayOfWeek = firstDay.getDay() // 根据当前日期计算偏移量 // Calculate the offset based on the current date if (this.calendar.options.weekStartOn > dayOfWeek) { dayOfWeek = dayOfWeek - this.calendar.options.weekStartOn 7 } else { dayOfWeek = dayOfWeek - this.calendar.options.weekStartOn } let startDate = new Date(firstDay) startDate.setDate(firstDay.getDate() - dayOfWeek) let item, status, tempArr = [], tempItem for (let i = 0; i < 42; i ) { item = new Date(startDate) item.setDate(startDate.getDate() i) if (this.calendar.params.curMonth === item.getMonth()) { status = 1 } else { status = 0 } tempItem = { date: `${item.getFullYear()}/${item.getMonth() 1}/${item.getDate()}`, status: status, customClass: [] } this.events.forEach(event => { if (isEqualDateStr(event.date, tempItem.date)) { tempItem.title = event.title tempItem.desc = event.desc || '' if (event.customClass) tempItem.customClass.push(event.customClass) } }) tempArr.push(tempItem) } return tempArr }, today() { let dateObj = new Date() return `${dateObj.getFullYear()}/${dateObj.getMonth() 1}/${dateObj.getDate()}` }, curYearMonth() { let tempDate = Date.parse( new Date( `${this.calendar.params.curYear}/${this.calendar.params.curMonth 1}/01` ) ) return dateTimeFormatter( tempDate, this.i18n[this.calendar.options.locale].format ) }, customColor() { return this.calendar.options.color } }, methods: { isSunday(val) { let day = val.date; if(moment(day).weekday() === 0){ if(val.status === 1){ return true } } else { return false } }, nextMonth() { this.$EventCalendar.nextMonth() this.$emit('month-changed', this.curYearMonth) }, preMonth() { this.$EventCalendar.preMonth() this.$emit('month-changed', this.curYearMonth) }, handleChangeCurday(date) { if (date.status) { this.$emit('cur-day-changed', date.date) } } } } </script>