Coder Social home page Coder Social logo

hzy0913 / mpvue-calendar Goto Github PK

View Code? Open in Web Editor NEW
502.0 9.0 105.0 3.49 MB

📅 A calendar component for vue3.0. Support gesture sliding, range selection, according to the week switch...

Home Page: http://preview.binlive.cn/mpvue-calendar#/

License: MIT License

JavaScript 2.36% Vue 53.23% HTML 0.54% Less 7.90% TypeScript 35.98%
mpvue mpvue-calendar calendar vue chinese-lunar vue3 vue-calendar vue-component

mpvue-calendar's Introduction

mpvue-calendar logo

Downloads Version License

mpvue-calendar

A feature-rich calendar component, support multiple modes and gesture sliding. For vue 3.0+

mpvue-calendar preview

💻 Install

mpvue-calendar only support [email protected]+

npm i mpvue-calendar -S

🔨 Usage

<Calendar
  backgroundText
  class-name="select-mode"
  :remarks="remarks"
/>

import { ref } from 'vue'
import Calendar from 'mpvue-calendar'

export default {
  components: {
    Calendar,
  },
  setup() {
    const remarks = ref({'2021-1-13': 'some tings'})

    return {
      remarks,
    }
  }
}

⚙️ API

name type default description
selectMode String 'select' For the selection mode of calendar component, can be used by 'select', 'multi','range', 'multiRange' mode
mode String 'month' Configure calendar display mode, the modes has 'month', 'week','monthRange'
selectDate String / String[] / {start: String; end: String} / {start: String; end: String} [] In different selection modes, there are use different types. String type for select mode, String[] type for multi mode, {start: String; end: String} type for range mode, and {start: String; end: String} [] type for multiRange mode.
monthRange String[] If you use monthRange mode, you need to set the content of the month to be displayed. for example [2021-1, 2021-2, 2021-6, 2021-9]
remarks Object Create remark for a day, key is date string, and value is remark content. for example { '2021-1-13': 'some things' }
tileContent Object Create tile content for a day, key is date string, and value is object, object have className and content. for example { '2021-1-5': { className: 'tip-class', content: 'some tip' } }
holidays Object Custom holiday information, for example {'2021-1-1': 'New Year'}
completion Boolean false Complete the calendar table with 6 lines
useSwipe Boolean true The mobile terminal supports gesture sliding to switch calendar
arrowLeft String Left arrow image url of toolbar
arrowRight String Right arrow image url of toolbar
monFirst Boolean false The first day of the week begins on Monday
backgroundText Boolean false Displays the background text of the current month calendar
language String use 'en' or 'cn' language
format (year, month) => [String, String] Format the date display at the header. you need return a array, the contents of the array are year and month
weeks String[] Weekly display content of custom header, for example ['S', 'M', 'T', 'W', 'T', 'F', 'S']
begin String Set the available date of the start, and the date before it will be disabled, for example '2021-1-5'
end String Set the available date of the end, and the date after it will be disabled, for example '2021-2-5'
disabled String[] Disable certain dates , for example ['2021-1-9', '2021-2-5']

Chinese lunar

If you need show chinese lunar, you need import lunar module.

<Calendar
  :lunar="lunar"
/>

import lunar from 'mpvue-calendar/dist/lunar'
export default {
  ...,
  setup() {
    return {
      lunar,
    }
  }
}

⚙️ methods

name type description
onSelect (selectDate) => void This function is triggered when the date is selected
onMonthChange (year, month, day) => void The callback is triggered when the month is change
next (year, month) => void Callback this method when triggered next month
prev (year, month) => void Callback this method when triggered prev month
setToday ref method Back today, you need to pass the ref parameter to call the internal method

mpvue-calendar's People

Contributors

hzy0913 avatar naplec avatar natescarlet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpvue-calendar's Issues

初始化的时候只要有range跟multi就无法成功显示日历

screen shot 2018-08-28 at 9 04 00 pm

初始化的时候只要有range跟multi就无法成功显示日历,去掉这个2个选项就可以显示
<calendar
:months="months"
:value="value"
@next="next"
@Prev="prev"
:events="events"
lunar="true"
clean="true"
@select="select"
ref="calendar"
@selectMonth="selectMonth"
@selectYear="selectYear"
:arrowLeft="arrowLeft">

tileContent 属性设置有问题

我使用的是 chrom浏览器

return {
value: [],
isrange: false,
weekSwitch: false,
ismulti: false,
dataInfo: {},
monFirst: true,
clean: false, //简洁模式
lunar: true, //显示农历
events: {'2019-2-7':'今日备注', '2019-2-8':'一条很长的明日备注'},
tileContent: [],
renderValues: [],
disabledArray: ['2019-1-27','2019-2-25'],
almanacs: {'4-14': '学生日', '11-22': '感恩日'},
search:{
startDate:null,
endDate : null,
month : ''
},
}

methods: {
load(){
tool.service.workdayAndHoliday.queryWHEnterpriseSet(this.search).then((result)=>{
var dataList = result.dataList;
this.tileContent = []
for(let j = 0,len = dataList.length; j < len; j++){
if(dataList[j].status===2){
var _day = {className: 'xiu', content: '假'};
_day.date = this.formatDateMD(dataList[j].date);
this.tileContent.push(_day);
}else if(dataList[j].status===3){
var _day = { className: 'ban', content: '班'};
_day.date = this.formatDateMD(dataList[j].date);
this.tileContent.push(_day);
}
}
})
},

tileContent 赋值过之后 ,点击多个日期, 会显示多个日期被选中,样式类似日期muti样式

events的对象里有有多个同一天的event

image

events的对象里就像这样有两个同一天内但是不同的event,点击这一天只返回后面的那个event,如果可以的话当然希望能返回一个数组,不过也可以用'date': [ event1, event2]这样的方式绕过去

返回今日的时候有bug

返回今日之后,
default
应该是如下的效果
default
点击下个月5号,但是5号没有选中,而是显示整个下个月

select(val, val2)在range模式下有bug

小程序

select(val, val2)在range模式下有bug

range模式下如选择2018-11-21到2018-12-30, 返回[2018,10,21] [2018,11,30]

但非range模式下选择2018-11-21,返回[2018,11,21]

不能禁用

<Calendar
:months="months"
:value="value"
@next="next"
@Prev="prev"
:disabled="disabled"
:events="events"
@select="select"
ref="calendar"
@selectMonth="selectMonth"
@selectYear="selectYear"
v-if="tab.selectedId == '1'"
/>

好吧,又是我。这次是组件数据渲染的问题

正常:我在日历显示系统时间 2018年九月份的时候, 提交了 比如 十月份(反正不是当前显示的月份) 的某些天的日期给后台,提交成功后,切换到十月份的日历能够看到我刚提交的那些日期已经被我标注的class渲染了样式,返回格式:[{date: '2018-9-20', className: 'holiday'}])

异常:如果我修改提交的日期是页面显示的月份(比如我切换到十一月份,去提交当前显示的这个十一月的某些日期,),在提交成功后,当前日期的数据并没有被class渲染(dom没有更新),必须切到上个月或者下个月,再返回到十一月才能看到数据修改后的样式渲染

range模式下,手动赋值value后,日历没有选中

期望:给value赋值后,range模式下日历组件选中对应的区域范围,
结果:没有选中

 this.$set(this.$refs.calendar, "rangeBegin", [
              ...this.startTime.split("-").map(v => (v = +v))
            ]);
            this.$set(this.$refs.calendar, "rangeEnd", [
              ...this.endTime.split("-").map(v => (v = +v))
            ]);
            this.$set(this.$refs.calendar, "rangeBeginTemp", [2019, 4, 10]);
            this.$set(this.$refs.calendar, "rangeEndTemp", 1);
            this.$forceUpdate();

请教一下关于打包问题

Hi,想请教你一个问题~

我注意到你的组件并没有经过打包处理,而是直接输出vue文件。这样的话我在自己的项目中引入你的组件就相当于直接引入了一个vue文件。

现在我想封装一个mpvue组件,但是可能会在vue文件中写一些es6,所以想要经过打包处理一下vue文件。但是vue-loader会将我的vue文件转化为js文件,这样的话微信小程序中的mpvue就不认识了。

想请教一下您有没有遇到过类似问题呢?

切换到上个月不会触发 `selectMonth` 事件

this.render(this.year, this.month);
this.$emit('selectMonth', this.month + 1, this.year);
const weekIndex = weekSwitch ? this.weekIndex : undefined;
this.$emit('next', this.year, this.month + 1, weekIndex);

this.render(this.year, this.month);
(typeof changed === 'function') && changed();
const weekIndex = weekSwitch ? this.weekIndex : undefined;
this.$emit('prev', this.year, this.month + 1, weekIndex);

image

每次在未来月份选择的时候都会跳转到当前月

比如现在2018/8/24,我去十月份进行多选,只要一点击某个日期(只要是未来月份的日期),就会立即跳转到当前月份(只有回到十月份,把刚刚点击的日期再次点击取消,之后就能在十月份这哥日历上进行多选,而不会再次跳转到系统当前月了)

Cannot read property 'monFirst' of undefined

return this.monFirst ? ['', '', '', '', '', '', ''] : ['', '', '', '', '', '', ''];

weeks 只是用来做展示,可以使用 computed 来计算,默认执行,报错了

props: {
	monFirst: {
		type: Boolean,
		default: false
    },
},
computed: {
	weeks() {
		return this.monFirst ? ['一', '二', '三', '四', '五', '六', '日'] : ['日', '一', '二', '三', '四', '五', '六'];	
	}
}

总是出现 TypeError: Cannot read property '1' of undefined

VM963:1 TypeError: Cannot read property '1' of undefined
at VueComponent.init (mpvue-calendar.vue:225)
at VueComponent.boundFn [as init] (index.js:191)
at VueComponent.value (mpvue-calendar.vue:181)
at Watcher.run (index.js:2591)
at flushSchedulerQueue (index.js:2345)
at Array. (index.js:609)
at nextTickHandler (index.js:556)
at
这个错误都指向了 mpvue-calendar.vue:225 和 mpvue-calendar.vue:181
下午就要就要给老板看代码了= =,这个错误终止了当前页面其它样式(单选之类)的切换和日历上下月翻页的事件。

能兼容pc么?

需要在PC上展示 今年今月 --- 明年次月 (2018年9月 --- 2019年8月) 12个月的日历

关于disabled日期的问题

在使用手册里面看到:
disabled 参数 disabled为禁用日期,如禁用2018-6-21日为['2018-6-21']
但是例子程序是写成了: disabledArray 这里是不是有问题? 查了通篇的源代码没看到有引用disabledArray的地方。

export default {
  data () {
    return {
      ...
      disabledArray: ['2018-6-27','2018-6-25'],
      ...  
  },

还有就是即使写成 disabled后,对应的日子依然可以点击选择:

   return {
     ...
     disabled: ['2018-6-27','2018-6-25'],
     ...  
 },

谢谢解惑

是否可以不补全日期

在completion默认为false的时候,也不用上个月的日期来补全日历,不知道怎么实现呢

请问可否动态定义 “禁用日期”

请问目前支持在method里面通过点击的方式添加禁用日期吗?

data () {
            return {
                  disabledArray: ['2018-9-15']
            }
},
 methods   : {
            disableSelectedDate (date, month, year) {
                  this.disabledArray = ['2018-9-15', '2018-9-20'] 
            } 
...

这样添加没有变化,想请教一下目前的版本支持添加禁用日期吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.