feat: localize shared campus workflows

This commit is contained in:
biss committed 2026-10-31 10:25:19 +08:00
1 parent 64798e7fe6
commit 3351cf6e80
12 files changed
+199 -100

No files matched your search

+20 -18
View File
@@ -1,9 +1,11 @@
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { ElMessage } from 'element-plus'
import http, { apiErrorMessage } from '../api/http'
const emit = defineEmits<{ changed: [] }>()
const { locale, t } = useI18n()
const visible = ref(false)
const busy = ref(false)
const kind = ref('')
@@ -16,10 +18,10 @@ const historyId = ref('')
const historyPage = ref(1)
const historyMode = ref(false)
const eligible = computed(() => previews.value.filter(x => !x.error && !x.blockers?.length && x.isArchived !== archived.value))
const title = computed(() => historyMode.value ? '归档操作历史' : archived.value ? '归档预检查' : '恢复预检查')
const title = computed(() => historyMode.value ? t('archive.historyTitle') : archived.value ? t('archive.archivePreview') : t('archive.restorePreview'))
async function open(entityKind: string, rows: { id: string }[], target: boolean) {
if (!rows.length) { ElMessage.info('请先选择记录'); return }
if (rows.length > 100) { ElMessage.warning('每次最多操作 100 条记录'); return }
if (!rows.length) { ElMessage.info(t('archive.selectRecords')); return }
if (rows.length > 100) { ElMessage.warning(t('archive.limit')); return }
kind.value = entityKind
archived.value = target
historyMode.value = false
@@ -64,33 +66,33 @@ defineExpose({ open, showHistory })
<div v-loading="busy" class="archive-content">
<template v-if="historyMode">
<article v-for="entry in history" :key="entry.id">
<strong>{{ entry.isArchived ? '归档' : '恢复' }} · {{ entry.actorName || entry.actorUserId }}</strong>
<p>{{ new Date(entry.createdAt).toLocaleString() }}</p><p>{{ entry.reason }}</p>
<strong>{{ entry.isArchived ? t('archive.archive') : t('archive.restore') }} · {{ entry.actorName || entry.actorUserId }}</strong>
<p>{{ new Date(entry.createdAt).toLocaleString(locale) }}</p><p>{{ entry.reason }}</p>
</article>
<el-empty v-if="!busy && !history.length" description="暂无操作历史(旧归档记录可能没有操作日志)" />
<el-empty v-if="!busy && !history.length" :description="t('archive.noHistory')" />
<div class="archive-pagination">
<el-button :disabled="busy || historyPage === 1" @click="historyPage--; loadHistory()">上一页</el-button>
<span>第 {{ historyPage }} 页</span>
<el-button :disabled="busy || history.length < 20" @click="historyPage++; loadHistory()">下一页</el-button>
<el-button :disabled="busy || historyPage === 1" @click="historyPage--; loadHistory()">{{ t('archive.previous') }}</el-button>
<span>{{ t('archive.page', { page: historyPage }) }}</span>
<el-button :disabled="busy || history.length < 20" @click="historyPage++; loadHistory()">{{ t('archive.next') }}</el-button>
</div>
</template>
<template v-else>
<p>符合条件 {{ eligible.length }} / {{ previews.length }} 条。提交时会再次检查,受阻记录不执行。</p>
<p>{{ t('archive.eligible', { eligible: eligible.length, total: previews.length }) }}</p>
<article v-for="item in previews" :key="item.id">
<strong>{{ item.name || '不可操作记录' }}</strong>
<strong>{{ item.name || t('archive.ineligible') }}</strong>
<p v-if="item.error" class="archive-error">{{ item.error }}</p>
<template v-else>
<p>{{ item.isArchived ? '已归档' : '未归档' }}<span v-if="item.archivedAt"> · {{ new Date(item.archivedAt).toLocaleString() }}</span></p>
<p v-if="item.archiveReason">归档原因:{{ item.archiveReason }}</p>
<p v-if="item.isArchived === archived">已处于目标状态,无需重复操作。</p>
<p>{{ item.isArchived ? t('archive.archived') : t('archive.notArchived') }}<span v-if="item.archivedAt"> · {{ new Date(item.archivedAt).toLocaleString(locale) }}</span></p>
<p v-if="item.archiveReason">{{ t('archive.reason', { reason: item.archiveReason }) }}</p>
<p v-if="item.isArchived === archived">{{ t('archive.alreadyTarget') }}</p>
<p v-for="(blocker, index) in item.blockers" :key="`b${index}`" class="archive-error">
{{ blocker.message }} <router-link v-if="blocker.link" :to="blocker.link" @click="visible = false">前往处理</router-link>
{{ blocker.message }} <router-link v-if="blocker.link" :to="blocker.link" @click="visible = false">{{ t('archive.handle') }}</router-link>
</p>
<p v-for="(notice, index) in item.notices" :key="`n${index}`">{{ notice.message }}</p>
</template>
</article>
<el-form v-if="!results.length" label-position="top">
<el-form-item :label="archived ? '归档原因(必填)' : '恢复原因(必填)'">
<el-form-item :label="archived ? t('archive.archiveReason') : t('archive.restoreReason')">
<el-input v-model="reason" type="textarea" :rows="3" maxlength="500" show-word-limit :disabled="busy" />
</el-form-item>
</el-form>
@@ -101,9 +103,9 @@ defineExpose({ open, showHistory })
</template>
</div>
<template #footer>
<el-button :disabled="busy" @click="visible = false">关闭</el-button>
<el-button :disabled="busy" @click="visible = false">{{ t('archive.close') }}</el-button>
<el-button v-if="!historyMode && !results.length" type="primary" :loading="busy" :disabled="!reason.trim() || !eligible.length" @click="apply">
{{ archived ? '确认归档' : '确认恢复' }}({{ eligible.length }})
{{ archived ? t('archive.confirmArchive') : t('archive.confirmRestore') }} ({{ eligible.length }})
</el-button>
</template>
</el-dialog>
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { computed, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { nativePlaceCandidatesForPostcode, postcodeForNativePlace } from '../data/nativePlaceLookup'
const postcode = defineModel<string>({ default: '' })
const nativePlace = defineModel<string>('nativePlace', { default: '' })
const props = defineProps<{ linked?: boolean; disabled?: boolean }>()
const { t } = useI18n()
const candidates = ref<string[]>([])
const suggestedPostcode = ref<string>()
@@ -64,12 +66,12 @@ watch(() => props.linked, (linked) => {
<template>
<div class="postcode-control">
<template v-if="linked !== false && lockedPrefix">
<el-input :model-value="lockedPrefix" disabled class="postcode-prefix" aria-label="邮政编码前四位" />
<el-input v-model="suffix" inputmode="numeric" maxlength="2" :disabled="disabled" placeholder="后两位" aria-label="邮政编码后两位" />
<el-input :model-value="lockedPrefix" disabled class="postcode-prefix" :aria-label="t('shared.postcode.prefix')" />
<el-input v-model="suffix" inputmode="numeric" maxlength="2" :disabled="disabled" :placeholder="t('shared.postcode.suffixPlaceholder')" :aria-label="t('shared.postcode.suffix')" />
</template>
<el-input v-else-if="linked !== false" :model-value="postcode" inputmode="numeric" maxlength="6" :disabled="disabled" placeholder="6位邮政编码" @update:model-value="updatePostcode" />
<el-input v-else v-model="postcode" maxlength="20" :disabled="disabled" placeholder="邮政编码" />
<el-select v-if="linked !== false && candidates.length > 1" :disabled="disabled" placeholder="请选择匹配的区县" @update:model-value="selectCandidate">
<el-input v-else-if="linked !== false" :model-value="postcode" inputmode="numeric" maxlength="6" :disabled="disabled" :placeholder="t('shared.postcode.sixDigits')" @update:model-value="updatePostcode" />
<el-input v-else v-model="postcode" maxlength="20" :disabled="disabled" :placeholder="t('shared.postcode.label')" />
<el-select v-if="linked !== false && candidates.length > 1" :disabled="disabled" :placeholder="t('shared.postcode.selectDistrict')" @update:model-value="selectCandidate">
<el-option v-for="candidate in candidates" :key="candidate" :label="candidate" :value="candidate" />
</el-select>
</div>
+17 -20
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { reactive, ref, watch } from 'vue'
import { computed, reactive, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { Delete, Refresh } from '@element-plus/icons-vue'
import http, { apiErrorMessage } from '../api/http'
@@ -8,16 +9,12 @@ type ReplyCursor = { createdAt: string; id: string }
type ReactionName = 'Like' | 'Insightful' | 'Agree' | 'Hooray' | 'Heart' | 'Rocket' | 'Eyes' | 'Laugh'
type ReactionOption = { type: ReactionName; emoji: string; label: string; countKey: string; activeKey: string }
type Comment = Reply & { replyCount: number; replies?: Reply[]; repliesHasMore?: boolean; repliesNextCursor?: ReplyCursor; [key: string]: string | number | boolean | Reply[] | ReplyCursor | undefined }
const reactionOptions: ReactionOption[] = [
{ type: 'Like', emoji: '👍', label: '赞', countKey: 'likeCount', activeKey: 'hasLiked' },
{ type: 'Insightful', emoji: '💡', label: '有启发', countKey: 'insightfulCount', activeKey: 'hasInsightful' },
{ type: 'Agree', emoji: '🤝', label: '认同', countKey: 'agreeCount', activeKey: 'hasAgreed' },
{ type: 'Hooray', emoji: '🎉', label: '庆祝', countKey: 'hoorayCount', activeKey: 'hasHoorayed' },
{ type: 'Heart', emoji: '❤️', label: '喜欢', countKey: 'heartCount', activeKey: 'hasHearted' },
{ type: 'Rocket', emoji: '🚀', label: '很棒', countKey: 'rocketCount', activeKey: 'hasRocketed' },
{ type: 'Eyes', emoji: '👀', label: '关注', countKey: 'eyesCount', activeKey: 'hasEyed' },
{ type: 'Laugh', emoji: '😄', label: '好笑', countKey: 'laughCount', activeKey: 'hasLaughed' },
]
const { locale, t } = useI18n()
const reactionDefinitions = [
['Like', '👍', 'likeCount', 'hasLiked'], ['Insightful', '💡', 'insightfulCount', 'hasInsightful'], ['Agree', '🤝', 'agreeCount', 'hasAgreed'], ['Hooray', '🎉', 'hoorayCount', 'hasHoorayed'],
['Heart', '❤️', 'heartCount', 'hasHearted'], ['Rocket', '🚀', 'rocketCount', 'hasRocketed'], ['Eyes', '👀', 'eyesCount', 'hasEyed'], ['Laugh', '😄', 'laughCount', 'hasLaughed'],
] as const
const reactionOptions = computed<ReactionOption[]>(() => reactionDefinitions.map(([type, emoji, countKey, activeKey]) => ({ type, emoji, label: t(`discussion.reactions.${type}`), countKey, activeKey })))
const props = defineProps<{ sheetId: string; courseName?: string }>()
const comments = ref<Comment[]>([]); const loading = ref(false); const submitting = ref(false)
const content = ref(''); const anonymous = ref(false); const hasMore = ref(false)
@@ -35,9 +32,9 @@ async function load(reset = false) {
} catch (error) { ElMessage.error(apiErrorMessage(error)) } finally { loading.value = false }
}
async function submit() {
const text = content.value.trim(); if (!text) return ElMessage.warning('请先输入评论内容。')
const text = content.value.trim(); if (!text) return ElMessage.warning(t('discussion.messages.enterContent'))
submitting.value = true
try { await http.post(`${base()}/comments`, { content: text, isAnonymous: anonymous.value }); content.value = ''; await load(true); ElMessage.success(anonymous.value ? '匿名评论已发布。' : '实名评论已发布。') }
try { await http.post(`${base()}/comments`, { content: text, isAnonymous: anonymous.value }); content.value = ''; await load(true); ElMessage.success(t(anonymous.value ? 'discussion.messages.anonymousPublished' : 'discussion.messages.published')) }
catch (error) { ElMessage.error(apiErrorMessage(error)) } finally { submitting.value = false }
}
function reactionCount(comment: Comment, option: ReactionOption) { return Number(comment[option.countKey] ?? 0) }
@@ -62,7 +59,7 @@ async function reply(comment: Comment) {
try { await http.post(`${base()}/comments/${comment.id}/replies`, { content: text, isAnonymous: replyAnonymous[comment.id] === true }); drafts[comment.id] = ''; comment.replies = undefined; replyOpen[comment.id] = false; await toggleReplies(comment); await load(true) } catch (error) { ElMessage.error(apiErrorMessage(error)) }
}
async function remove(comment: Reply) {
try { await ElMessageBox.confirm('删除后不能恢复,确定要删除这条评论吗?', '删除评论', { type: 'warning' }); await http.delete(`${base()}/comments/${comment.id}`); await load(true); ElMessage.success('评论已删除。') }
try { await ElMessageBox.confirm(t('discussion.messages.deleteConfirm'), t('discussion.messages.deleteTitle'), { type: 'warning' }); await http.delete(`${base()}/comments/${comment.id}`); await load(true); ElMessage.success(t('discussion.messages.deleted')) }
catch (error) { if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error)) }
}
watch(() => props.sheetId, () => load(true), { immediate: true })
@@ -70,12 +67,12 @@ watch(() => props.sheetId, () => load(true), { immediate: true })
<template>
<section class="course-discussion" v-loading="loading">
<header><div><span>COURSE DISCUSSION</span><h3>{{ courseName }} · 课程讨论</h3><p>仅限已发布该课程成绩的用户参与;匿名会隐藏姓名,但系统保留作者以便本人删除和管理员处理。</p></div><el-button :icon="Refresh" circle aria-label="刷新评论" @click="load(true)" /></header>
<el-input v-model="content" type="textarea" :rows="3" maxlength="1000" show-word-limit placeholder="分享对这门课程成绩、学习收获或教学改进的看法" />
<div class="compose"><el-checkbox v-model="anonymous">匿名发布</el-checkbox><el-button type="primary" :loading="submitting" @click="submit">发布评论</el-button></div>
<el-empty v-if="!loading && !comments.length" :image-size="64" description="还没有评论,来说说你的看法吧" />
<ol v-else class="comments"><li v-for="comment in comments" :key="comment.id"><div class="meta"><strong>{{ comment.authorName || '未命名用户' }}</strong><span v-if="comment.isAnonymous">匿名</span><time>{{ new Date(comment.createdAt).toLocaleString('zh-CN') }}</time></div><p>{{ comment.content }}</p><div class="actions"><div class="reaction-bar"><button v-for="option in reactionOptions.filter(item => reactionCount(comment, item))" :key="option.type" type="button" class="reaction-chip" :class="{ active: reacted(comment, option) }" :aria-label="`${option.label} ${reactionCount(comment, option)}`" @click="react(comment, option.type)">{{ option.emoji }} <span>{{ reactionCount(comment, option) }}</span></button><el-popover placement="top-start" :width="260" trigger="click"><template #reference><el-button class="reaction-add" text size="small" aria-label="添加表情反应">😊</el-button></template><div class="reaction-picker" aria-label="选择表情反应"><button v-for="option in reactionOptions" :key="option.type" type="button" :class="{ active: reacted(comment, option) }" :aria-label="option.label" @click="react(comment, option.type)"><span>{{ option.emoji }}</span><small>{{ option.label }}</small></button></div></el-popover></div><el-button text size="small" @click="toggleReplies(comment)">回复{{ comment.replyCount ? ` (${comment.replyCount})` : '' }}</el-button><el-button v-if="comment.canDelete" text type="danger" size="small" :icon="Delete" @click="remove(comment)">删除</el-button></div><div v-if="replyOpen[comment.id]" class="replies" v-loading="replyLoading[comment.id]"><ol v-if="comment.replies?.length"><li v-for="item in comment.replies" :key="item.id"><div class="meta"><strong>{{ item.authorName }}</strong><span v-if="item.isAnonymous">匿名</span><time>{{ new Date(item.createdAt).toLocaleString('zh-CN') }}</time></div><p>{{ item.content }}</p><el-button v-if="item.canDelete" text type="danger" size="small" @click="remove(item)">删除</el-button></li></ol><div v-if="comment.repliesHasMore" class="more"><el-button size="small" :loading="replyLoading[comment.id]" @click="loadReplies(comment)">加载更多回复</el-button></div><el-input v-model="drafts[comment.id]" type="textarea" :rows="2" maxlength="1000" show-word-limit placeholder="回复这条评论" /><div class="compose"><el-checkbox v-model="replyAnonymous[comment.id]">匿名回复</el-checkbox><el-button type="primary" size="small" @click="reply(comment)">回复</el-button></div></div></li></ol>
<div v-if="hasMore" class="more"><el-button :loading="loading" @click="load()">加载更多评论</el-button></div>
<header><div><span>COURSE DISCUSSION</span><h3>{{ courseName }} · {{ t('discussion.title') }}</h3><p>{{ t('discussion.description') }}</p></div><el-button :icon="Refresh" circle :aria-label="t('discussion.refresh')" @click="load(true)" /></header>
<el-input v-model="content" type="textarea" :rows="3" maxlength="1000" show-word-limit :placeholder="t('discussion.placeholder')" />
<div class="compose"><el-checkbox v-model="anonymous">{{ t('discussion.anonymousPublish') }}</el-checkbox><el-button type="primary" :loading="submitting" @click="submit">{{ t('discussion.publish') }}</el-button></div>
<el-empty v-if="!loading && !comments.length" :image-size="64" :description="t('discussion.empty')" />
<ol v-else class="comments"><li v-for="comment in comments" :key="comment.id"><div class="meta"><strong>{{ comment.authorName || t('discussion.unnamed') }}</strong><span v-if="comment.isAnonymous">{{ t('discussion.anonymous') }}</span><time>{{ new Date(comment.createdAt).toLocaleString(locale) }}</time></div><p>{{ comment.content }}</p><div class="actions"><div class="reaction-bar"><button v-for="option in reactionOptions.filter(item => reactionCount(comment, item))" :key="option.type" type="button" class="reaction-chip" :class="{ active: reacted(comment, option) }" :aria-label="`${option.label} ${reactionCount(comment, option)}`" @click="react(comment, option.type)">{{ option.emoji }} <span>{{ reactionCount(comment, option) }}</span></button><el-popover placement="top-start" :width="260" trigger="click"><template #reference><el-button class="reaction-add" text size="small" :aria-label="t('discussion.addReaction')">😊</el-button></template><div class="reaction-picker" :aria-label="t('discussion.selectReaction')"><button v-for="option in reactionOptions" :key="option.type" type="button" :class="{ active: reacted(comment, option) }" :aria-label="option.label" @click="react(comment, option.type)"><span>{{ option.emoji }}</span><small>{{ option.label }}</small></button></div></el-popover></div><el-button text size="small" @click="toggleReplies(comment)">{{ t('discussion.reply') }}{{ comment.replyCount ? ` (${comment.replyCount})` : '' }}</el-button><el-button v-if="comment.canDelete" text type="danger" size="small" :icon="Delete" @click="remove(comment)">{{ t('discussion.delete') }}</el-button></div><div v-if="replyOpen[comment.id]" class="replies" v-loading="replyLoading[comment.id]"><ol v-if="comment.replies?.length"><li v-for="item in comment.replies" :key="item.id"><div class="meta"><strong>{{ item.authorName }}</strong><span v-if="item.isAnonymous">{{ t('discussion.anonymous') }}</span><time>{{ new Date(item.createdAt).toLocaleString(locale) }}</time></div><p>{{ item.content }}</p><el-button v-if="item.canDelete" text type="danger" size="small" @click="remove(item)">{{ t('discussion.delete') }}</el-button></li></ol><div v-if="comment.repliesHasMore" class="more"><el-button size="small" :loading="replyLoading[comment.id]" @click="loadReplies(comment)">{{ t('discussion.loadMoreReplies') }}</el-button></div><el-input v-model="drafts[comment.id]" type="textarea" :rows="2" maxlength="1000" show-word-limit :placeholder="t('discussion.replyPlaceholder')" /><div class="compose"><el-checkbox v-model="replyAnonymous[comment.id]">{{ t('discussion.anonymousReply') }}</el-checkbox><el-button type="primary" size="small" @click="reply(comment)">{{ t('discussion.reply') }}</el-button></div></div></li></ol>
<div v-if="hasMore" class="more"><el-button :loading="loading" @click="load()">{{ t('discussion.loadMoreComments') }}</el-button></div>
</section>
</template>
Loaded 3 of 12 files, more files were not shown because too many files have changed in this diff. Show more