1.3.3 • Published 6 years ago

himmas-vue-calendar v1.3.3

Weekly downloads
11
License
MIT
Repository
github
Last release
6 years ago

calendar

Chinese

This is a calendar component based on vue.js . support custom content. No dependencies. Currently, It only supports month view. You can click the control button to change the month.

Simple Live Demo

npm.io

Install

npm

$ npm install himmas-vue-calendar

script

<script src='dist/vue-calendar.js'>

Usage

Global Registration

//main.js
import Vue from 'vue'
import App from './App.vue'
//...

import Calendar from 'himmas-vue-calendar'
Vue.use(Calendar)

//...

new Vue({
  el: '#app',
  render: h => h(App)
})
<!--app.vue-->
<template>
  <div id="app">
    <!-- 'kl-' prefix -->
    <kl-calendar height="800px" width="800px"/>
  </div>
</template>

<script>

  export default {
    name: 'App'
  }
</script>

Local Registration

<!--app.vue-->
<template>
  <div id="app">
    <calendar height="800px" width="800px"/>
  </div>
</template>

<script>
  import Calendar from 'himmas-vue-calendar'
  export default {
    name: 'App',
    components:{Calendar}
  }
</script>

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
widthCalendar's widthString-100%
heightCalendar's heightString-100%
borderwhether Calendar has vertical borderBooleantrue/falsetrue
default-datedefault render dateDate,Stringanything accepted by new Date()new Date()
show-lunarwhether lunar info is visible.if render-content has been defined, this attribute does not work)Booleantrue/falsetrue
show-festivalwhether festival is visible.if render-content has been defined, this attribute does not workBooleantrue/falsetrue
show-termwhether solar terms is visible.if render-content has been defined, this attribute does not workBooleantrue/falsetrue
week-countthe number of weeksNumber-6
week-title-alignthe alignment of head informationStringleft/right/centerright
week-titlehead contentArray-'周日', '周一', '周二', '周三', '周四', '周五', '周六'
render-contentrender function for date, support jsxFunction(h,date)-
show-titlewhether title bar is visibleBooleantrue/falsetrue
show-control-btnwhether right control btn group is visible.if render-title has been defined, this attribute does not workBooleantrue/falsetrue
render-titlerender function for title bar, support jsxFunction(h,year,month)-
before-rendercallback before renderingFunction(year,month,next)-

Events

EventDescriptionparams
year-changeThis event will be fired when the currently rendered year changesyear,month
month-changeThis event will be fired when the currently rendered month changesyear,month
date-clickThis event will be fired when you click a datedate

Methods

MethodDescriptionparams
renderThisMonthrender a monthyear, month
getRenderedMonthget the currently rendered month information

date

render-content second param date

KeyDescription
dateDate Object
yearyear
monththe month of the year
daythe day of the month
weekDaythe day of the week(0-6)
lunarlunar info
festivalfestival
termsolar term
isTodayisToday
isWeekendisWeekend
isOtherMonthDaywhether it belongs to the current rendering month
renderYearthe current rendering year
renderMonththe current month is rendered
isDefaultDateisDefaultDate

example

  • default
  • custom example

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Title</title>
    </head>
    <style>
      .date-box {
        position: absolute;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
      }
      .first-info{
        flex: 1;
        display: flex;
        align-items: flex-end;
        justify-content: center;
        font-size: 18px;
        font-weight: bold;
      }
      .second-info{
        flex: 1;
        display: flex;
        justify-content: center;
        color: #999;
        font-size: 12px;
      }
      .second-info.festival{
        color: #f43;
      }
      .sign{
        display: none;
        position: absolute;
        top: 0;
        left: 0;
        background: #f43;
        width: 20px;
        height: 20px;
        color: #fff;
        line-height: 20px;
        text-align: center;
      }
      .date-box.today{
        background: #fb0;
        color: #fff;
      }
      .date-box.today .second-info{
        color: #fff;
      }
      .weekend{
        background: #f6f8fa;
      }
      .holiday .sign{
        display: block;
      }
      .date-box.other-month .second-info,.date-box.other-month .first-info{
        color: #999;
      }
      .date-box:hover{
        border: 3px solid #fb0;
      }
      .title-box{
        font-size: 20px;
      }
    </style>
    <body>
    <script src="./lib/vue.min.js"></script>
    <script src="../dist/vue-calendar.js"></script>
    <div id="app">
      <kl-calendar width="600px" height="500px"
                   :render-content="renderContent"
                   :week-title="weekTitle"
                   :border="false"
                   :before-render="beforeRender"
                   @year-change="changeHandle"
                   @month-change="changeHandle"
                   :render-title="renderTitle"
    
      />
    </div>
    <script>
    
      Vue.use(Calendar)
    
      new Vue({
        el: '#app',
        data() {
          return {
            weekTitle: ['日', '一', '二', '三', '四', '五', '六'],
            holiday: [
              '2018-01-01',
              '2018-02-15',
              '2018-02-16',
              '2018-02-17',
              '2018-02-18',
              '2018-02-19',
              '2018-02-20',
              '2018-02-21',
            ]
          }
        },
        methods: {
          twoDigit:function(num){ return ('000'+num).slice(-2) },
          renderTitle(h,year,month){
            return h('div', {
              class: {
                'title-box': true
              }
            },[
              h('span',{},year+'年'),
              h('span',{},month+'月')
            ])
          },
          renderContent(h, data) {
            var {isToday,isWeekend,isOtherMonthDay, year, day, month, renderYear, renderMonth, lunar, weekDay, festival, term} = data
    
            // lunar对象中存有农历数据
            var {lunarDayChiness} = lunar
    
            //第二行展示的数据的优先级为 节日>节气>农历日
            var secondInfo = festival ?
              festival : (term ? term : (lunarDayChiness || ''))
    
            var dateStr = `${year}-${this.twoDigit(month)}-${this.twoDigit(day)}`
    
            var isHoliday = (!!~this.holiday.indexOf(dateStr)) || isWeekend
    
            return h('div', {
              class: {
                'date-box': true,
                'today':isToday,
                'weekend':isWeekend,
                'holiday':isHoliday,
                'other-month':isOtherMonthDay
              }
            }, [h('div',{
              class: {
                'first-info': true
              }
            },day),h('div',{
              class: {
                'second-info': true,
                'festival':festival
              }
            },secondInfo),h('div',{
              class: {
                'sign': true
              }
            },'休')])
          },
          beforeRender(year,month,next){
            console.log('before-render',year,month)
            next()
          },
          changeHandle(year,month){
            console.log('change',year,month)
          }
        }
      })
    </script>
    </body>
    </html>

tips

  • IE9- not support
  • based on vue.js v2.1.5+

Build Setup

# install dependencies
npm install

# serve with hot reload at localhost:8080
npm run dev

# build for production with minification
npm run build
1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago