feat: localize academic calendar

This commit is contained in:
biss committed 2026-10-31 10:20:59 +08:00
1 parent bc8757c098
commit 64798e7fe6
3 files changed
+81 -91

No files matched your search

+9
View File
@@ -91,6 +91,15 @@ export default {
metric: { gpaHint: 'Weighted by course credits', weighted: 'Credit-weighted average', weightedHint: 'Final course scores weighted by credits', average: 'Average score', averageHint: 'Arithmetic mean of published final scores' },
trendTitle: 'Academic performance by term', trendHint: 'GPA uses the left axis (0–4); scores use the right axis (0–100).', trendEmpty: 'No published grades are available for a trend chart',
},
calendar: {
title: 'Academic calendar', description: 'Teaching dates, public holidays, and upcoming reminders share one calendar. These reminders do not change any business rules or deadlines.', add: 'Add event', currentTerm: 'Current term', today: 'Today', teachingSchedule: 'Teaching event', due: 'Due soon', info: 'Calendar reminders are informational. They are not tasks and do not restrict any workflow.', monthAgenda: 'This month', items: '{count} items', audience: 'Audience: {audience}', dueReminder: 'Due soon', edit: 'Edit', delete: 'Delete', empty: 'No events this month', allRoles: 'All roles', examTitle: 'Exam: {course}', cancel: 'Cancel', save: 'Save',
kinds: { course: 'Course selection', grade: 'Grades', evaluation: 'Evaluation', exam: 'Exam', graduation: 'Graduation audit', holiday: 'Public holiday', other: 'Other' },
roles: { SuperAdmin: 'Super administrator', AcademicAdmin: 'Academic administrator', CollegeAdmin: 'College administrator', Leader: 'Leader', Counselor: 'Counselor', Teacher: 'Teacher', Student: 'Student', MaintenanceAdmin: 'Maintenance administrator', MaintenanceStaff: 'Maintenance staff', PhysicalEducationAdmin: 'Physical education administrator', DormitoryAdmin: 'Dormitory administrator', StudentAffairsAdmin: 'Student affairs administrator' },
dialog: { edit: 'Edit calendar event', add: 'Add calendar event' },
form: { term: 'Term', name: 'Event name', type: 'Event type', range: 'Start / end', to: 'to', reminder: 'Advance reminder', reminderHint: 'days (controls due-soon highlighting only)', roles: 'Audience roles', rolesHint: 'Leave empty to show the event to all roles.', description: 'Description', enabled: 'Enabled' },
messages: { selectTerm: 'Select the term that will receive the holiday events.', syncConfirm: 'Sync public holidays for {year} and replace previously synced data for that year in this term?', synced: 'Synced {count} holiday or adjusted-workday events covering {days} days.', required: 'Enter a term, event name, and start date.', saved: 'Calendar event saved. It is used only for display and reminders.', deleteConfirm: 'Delete “{title}”?', deleteTitle: 'Delete event', deleted: 'Event deleted' },
sync: { title: 'Sync public holidays', action: 'Sync public holidays', confirm: 'Sync', intro: 'Read the selected year from the holiday data source and add it to the current term. Syncing the same year again replaces previously synced data.', preview: 'Preview data', previewHint: 'Select Preview to load holiday data', dayOff: 'Day off', workday: 'Adjusted workday', submit: 'Sync to current term' },
},
api: {
'data.constraint_conflict': 'A data constraint conflict occurred.',
'server.unhandled_error': 'The server encountered an error while processing the request.',
+9
View File
@@ -91,6 +91,15 @@ export default {
metric: { gpaHint: '绩点按课程学分加权', weighted: '加权平均成绩', weightedHint: '课程总评按课程学分加权', average: '平均成绩', averageHint: '已发布课程总评的算术平均' },
trendTitle: '各学期学业成绩变化', trendHint: 'GPA 使用左轴(0–4),两项成绩使用右轴(0–100)。', trendEmpty: '暂无可绘制趋势的已发布成绩',
},
calendar: {
title: '学期校历', description: '教学日程、法定节假日与临期提醒都落在同一张日历上;仅作提醒,不改变任何业务办理规则。', add: '新增日程', currentTerm: '当前学期', today: '今天', teachingSchedule: '教学日程', due: '临期', info: '这里是校历提醒,不表示您有待办,也不会限制任何业务操作。', monthAgenda: '本月安排', items: '{count} 项', audience: '面向:{audience}', dueReminder: '临期提醒', edit: '编辑', delete: '删除', empty: '本月暂无日程', allRoles: '全部角色', examTitle: '考试:{course}', cancel: '取消', save: '保存',
kinds: { course: '选课', grade: '成绩', evaluation: '评教', exam: '考试', graduation: '毕业审核', holiday: '法定节假日', other: '其他' },
roles: { SuperAdmin: '超级管理员', AcademicAdmin: '校级教务管理员', CollegeAdmin: '学院教务管理员', Leader: '领导', Counselor: '辅导员', Teacher: '教师', Student: '学生', MaintenanceAdmin: '维修管理员', MaintenanceStaff: '维修人员', PhysicalEducationAdmin: '体测管理员', DormitoryAdmin: '宿管管理员', StudentAffairsAdmin: '学工管理员' },
dialog: { edit: '编辑校历日程', add: '新增校历日程' },
form: { term: '所属学期', name: '日程名称', type: '日程类型', range: '开始 / 结束', to: '至', reminder: '提前提醒', reminderHint: '天(只控制页面临期提示)', roles: '面向角色', rolesHint: '不选则向所有角色显示。', description: '说明', enabled: '启用' },
messages: { selectTerm: '请先选择要写入节假日的学期。', syncConfirm: '将同步 {year} 年节假日,并替换该学期已同步的同年度数据。', synced: '已同步 {count} 个节假日/调休日程,覆盖 {days} 天。', required: '请填写学期、日程名称和开始日期。', saved: '校历日程已保存;它只用于展示和提醒。', deleteConfirm: '删除“{title}”吗?', deleteTitle: '删除日程', deleted: '日程已删除' },
sync: { title: '同步法定节假日', action: '同步法定节假日', confirm: '确认同步', intro: '从节假日数据源读取指定年份,写入当前选择的学期。再次同步同一年会替换此前同步的数据。', preview: '预览数据', previewHint: '点击预览以加载节假日数据', dayOff: '休息', workday: '调休上班', submit: '同步到当前学期' },
},
api: {
'data.constraint_conflict': '数据约束冲突。',
'server.unhandled_error': '服务器处理请求时发生错误。',
+63 -91
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from "vue";
import { computed, onMounted, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { ElMessage, ElMessageBox } from "element-plus";
import { ArrowLeft, ArrowRight, Plus } from "@element-plus/icons-vue";
import http from "../api/http";
@@ -37,6 +38,7 @@ const auth = useAuthStore(),
holidayYear = ref(new Date().getFullYear()),
editingId = ref<string>(),
cursor = ref(new Date(new Date().getFullYear(), new Date().getMonth(), 1));
const { locale, t } = useI18n();
const canManage = computed(
() =>
auth.user?.roles.some((role) =>
@@ -44,30 +46,11 @@ const canManage = computed(
) ?? false,
);
const isStudent = computed(() => auth.user?.roles.includes("Student") ?? false);
const roles = [
["SuperAdmin", "超级管理员"],
["AcademicAdmin", "校级教务管理员"],
["CollegeAdmin", "学院教务管理员"],
["Leader", "领导"],
["Counselor", "辅导员"],
["Teacher", "教师"],
["Student", "学生"],
["MaintenanceAdmin", "维修管理员"],
["MaintenanceStaff", "维修人员"],
["PhysicalEducationAdmin", "体测管理员"],
["DormitoryAdmin", "宿管管理员"],
["StudentAffairsAdmin", "学工管理员"],
];
const kinds = [
[1, "选课"],
[2, "成绩"],
[3, "评教"],
[4, "考试"],
[5, "毕业审核"],
[6, "法定节假日"],
[99, "其他"],
],
weekdays = ["一", "二", "三", "四", "五", "六", "日"];
const roleKeys = ["SuperAdmin", "AcademicAdmin", "CollegeAdmin", "Leader", "Counselor", "Teacher", "Student", "MaintenanceAdmin", "MaintenanceStaff", "PhysicalEducationAdmin", "DormitoryAdmin", "StudentAffairsAdmin"];
const roles = computed(() => roleKeys.map((role) => [role, t(`calendar.roles.${role}`)]));
const kindValues = [1, 2, 3, 4, 5, 6, 99];
const kinds = computed(() => kindValues.map((kind) => [kind, label(kind)]));
const weekdays = computed(() => Array.from({ length: 7 }, (_, index) => new Intl.DateTimeFormat(locale.value, { weekday: "short" }).format(new Date(2026, 10, 2 + index))));
const form = reactive<any>({
academicTermId: "",
title: "",
@@ -109,17 +92,7 @@ function kindKey(kind: number | string) {
);
}
function label(kind: number | string) {
return (
{
course: "选课",
grade: "成绩",
evaluation: "评教",
exam: "考试",
graduation: "毕业审核",
holiday: "法定节假日",
other: "其他",
} as Record<string, string>
)[kindKey(kind)];
return t(`calendar.kinds.${kindKey(kind)}`);
}
function spans(item: CalendarEvent, day: string) {
return item.startsOn <= day && (item.endsOn ?? item.startsOn) >= day;
@@ -132,9 +105,7 @@ interface WeekEventSegment {
lane: number;
}
const today = key(new Date()),
monthTitle = computed(
() => `${cursor.value.getFullYear()} 年 ${cursor.value.getMonth() + 1} 月`,
);
monthTitle = computed(() => new Intl.DateTimeFormat(locale.value, { year: "numeric", month: "long" }).format(cursor.value));
const days = computed(() => {
const first = new Date(
cursor.value.getFullYear(),
@@ -210,9 +181,9 @@ function due(item: CalendarEvent) {
function audience(item: CalendarEvent) {
return item.audienceRoles.length
? item.audienceRoles
.map((role) => roles.find((x) => x[0] === role)?.[1] ?? role)
.join("、")
: "全部角色";
.map((role) => roles.value.find((x) => x[0] === role)?.[1] ?? role)
.join(t("common.listSeparator"))
: t("calendar.allRoles");
}
async function load() {
loading.value = true;
@@ -232,7 +203,7 @@ async function load() {
const examEvents = (exams.data as any[]).map((exam) => ({
id: `exam-${exam.id}`,
academicTermId: selectedTermId.value,
title: `考试:${exam.courseName}`,
title: t("calendar.examTitle", { course: exam.courseName }),
kind: "Exam",
startsOn: exam.examDate,
reminderDays: 7,
@@ -263,11 +234,11 @@ async function openHolidaySync() {
}
async function syncHolidays() {
if (!selectedTermId.value)
return ElMessage.warning("请先选择要写入节假日的学期。");
return ElMessage.warning(t("calendar.messages.selectTerm"));
await ElMessageBox.confirm(
`将同步 ${holidayYear.value} 年节假日,并替换该学期已同步的同年度数据。`,
"同步法定节假日",
{ type: "warning", confirmButtonText: "确认同步" },
t("calendar.messages.syncConfirm", { year: holidayYear.value }),
t("calendar.sync.title"),
{ type: "warning", confirmButtonText: t("calendar.sync.confirm") },
);
holidayLoading.value = true;
try {
@@ -275,7 +246,7 @@ async function syncHolidays() {
academicTermId: selectedTermId.value,
year: holidayYear.value,
});
ElMessage.success(`已同步 ${data.syncedCount} 个节假日/调休日程,覆盖 ${data.sourceDayCount} 天。`);
ElMessage.success(t("calendar.messages.synced", { count: data.syncedCount, days: data.sourceDayCount }));
holidayDialogVisible.value = false;
await load();
} finally {
@@ -305,7 +276,7 @@ function open(item?: CalendarEvent) {
}
async function save() {
if (!form.academicTermId || !form.title.trim() || !form.startsOn)
return ElMessage.warning("请填写学期、日程名称和开始日期。");
return ElMessage.warning(t("calendar.messages.required"));
const body = {
...form,
title: form.title.trim(),
@@ -315,16 +286,16 @@ async function save() {
if (editingId.value)
await http.put(`/academic-calendar/${editingId.value}`, body);
else await http.post("/academic-calendar", body);
ElMessage.success("校历日程已保存;它只用于展示和提醒。");
ElMessage.success(t("calendar.messages.saved"));
dialogVisible.value = false;
await load();
}
async function remove(item: CalendarEvent) {
await ElMessageBox.confirm(`删除“${item.title}”吗?`, "删除日程", {
await ElMessageBox.confirm(t("calendar.messages.deleteConfirm", { title: item.title }), t("calendar.messages.deleteTitle"), {
type: "warning",
});
await http.delete(`/academic-calendar/${item.id}`);
ElMessage.success("日程已删除");
ElMessage.success(t("calendar.messages.deleted"));
await load();
}
onMounted(async () => {
@@ -332,21 +303,22 @@ onMounted(async () => {
selectedTermId.value = defaultAcademicTermId(terms.value) ?? "";
await load();
});
watch(locale, load);
</script>
<template>
<section class="calendar-page">
<header class="calendar-masthead">
<div>
<p>ACADEMIC ALMANAC</p>
<h1>学期校历</h1>
<h1>{{ t('calendar.title') }}</h1>
<span
>教学日程、法定节假日与临期提醒都落在同一张日历上;仅作提醒,不改变任何业务办理规则。</span
>{{ t('calendar.description') }}</span
>
</div>
<div v-if="canManage" class="calendar-masthead-actions">
<el-button @click="openHolidaySync">同步法定节假日</el-button>
<el-button @click="openHolidaySync">{{ t('calendar.sync.action') }}</el-button>
<el-button type="primary" :icon="Plus" @click="open()"
>新增日程</el-button
>{{ t('calendar.add') }}</el-button
>
</div>
</header>
@@ -354,7 +326,7 @@ onMounted(async () => {
<el-select
v-model="selectedTermId"
clearable
placeholder="当前学期"
:placeholder="t('calendar.currentTerm')"
@change="load"
><el-option
v-for="term in terms"
@@ -366,17 +338,17 @@ onMounted(async () => {
<el-button :icon="ArrowLeft" circle text @click="shift(-1)" /><strong>{{
monthTitle
}}</strong
><el-button text @click="goToday">今天</el-button
><el-button text @click="goToday">{{ t('calendar.today') }}</el-button
><el-button :icon="ArrowRight" circle text @click="shift(1)" />
</div>
<div class="calendar-legend">
<span class="holiday">法定节假日</span><span>教学日程</span
><span class="due">临期</span>
<span class="holiday">{{ t('calendar.kinds.holiday') }}</span><span>{{ t('calendar.teachingSchedule') }}</span
><span class="due">{{ t('calendar.due') }}</span>
</div>
</div>
<el-alert
v-if="!canManage"
title="这里是校历提醒,不表示您有待办,也不会限制任何业务操作。"
:title="t('calendar.info')"
type="info"
:closable="false"
show-icon
@@ -385,7 +357,7 @@ onMounted(async () => {
<div class="calendar-board">
<div class="weekdays">
<span v-for="weekday in weekdays" :key="weekday"
>周{{ weekday }}</span
>{{ weekday }}</span
>
</div>
<div class="calendar-grid">
@@ -415,14 +387,14 @@ onMounted(async () => {
:class="['calendar-event', kindKey(segment.item.kind), { due: due(segment.item) }]"
:title="segment.item.title"
@click="canManage && open(segment.item)"
><span>{{ segment.item.title.replace("(法定节假日)", "") }}</span></button>
><span>{{ segment.item.title.replace(/\s*[((].*[))]$/, "") }}</span></button>
</div>
</section>
</div>
</div>
<aside class="month-agenda">
<header>
<span>本月安排</span><strong>{{ monthEvents.length }} 项</strong>
<span>{{ t('calendar.monthAgenda') }}</span><strong>{{ t('calendar.items', { count: monthEvents.length }) }}</strong>
</header>
<div v-if="monthEvents.length" class="agenda-items">
<article
@@ -440,57 +412,57 @@ onMounted(async () => {
<b>{{ item.title }}</b>
<p>{{ item.description || label(item.kind) }}</p>
<small v-if="canManage"
>面向:{{ audience(item)
}}<template v-if="due(item)"> · 临期提醒</template></small
>{{ t('calendar.audience', { audience: audience(item) })
}}<template v-if="due(item)"> · {{ t('calendar.dueReminder') }}</template></small
>
</div>
<div v-if="canManage" class="agenda-actions">
<el-button text @click="open(item)">编辑</el-button
<el-button text @click="open(item)">{{ t('calendar.edit') }}</el-button
><el-button text type="danger" @click="remove(item)"
>删除</el-button
>{{ t('calendar.delete') }}</el-button
>
</div>
</article>
</div>
<el-empty v-else :image-size="60" description="本月暂无日程" />
<el-empty v-else :image-size="60" :description="t('calendar.empty')" />
</aside>
</div>
<el-dialog
v-model="dialogVisible"
:title="editingId ? '编辑校历日程' : '新增校历日程'"
:title="editingId ? t('calendar.dialog.edit') : t('calendar.dialog.add')"
width="620px"
destroy-on-close
><el-form label-width="98px"
><el-form-item label="所属学期" required
><el-form-item :label="t('calendar.form.term')" required
><el-select v-model="form.academicTermId"
><el-option
v-for="term in terms"
:key="term.id"
:label="academicTermLabel(term)"
:value="term.id" /></el-select></el-form-item
><el-form-item label="日程名称" required
><el-form-item :label="t('calendar.form.name')" required
><el-input v-model="form.title" maxlength="120" /></el-form-item
><el-form-item label="日程类型"
><el-form-item :label="t('calendar.form.type')"
><el-select v-model="form.kind"
><el-option
v-for="kind in kinds"
:key="kind[0]"
:label="kind[1]"
:value="kind[0]" /></el-select></el-form-item
><el-form-item label="开始 / 结束" required
><el-form-item :label="t('calendar.form.range')" required
><el-date-picker
v-model="form.startsOn"
type="date"
value-format="YYYY-MM-DD" /><span class="range-separator">至</span
value-format="YYYY-MM-DD" /><span class="range-separator">{{ t('calendar.form.to') }}</span
><el-date-picker
v-model="form.endsOn"
type="date"
value-format="YYYY-MM-DD"
clearable /></el-form-item
><el-form-item label="提前提醒"
><el-form-item :label="t('calendar.form.reminder')"
><el-input-number v-model="form.reminderDays" :min="0" :max="90" />
<span class="form-hint">天(只控制页面临期提示)</span></el-form-item
><el-form-item label="面向角色"
<span class="form-hint">{{ t('calendar.form.reminderHint') }}</span></el-form-item
><el-form-item :label="t('calendar.form.roles')"
><el-checkbox-group v-model="form.audienceRoles"
><el-checkbox
v-for="role in roles"
@@ -499,28 +471,28 @@ onMounted(async () => {
>{{ role[1] }}</el-checkbox
></el-checkbox-group
>
<div class="form-hint">不选则向所有角色显示。</div></el-form-item
><el-form-item label="说明"
<div class="form-hint">{{ t('calendar.form.rolesHint') }}</div></el-form-item
><el-form-item :label="t('calendar.form.description')"
><el-input
v-model="form.description"
type="textarea"
:rows="3"
maxlength="1000"
show-word-limit /></el-form-item
><el-form-item label="启用"
><el-form-item :label="t('calendar.form.enabled')"
><el-switch v-model="form.isEnabled" /></el-form-item></el-form
><template #footer
><el-button @click="dialogVisible = false">取消</el-button
><el-button type="primary" @click="save">保存</el-button></template
><el-button @click="dialogVisible = false">{{ t('calendar.cancel') }}</el-button
><el-button type="primary" @click="save">{{ t('calendar.save') }}</el-button></template
></el-dialog
><el-dialog
v-model="holidayDialogVisible"
title="同步法定节假日"
:title="t('calendar.sync.title')"
width="620px"
destroy-on-close
>
<p class="holiday-sync-intro">
从节假日数据源读取指定年份,写入当前选择的学期。再次同步同一年会替换此前同步的数据。
{{ t('calendar.sync.intro') }}
</p>
<div class="holiday-sync-controls">
<el-input-number
@@ -530,14 +502,14 @@ onMounted(async () => {
controls-position="right"
/>
<el-button :loading="holidayLoading" @click="previewHolidays"
>预览数据</el-button
>{{ t('calendar.sync.preview') }}</el-button
>
</div>
<div v-loading="holidayLoading" class="holiday-preview">
<el-empty
v-if="!holidayDays.length"
:image-size="50"
description="点击预览以加载节假日数据"
:description="t('calendar.sync.previewHint')"
/>
<div v-else class="holiday-preview-list">
<span
@@ -546,18 +518,18 @@ onMounted(async () => {
:class="{ workday: !item.isOffDay }"
>
<b>{{ item.date }}</b
>{{ item.name }} · {{ item.isOffDay ? "休息" : "调休上班" }}
>{{ item.name }} · {{ item.isOffDay ? t('calendar.sync.dayOff') : t('calendar.sync.workday') }}
</span>
</div>
</div>
<template #footer>
<el-button @click="holidayDialogVisible = false">取消</el-button>
<el-button @click="holidayDialogVisible = false">{{ t('calendar.cancel') }}</el-button>
<el-button
type="primary"
:loading="holidayLoading"
:disabled="!holidayDays.length"
@click="syncHolidays"
>同步到当前学期</el-button
>{{ t('calendar.sync.submit') }}</el-button
>
</template>
</el-dialog>
@@ -909,7 +881,7 @@ onMounted(async () => {
content: "●";
}
.calendar-event.holiday:after {
content: "休";
content: "○";
}
.weekdays span {
padding: 7px 2px;