diff --git a/webapp/package-lock.json b/webapp/package-lock.json index 664d488..430fc77 100644 --- a/webapp/package-lock.json +++ b/webapp/package-lock.json @@ -14,6 +14,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "lucide-vue-next": "^0.562.0", + "lunar-javascript": "^1.7.7", "reka-ui": "^2.7.0", "tailwind-merge": "^3.4.0", "tailwindcss": "^4.1.18", @@ -2022,6 +2023,12 @@ "vue": ">=3.0.1" } }, + "node_modules/lunar-javascript": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/lunar-javascript/-/lunar-javascript-1.7.7.tgz", + "integrity": "sha512-u/KYiwPIBo/0bT+WWfU7qO1d+aqeB90Tuy4ErXenr2Gam0QcWeezUvtiOIyXR7HbVnW2I1DKfU0NBvzMZhbVQw==", + "license": "MIT" + }, "node_modules/magic-string": { "version": "0.30.21", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", diff --git a/webapp/package.json b/webapp/package.json index d5c0c3d..48cc65f 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -18,6 +18,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "lucide-vue-next": "^0.562.0", + "lunar-javascript": "^1.7.7", "reka-ui": "^2.7.0", "tailwind-merge": "^3.4.0", "tailwindcss": "^4.1.18", diff --git a/webapp/src/components/ui/calendar/Calendar.vue b/webapp/src/components/ui/calendar/Calendar.vue new file mode 100644 index 0000000..a5c7279 --- /dev/null +++ b/webapp/src/components/ui/calendar/Calendar.vue @@ -0,0 +1,593 @@ + + + diff --git a/webapp/src/lib/holiday-service.ts b/webapp/src/lib/holiday-service.ts new file mode 100644 index 0000000..b97c430 --- /dev/null +++ b/webapp/src/lib/holiday-service.ts @@ -0,0 +1,65 @@ +// 假期API类型定义 +export interface HolidayDay { + /** 节日名称 */ + name: string; + /** 日期, ISO 8601 格式 */ + date: string; + /** 是否为休息日 */ + isOffDay: boolean; +} + +export interface Holidays { + /** 完整年份, 整数。*/ + year: number; + /** 所用国务院文件网址列表 */ + papers: string[]; + days: HolidayDay[]; +} + +// 假期数据缓存 +const holidayCache = new Map(); + +/** + * 获取指定年份的假期数据 + */ +export async function getHolidaysByYear(year: number): Promise { + // 检查缓存 + if (holidayCache.has(year)) { + return holidayCache.get(year)!; + } + + try { + const response = await fetch(`https://api.coding.icu/cnholiday/${year}.json`); + + if (!response.ok) { + console.warn(`获取${year}年假期数据失败: ${response.status}`); + return null; + } + + const data: Holidays = await response.json(); + + // 缓存数据 + holidayCache.set(year, data); + + return data; + } catch (error) { + console.error(`获取${year}年假期数据出错:`, error); + return null; + } +} + +/** + * 获取指定日期的假期信息 + */ +export function getHolidayByDate(holidays: Holidays | null, dateStr: string): HolidayDay | null { + if (!holidays) return null; + + return holidays.days.find(day => day.date === dateStr) || null; +} + +/** + * 清除假期缓存 + */ +export function clearHolidayCache() { + holidayCache.clear(); +} diff --git a/webapp/src/router/index.ts b/webapp/src/router/index.ts index 72782b8..5ff2727 100644 --- a/webapp/src/router/index.ts +++ b/webapp/src/router/index.ts @@ -17,11 +17,20 @@ const router = createRouter({ } }, { - path: '/image/:date', + path: '/image/:date?', name: 'ImageView', component: ImageView, meta: { title: '图片详情' + }, + beforeEnter: (to, _from, next) => { + // 如果没有提供日期参数,重定向到今天的日期 + if (!to.params.date) { + const today = new Date().toISOString().split('T')[0] + next({ path: `/image/${today}`, replace: true }) + } else { + next() + } } }, { diff --git a/webapp/src/types/lunar-javascript.d.ts b/webapp/src/types/lunar-javascript.d.ts new file mode 100644 index 0000000..439564c --- /dev/null +++ b/webapp/src/types/lunar-javascript.d.ts @@ -0,0 +1,20 @@ +declare module 'lunar-javascript' { + export class Solar { + static fromDate(date: Date): Solar + getLunar(): Lunar + getFestivals(): string[] + } + + export class Lunar { + getYearInChinese(): string + getMonthInChinese(): string + getDayInChinese(): string + getDay(): number + getJieQi(): string + getFestivals(): string[] + } + + export class HolidayUtil { + // Add methods if needed + } +} diff --git a/webapp/src/views/ImageView.vue b/webapp/src/views/ImageView.vue index 4419ed8..9214fee 100644 --- a/webapp/src/views/ImageView.vue +++ b/webapp/src/views/ImageView.vue @@ -17,7 +17,11 @@ -
+
- - + +
+ + + + + +
+ + +
@@ -141,16 +170,32 @@