|
@@ -1,6 +1,6 @@
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
-import { ref, computed } from 'vue'
|
|
|
|
-import { getLunarDate, getDayDetail, isInLieu, getSolarTermsInRange } from 'chinese-days'
|
|
|
|
|
|
+import { computed, ref } from 'vue'
|
|
|
|
+import { getDayDetail, getLunarDate, getSolarTermsInRange, isInLieu } from 'chinese-days'
|
|
|
|
|
|
const props = withDefaults(
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
defineProps<{
|
|
@@ -9,17 +9,17 @@ const props = withDefaults(
|
|
}>(),
|
|
}>(),
|
|
{
|
|
{
|
|
lang: 'en',
|
|
lang: 'en',
|
|
- startOfWeek: 1
|
|
|
|
- }
|
|
|
|
|
|
+ startOfWeek: 1,
|
|
|
|
+ },
|
|
)
|
|
)
|
|
|
|
|
|
const currentDate = ref(new Date())
|
|
const currentDate = ref(new Date())
|
|
const currentMonth = ref(currentDate.value.getMonth())
|
|
const currentMonth = ref(currentDate.value.getMonth())
|
|
const currentYear = ref(currentDate.value.getFullYear())
|
|
const currentYear = ref(currentDate.value.getFullYear())
|
|
const daysOfWeek = computed(() =>
|
|
const daysOfWeek = computed(() =>
|
|
- props.lang == 'zh'
|
|
|
|
|
|
+ props.lang === 'zh'
|
|
? ['日', '一', '二', '三', '四', '五', '六']
|
|
? ['日', '一', '二', '三', '四', '五', '六']
|
|
- : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
|
|
|
|
+ : ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
|
)
|
|
)
|
|
const monthNames = [
|
|
const monthNames = [
|
|
'January',
|
|
'January',
|
|
@@ -33,7 +33,7 @@ const monthNames = [
|
|
'September',
|
|
'September',
|
|
'October',
|
|
'October',
|
|
'November',
|
|
'November',
|
|
- 'December'
|
|
|
|
|
|
+ 'December',
|
|
]
|
|
]
|
|
|
|
|
|
const daysInMonth = computed(() => {
|
|
const daysInMonth = computed(() => {
|
|
@@ -67,62 +67,64 @@ const daysInMonth = computed(() => {
|
|
return days
|
|
return days
|
|
})
|
|
})
|
|
|
|
|
|
-const prevMonth = () => {
|
|
|
|
|
|
+function prevMonth() {
|
|
if (currentMonth.value === 0) {
|
|
if (currentMonth.value === 0) {
|
|
currentMonth.value = 11
|
|
currentMonth.value = 11
|
|
currentYear.value--
|
|
currentYear.value--
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
currentMonth.value--
|
|
currentMonth.value--
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const nextMonth = () => {
|
|
|
|
|
|
+function nextMonth() {
|
|
if (currentMonth.value === 11) {
|
|
if (currentMonth.value === 11) {
|
|
currentMonth.value = 0
|
|
currentMonth.value = 0
|
|
currentYear.value++
|
|
currentYear.value++
|
|
- } else {
|
|
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
currentMonth.value++
|
|
currentMonth.value++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const isToday = (date: Date) => {
|
|
|
|
|
|
+function isToday(date: Date) {
|
|
const today = new Date()
|
|
const today = new Date()
|
|
return (
|
|
return (
|
|
- date.getDate() === today.getDate() &&
|
|
|
|
- date.getMonth() === today.getMonth() &&
|
|
|
|
- date.getFullYear() === today.getFullYear()
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const isSelected = (date: Date) => {
|
|
|
|
- return (
|
|
|
|
- date.getDate() === selectedDate.value?.date.getDate() &&
|
|
|
|
- date.getMonth() === selectedDate.value?.date.getMonth() &&
|
|
|
|
- date.getFullYear() === selectedDate.value?.date.getFullYear()
|
|
|
|
|
|
+ date.getDate() === today.getDate()
|
|
|
|
+ && date.getMonth() === today.getMonth()
|
|
|
|
+ && date.getFullYear() === today.getFullYear()
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
-const getDayInfo = (date: Date) => {
|
|
|
|
|
|
+function getDayInfo(date: Date) {
|
|
const dayDetail = getDayDetail(date)
|
|
const dayDetail = getDayDetail(date)
|
|
const holidayName = dayDetail.name.split(',')[1]
|
|
const holidayName = dayDetail.name.split(',')[1]
|
|
return {
|
|
return {
|
|
- disable: currentMonth.value != date.getMonth(),
|
|
|
|
|
|
+ disable: currentMonth.value !== date.getMonth(),
|
|
isToday: isToday(date),
|
|
isToday: isToday(date),
|
|
isInLieu: isInLieu(date),
|
|
isInLieu: isInLieu(date),
|
|
solarTerm: getSolarTermsInRange(date)[0],
|
|
solarTerm: getSolarTermsInRange(date)[0],
|
|
...getLunarDate(date),
|
|
...getLunarDate(date),
|
|
...dayDetail,
|
|
...dayDetail,
|
|
holidayName,
|
|
holidayName,
|
|
- date
|
|
|
|
|
|
+ date,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const daysInfo = computed(() => daysInMonth.value.map((date: Date) => getDayInfo(date)))
|
|
|
|
-
|
|
|
|
const selectedDate = ref(getDayInfo(new Date()))
|
|
const selectedDate = ref(getDayInfo(new Date()))
|
|
-const selectDate = (date: any) => {
|
|
|
|
|
|
+function selectDate(date: any) {
|
|
selectedDate.value = date
|
|
selectedDate.value = date
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+function isSelected(date: Date) {
|
|
|
|
+ return (
|
|
|
|
+ date.getDate() === selectedDate.value?.date.getDate()
|
|
|
|
+ && date.getMonth() === selectedDate.value?.date.getMonth()
|
|
|
|
+ && date.getFullYear() === selectedDate.value?.date.getFullYear()
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const daysInfo = computed(() => daysInMonth.value.map((date: Date) => getDayInfo(date)))
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
@@ -139,18 +141,26 @@ const selectDate = (date: any) => {
|
|
<path
|
|
<path
|
|
d="M684.29 799.276L393.929 513.019 684.29 226.762c37.685-37.153 38.003-97.625 0.707-134.384-37.297-36.758-98.646-36.435-136.331 0.718l-357.43 352.378c-0.155 0.153-0.297 0.314-0.451 0.468-0.084 0.082-0.172 0.157-0.256 0.239-18.357 18.092-27.581 41.929-27.743 65.902-0.004 0.311-0.017 0.623-0.018 0.934 0.001 0.316 0.014 0.632 0.018 0.948 0.165 23.97 9.389 47.803 27.743 65.892 0.083 0.082 0.171 0.157 0.255 0.239 0.154 0.154 0.296 0.315 0.452 0.468l357.43 352.378c37.685 37.153 99.034 37.476 136.331 0.718 37.297-36.758 36.979-97.231-0.707-134.384z"
|
|
d="M684.29 799.276L393.929 513.019 684.29 226.762c37.685-37.153 38.003-97.625 0.707-134.384-37.297-36.758-98.646-36.435-136.331 0.718l-357.43 352.378c-0.155 0.153-0.297 0.314-0.451 0.468-0.084 0.082-0.172 0.157-0.256 0.239-18.357 18.092-27.581 41.929-27.743 65.902-0.004 0.311-0.017 0.623-0.018 0.934 0.001 0.316 0.014 0.632 0.018 0.948 0.165 23.97 9.389 47.803 27.743 65.892 0.083 0.082 0.171 0.157 0.255 0.239 0.154 0.154 0.296 0.315 0.452 0.468l357.43 352.378c37.685 37.153 99.034 37.476 136.331 0.718 37.297-36.758 36.979-97.231-0.707-134.384z"
|
|
fill="currentColor"
|
|
fill="currentColor"
|
|
- ></path>
|
|
|
|
|
|
+ />
|
|
</svg>
|
|
</svg>
|
|
</button>
|
|
</button>
|
|
- <h2 v-if="lang == 'zh'">
|
|
|
|
|
|
+ <h2 v-if="lang === 'zh'">
|
|
<select v-model="currentYear">
|
|
<select v-model="currentYear">
|
|
- <option v-for="(y, index) in 201" :key="index" :value="1900 + index">{{ 1900 + index }}</option>
|
|
|
|
- </select> 年
|
|
|
|
|
|
+ <option v-for="(y, index) in 201" :key="index" :value="1900 + index">
|
|
|
|
+ {{ 1900 + index }}
|
|
|
|
+ </option>
|
|
|
|
+ </select>
|
|
|
|
+ 年
|
|
<select v-model="currentMonth">
|
|
<select v-model="currentMonth">
|
|
- <option v-for="(month, index) in 12" :key="index" :value="index">{{ month < 10 ? `0${month}` : month }}</option>
|
|
|
|
- </select> 月
|
|
|
|
|
|
+ <option v-for="(month, index) in 12" :key="index" :value="index">
|
|
|
|
+ {{ month < 10 ? `0${month}` : month }}
|
|
|
|
+ </option>
|
|
|
|
+ </select>
|
|
|
|
+ 月
|
|
|
|
+ </h2>
|
|
|
|
+ <h2 v-else>
|
|
|
|
+ {{ monthNames[currentMonth] }} {{ currentYear }}
|
|
</h2>
|
|
</h2>
|
|
- <h2 v-else>{{ monthNames[currentMonth] }} {{ currentYear }}</h2>
|
|
|
|
<button @click="nextMonth">
|
|
<button @click="nextMonth">
|
|
<svg
|
|
<svg
|
|
class="r"
|
|
class="r"
|
|
@@ -163,35 +173,37 @@ const selectDate = (date: any) => {
|
|
<path
|
|
<path
|
|
d="M684.29 799.276L393.929 513.019 684.29 226.762c37.685-37.153 38.003-97.625 0.707-134.384-37.297-36.758-98.646-36.435-136.331 0.718l-357.43 352.378c-0.155 0.153-0.297 0.314-0.451 0.468-0.084 0.082-0.172 0.157-0.256 0.239-18.357 18.092-27.581 41.929-27.743 65.902-0.004 0.311-0.017 0.623-0.018 0.934 0.001 0.316 0.014 0.632 0.018 0.948 0.165 23.97 9.389 47.803 27.743 65.892 0.083 0.082 0.171 0.157 0.255 0.239 0.154 0.154 0.296 0.315 0.452 0.468l357.43 352.378c37.685 37.153 99.034 37.476 136.331 0.718 37.297-36.758 36.979-97.231-0.707-134.384z"
|
|
d="M684.29 799.276L393.929 513.019 684.29 226.762c37.685-37.153 38.003-97.625 0.707-134.384-37.297-36.758-98.646-36.435-136.331 0.718l-357.43 352.378c-0.155 0.153-0.297 0.314-0.451 0.468-0.084 0.082-0.172 0.157-0.256 0.239-18.357 18.092-27.581 41.929-27.743 65.902-0.004 0.311-0.017 0.623-0.018 0.934 0.001 0.316 0.014 0.632 0.018 0.948 0.165 23.97 9.389 47.803 27.743 65.892 0.083 0.082 0.171 0.157 0.255 0.239 0.154 0.154 0.296 0.315 0.452 0.468l357.43 352.378c37.685 37.153 99.034 37.476 136.331 0.718 37.297-36.758 36.979-97.231-0.707-134.384z"
|
|
fill="currentColor"
|
|
fill="currentColor"
|
|
- ></path>
|
|
|
|
|
|
+ />
|
|
</svg>
|
|
</svg>
|
|
</button>
|
|
</button>
|
|
</header>
|
|
</header>
|
|
<div class="calendar-grid">
|
|
<div class="calendar-grid">
|
|
- <div class="calendar-day" v-for="(day, i) in 7" :key="day">
|
|
|
|
|
|
+ <div v-for="(day, i) in 7" :key="day" class="calendar-day">
|
|
{{ daysOfWeek[daysInfo[i].date.getDay()] }}
|
|
{{ daysOfWeek[daysInfo[i].date.getDay()] }}
|
|
</div>
|
|
</div>
|
|
<div
|
|
<div
|
|
- class="calendar-cell"
|
|
|
|
- @click="selectDate(day)"
|
|
|
|
v-for="(day, index) in daysInfo"
|
|
v-for="(day, index) in daysInfo"
|
|
:key="index"
|
|
:key="index"
|
|
|
|
+ class="calendar-cell"
|
|
:class="{
|
|
:class="{
|
|
today: day.isToday,
|
|
today: day.isToday,
|
|
disable: day.disable,
|
|
disable: day.disable,
|
|
holiday: day.holidayName,
|
|
holiday: day.holidayName,
|
|
inlieu: day.isInLieu,
|
|
inlieu: day.isInLieu,
|
|
work: day.holidayName && day.work,
|
|
work: day.holidayName && day.work,
|
|
- solar: day.solarTerm?.index == 1,
|
|
|
|
- selected: isSelected(day.date)
|
|
|
|
|
|
+ solar: day.solarTerm?.index === 1,
|
|
|
|
+ selected: isSelected(day.date),
|
|
}"
|
|
}"
|
|
|
|
+ @click="selectDate(day)"
|
|
>
|
|
>
|
|
- <span v-if="day.isToday" class="today-dot">{{ lang == 'en' ? 'Today' : '今' }}</span>
|
|
|
|
|
|
+ <span v-if="day.isToday" class="today-dot">{{ lang === 'en' ? 'Today' : '今' }}</span>
|
|
<span v-if="day.holidayName" class="holiday-dot">{{
|
|
<span v-if="day.holidayName" class="holiday-dot">{{
|
|
day.work ? '班' : day.isInLieu ? '调' : '休'
|
|
day.work ? '班' : day.isInLieu ? '调' : '休'
|
|
}}</span>
|
|
}}</span>
|
|
<span class="day">{{ day.date.getDate() }}</span>
|
|
<span class="day">{{ day.date.getDate() }}</span>
|
|
- <span class="desc">{{ day.solarTerm?.index == 1 ? day.solarTerm?.name : day.holidayName || day.lunarDayCN }}</span>
|
|
|
|
|
|
+ <span class="desc">{{
|
|
|
|
+ day.solarTerm?.index === 1 ? day.solarTerm?.name : day.holidayName || day.lunarDayCN
|
|
|
|
+ }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -203,14 +215,25 @@ const selectDate = (date: any) => {
|
|
{{ selectedDate.lunarMonCN }}{{ selectedDate.lunarDayCN }}
|
|
{{ selectedDate.lunarMonCN }}{{ selectedDate.lunarDayCN }}
|
|
</p>
|
|
</p>
|
|
<p>
|
|
<p>
|
|
- {{ selectedDate.yearCyl }}{{ selectedDate.zodiac }}年
|
|
|
|
- {{ selectedDate.monCyl }}月
|
|
|
|
|
|
+ {{ selectedDate.yearCyl }}{{ selectedDate.zodiac }}年 {{ selectedDate.monCyl }}月
|
|
{{ selectedDate.dayCyl }}日
|
|
{{ selectedDate.dayCyl }}日
|
|
</p>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="right">
|
|
<div class="right">
|
|
- <p>{{ selectedDate.isToday ? '今天是' : '此日是' }} <span>{{ selectedDate.solarTerm?.name }}</span> 节气的第 <span>{{selectedDate.solarTerm?.index}}</span> 天。</p>
|
|
|
|
- <p>{{ selectedDate.work ? '又是需要工作的一天!😥' : selectedDate.isInLieu ? '虽然调休,但要补班还回来的!🤬' : '休息啦~😃' }}</p>
|
|
|
|
|
|
+ <p>
|
|
|
|
+ {{ selectedDate.isToday ? '今天是' : '此日是' }}
|
|
|
|
+ <span>{{ selectedDate.solarTerm?.name }}</span> 节气的第
|
|
|
|
+ <span>{{ selectedDate.solarTerm?.index }}</span> 天。
|
|
|
|
+ </p>
|
|
|
|
+ <p>
|
|
|
|
+ {{
|
|
|
|
+ selectedDate.work
|
|
|
|
+ ? '又是需要工作的一天!😥'
|
|
|
|
+ : selectedDate.isInLieu
|
|
|
|
+ ? '虽然调休,但要补班还回来的!🤬'
|
|
|
|
+ : '休息啦~😃'
|
|
|
|
+ }}
|
|
|
|
+ </p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
@@ -250,7 +273,7 @@ body {
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
align-items: center;
|
|
margin-bottom: calc(20px + var(--calendar-padding));
|
|
margin-bottom: calc(20px + var(--calendar-padding));
|
|
-
|
|
|
|
|
|
+
|
|
button {
|
|
button {
|
|
display: flex;
|
|
display: flex;
|
|
flex-flow: column nowrap;
|
|
flex-flow: column nowrap;
|
|
@@ -465,7 +488,8 @@ body {
|
|
}
|
|
}
|
|
|
|
|
|
@media screen and (max-width: 560px) {
|
|
@media screen and (max-width: 560px) {
|
|
- .left, .right {
|
|
|
|
|
|
+ .left,
|
|
|
|
+ .right {
|
|
p {
|
|
p {
|
|
font-size: 12px;
|
|
font-size: 12px;
|
|
&:first-child {
|
|
&:first-child {
|