Skip to content

Commit

Permalink
feat(calendar): goToToday
Browse files Browse the repository at this point in the history
  • Loading branch information
nemo-shen committed Jan 28, 2024
1 parent d25cf89 commit 6a89227
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
27 changes: 26 additions & 1 deletion packages/core/useCalendar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,31 @@ export const useCalendar = (options: UseCalendarOptions = {}) => {
currentMonth.value -= 1
}

// 将日历前进到下一个月。
const goToNextYear = () => {
if (currentYear.value === 285616) {
console.warn('It is already the biggest year.')
return
}
currentYear.value += 1
}

// 将日历后退到上一个月。
const goToPreviousYear = () => {
if (currentMonth.value === 1997) {
console.warn('It is already the smallest year.')
return
}
currentYear.value -= 1
}

// 将日历重置到今天的日期。
const goToToday = () => {}
const goToToday = () => {
// 需要重置年月
const now = new Date()
currentYear.value = now.getFullYear()
currentMonth.value = now.getMonth() + 1
}

//
/**
Expand Down Expand Up @@ -101,6 +124,8 @@ export const useCalendar = (options: UseCalendarOptions = {}) => {
selectDate,
goToNextMonth,
goToPreviousMonth,
goToNextYear,
goToPreviousYear,
goToToday,
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/demo/UseCalendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@
import { ref, h, VNode } from 'vue'
import { useCalendar } from '@noi/core'
const { currentMonthDays, goToNextMonth, goToPreviousMonth } = useCalendar()
const {
currentMonthDays,
goToToday,
goToNextMonth,
goToPreviousMonth,
goToNextYear,
goToPreviousYear,
} = useCalendar()
</script>

<template>
<button @click="goToPreviousMonth">prev month</button>
<button @click="goToNextMonth">next month</button>
<button @click="goToPreviousYear">goToPreviousYear</button>
<button @click="goToNextYear">goToNextYear</button>
<br />
<button @click="goToPreviousMonth">goToPreviousMonth</button>
<button @click="goToNextMonth">goToNextMonth</button>
<br />
<button @click="goToToday">goToToday</button>
需要生成一个当前日历需要知道哪些信息 1. 当前的月份有多少天 2.
每天是一个对象,应该会配有不同的内容 3. 周 4. 当前的年月 5.

Expand Down

0 comments on commit 6a89227

Please sign in to comment.