diff --git a/web/src/components/ApprovalAttachmentList.vue b/web/src/components/ApprovalAttachmentList.vue index f733006..0243566 100644 --- a/web/src/components/ApprovalAttachmentList.vue +++ b/web/src/components/ApprovalAttachmentList.vue @@ -6,9 +6,23 @@ import http, { apiErrorMessage } from '../api/http' import AttachmentFileList from './AttachmentFileList.vue' const props = defineProps<{ type: string; id: string }>() -const { locale } = useI18n() +const { t } = useI18n() const files = ref<{ id: string; fileName: string; length: number }[]>([]) -onMounted(async () => { try { files.value = (await http.get(`/approval-attachments/${props.type}/${props.id}`)).data } catch (e) { ElMessage.error(apiErrorMessage(e)) } }) +const loading = ref(true) +const loadError = ref('') +async function loadFiles() { + loading.value = true + loadError.value = '' + try { + files.value = (await http.get(`/approval-attachments/${props.type}/${props.id}`)).data + } catch (error) { + loadError.value = apiErrorMessage(error) + } finally { + loading.value = false + } +} +onMounted(loadFiles) + async function download(file: { id: string; fileName: string }) { try { const response = await http.get(`/approval-attachments/${props.type}/${props.id}/${file.id}`, { responseType: 'blob' }) @@ -18,8 +32,13 @@ async function download(file: { id: string; fileName: string }) { diff --git a/web/src/components/ApprovalAttachmentPicker.vue b/web/src/components/ApprovalAttachmentPicker.vue index 8ebdd2e..4ff5847 100644 --- a/web/src/components/ApprovalAttachmentPicker.vue +++ b/web/src/components/ApprovalAttachmentPicker.vue @@ -7,19 +7,27 @@ import http, { apiErrorMessage } from '../api/http' const policyHintId = useId() const props = defineProps<{ type: string }>() const emit = defineEmits<{ change: [files: File[]] }>() -const { locale } = useI18n() -const policy = ref({ allowedExtensions: '', maxFileBytes: 0, maxFileCount: 0 }) -const ready = ref(false) -onMounted(async () => { - try { policy.value = (await http.get(`/approval-attachments/policy/${props.type}`)).data; ready.value = true } - catch (e) { ElMessage.error(apiErrorMessage(e)) } -}) +const { t } = useI18n() +const policy = ref<{ allowedExtensions: string; maxFileBytes: number; maxFileCount: number }>() +const loadError = ref('') +async function loadPolicy() { + loadError.value = '' + try { + policy.value = (await http.get(`/approval-attachments/policy/${props.type}`)).data + } catch (error) { + loadError.value = apiErrorMessage(error) + } +} +onMounted(loadPolicy) + function change(event: Event) { + const limits = policy.value + if (!limits) return const input = event.target as HTMLInputElement const files = Array.from(input.files ?? []) - const allowed = policy.value.allowedExtensions.split(',').map(x => x.trim().toLowerCase()) - if (files.length > policy.value.maxFileCount || files.reduce((sum, x) => sum + x.size, 0) > 104857600 || files.some(x => !x.size || x.size > policy.value.maxFileBytes || !allowed.some(ext => x.name.toLowerCase().endsWith(ext)))) { - ElMessage.warning(locale.value.startsWith('zh') ? '附件格式、大小或数量不符合要求。' : 'Attachment type, size or count does not meet the requirements.') + const allowed = limits.allowedExtensions.split(',').map(x => x.trim().toLowerCase()) + if (files.length > limits.maxFileCount || files.reduce((sum, x) => sum + x.size, 0) > 104857600 || files.some(x => !x.size || x.size > limits.maxFileBytes || !allowed.some(ext => x.name.toLowerCase().endsWith(ext)))) { + ElMessage.warning(t('approvalAttachments.invalid')) input.value = ''; emit('change', []); return } emit('change', files) @@ -27,7 +35,14 @@ function change(event: Event) { diff --git a/web/src/i18n/messages/en-US/approvals.ts b/web/src/i18n/messages/en-US/approvals.ts index 8ae8dc0..005670f 100644 --- a/web/src/i18n/messages/en-US/approvals.ts +++ b/web/src/i18n/messages/en-US/approvals.ts @@ -10,6 +10,14 @@ export default { hours: "hours", hint: "Measured from the time shown on each item. The threshold is saved in this browser.", }, + approvalAttachments: { + title: "Attachments", + empty: "No attachments", + loading: "Loading attachments…", + loadingPolicy: "Loading upload requirements…", + limits: "Up to {size} MiB per file, {count} files and 100 MiB in total.", + invalid: "Attachment type, size or count does not meet the requirements.", + }, approvalProgress: { receivingCollegeApproved: "Receiving college approved", receivingCollegeRejected: "Receiving college rejected", diff --git a/web/src/i18n/messages/zh-CN/approvals.ts b/web/src/i18n/messages/zh-CN/approvals.ts index 60c440a..4c932eb 100644 --- a/web/src/i18n/messages/zh-CN/approvals.ts +++ b/web/src/i18n/messages/zh-CN/approvals.ts @@ -9,6 +9,14 @@ export default { hours: "小时", hint: "按每条事项显示的时间计算,阈值保存在当前浏览器。", }, + approvalAttachments: { + title: "附件", + empty: "暂无附件", + loading: "正在加载附件…", + loadingPolicy: "正在加载上传要求…", + limits: "每个文件最多 {size} MiB,最多 {count} 个文件,总计不超过 100 MiB。", + invalid: "附件格式、大小或数量不符合要求。", + }, approvalProgress: { receivingCollegeApproved: "转入学院审核通过", receivingCollegeRejected: "转入学院驳回", diff --git a/web/src/style.css b/web/src/style.css index ee82fe2..e3e7ce7 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -2026,6 +2026,15 @@ button:focus-visible { background: var(--button-disabled-surface); cursor: not-allowed; } +.attachment-error { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 4px 12px; + margin-top: 6px; + color: var(--el-color-danger); + overflow-wrap: anywhere; +} .attachment-hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; } .el-dialog__title { color: var(--ink); font-weight: 650; }