feat: localize dashboard experiences
This commit is contained in:
1 parent
6727f72121
commit
ea51c16d29
10 files changed
+337
-93
No files matched your search
@@ -1,23 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRouter } from 'vue-router'
|
||||
import http from '../api/http'
|
||||
|
||||
interface CalendarEvent { id: string; title: string; startsOn: string; reminderDays: number }
|
||||
const router = useRouter()
|
||||
const { t } = useI18n()
|
||||
const events = ref<CalendarEvent[]>([])
|
||||
const today = new Date().toISOString().slice(0, 10)
|
||||
function daysUntil(item: CalendarEvent) { return Math.ceil((new Date(`${item.startsOn}T00:00:00`).getTime() - new Date(`${today}T00:00:00`).getTime()) / 86400000) }
|
||||
const reminders = computed(() => events.value.filter(item => { const days = daysUntil(item); return days >= 0 && days <= item.reminderDays }).slice(0, 3))
|
||||
function label(item: CalendarEvent) { const days = daysUntil(item); return days === 0 ? '今天' : `${days} 天后` }
|
||||
function label(item: CalendarEvent) {
|
||||
const days = daysUntil(item)
|
||||
return days === 0 ? t('dashboard.calendar.today') : t('dashboard.calendar.inDays', { days })
|
||||
}
|
||||
onMounted(async () => { try { events.value = (await http.get('/academic-calendar')).data } catch { /* Calendar reminders must not affect the dashboard. */ } })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section v-if="reminders.length" class="calendar-reminder">
|
||||
<div><span>日程提醒</span><strong>近期关键日程</strong></div>
|
||||
<div><span>{{ t('dashboard.calendar.label') }}</span><strong>{{ t('dashboard.calendar.title') }}</strong></div>
|
||||
<button v-for="item in reminders" :key="item.id" type="button" @click="router.push('/academic-calendar')"><b>{{ label(item) }}</b><span>{{ item.title }}</span></button>
|
||||
<button class="all" type="button" @click="router.push('/academic-calendar')">查看校历 →</button>
|
||||
<button class="all" type="button" @click="router.push('/academic-calendar')">{{ t('dashboard.calendar.viewAll') }} →</button>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in new issue
Block a user