Share attachment loading and retry states with student leave requests
This commit is contained in:
1 parent
0b20ce3068
commit
52776feb2b
4 files changed
+20
-26
No files matched your search
Vendored
+1
-1
@@ -12,7 +12,6 @@ export {}
|
||||
declare module 'vue' {
|
||||
export interface GlobalComponents {
|
||||
AcademicCalendarReminder: typeof import('./components/AcademicCalendarReminder.vue')['default']
|
||||
ApprovalAttachmentList: typeof import('./components/ApprovalAttachmentList.vue')['default']
|
||||
ApprovalAttachmentPicker: typeof import('./components/ApprovalAttachmentPicker.vue')['default']
|
||||
AppUpdateManagementPanel: typeof import('./components/AppUpdateManagementPanel.vue')['default']
|
||||
ArchiveDialog: typeof import('./components/ArchiveDialog.vue')['default']
|
||||
@@ -80,6 +79,7 @@ declare module 'vue' {
|
||||
NotificationDeliverySettings: typeof import('./components/NotificationDeliverySettings.vue')['default']
|
||||
NotificationRichTextEditor: typeof import('./components/NotificationRichTextEditor.vue')['default']
|
||||
PerformanceReportPanel: typeof import('./components/PerformanceReportPanel.vue')['default']
|
||||
RecordAttachmentList: typeof import('./components/RecordAttachmentList.vue')['default']
|
||||
RichMessageContent: typeof import('./components/RichMessageContent.vue')['default']
|
||||
RouterLink: typeof import('vue-router')['RouterLink']
|
||||
RouterView: typeof import('vue-router')['RouterView']
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ import { ElMessage } from 'element-plus'
|
||||
import http, { apiErrorMessage } from '../api/http'
|
||||
import AttachmentFileList from './AttachmentFileList.vue'
|
||||
|
||||
const props = defineProps<{ type: string; id: string }>()
|
||||
const props = defineProps<{ endpoint: string; showTitle?: boolean }>()
|
||||
const { t } = useI18n()
|
||||
const files = ref<{ id: string; fileName: string; length: number }[]>([])
|
||||
const loading = ref(true)
|
||||
@@ -14,7 +14,7 @@ async function loadFiles() {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
files.value = (await http.get(`/approval-attachments/${props.type}/${props.id}`)).data
|
||||
files.value = (await http.get(props.endpoint)).data
|
||||
} catch (error) {
|
||||
loadError.value = apiErrorMessage(error)
|
||||
} finally {
|
||||
@@ -25,14 +25,14 @@ 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' })
|
||||
const response = await http.get(`${props.endpoint}/${file.id}`, { responseType: 'blob' })
|
||||
const url = URL.createObjectURL(response.data); const link = document.createElement('a'); link.href = url; link.download = file.fileName; link.click(); setTimeout(() => URL.revokeObjectURL(url), 1000)
|
||||
} catch (e) { ElMessage.error(apiErrorMessage(e)) }
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<section>
|
||||
<strong>{{ t('approvalAttachments.title') }}</strong>
|
||||
<strong v-if="showTitle">{{ t('approvalAttachments.title') }}</strong>
|
||||
<p v-if="loading" class="attachment-hint" role="status">{{ t('approvalAttachments.loading') }}</p>
|
||||
<div v-else-if="loadError" class="attachment-error">
|
||||
<span role="alert">{{ loadError }}</span>
|
||||
@@ -3,7 +3,7 @@ import { computed, onMounted, reactive, ref, useId } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import http, { apiErrorMessage } from '../api/http'
|
||||
import AttachmentFileList from './AttachmentFileList.vue'
|
||||
import RecordAttachmentList from './RecordAttachmentList.vue'
|
||||
import { downloadApiFile } from '../api/excel'
|
||||
|
||||
const policyHintId = useId()
|
||||
@@ -23,25 +23,13 @@ const files = ref<File[]>([])
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
const filePolicy = ref({ allowedExtensions: '.pdf,.jpg,.jpeg,.png', maxFileBytes: 10485760, maxFileCount: 5 })
|
||||
const attachmentDialog = ref(false)
|
||||
const attachments = ref<{ id: string; fileName: string; length: number }[]>([])
|
||||
const attachmentLeaveId = ref('')
|
||||
function selectFiles(event: Event) {
|
||||
files.value = Array.from((event.target as HTMLInputElement).files ?? [])
|
||||
}
|
||||
async function showAttachments(row: any) {
|
||||
try {
|
||||
attachments.value = (await http.get(`/student-leave-attachments/${row.id}`)).data
|
||||
attachmentLeaveId.value = row.id
|
||||
attachmentDialog.value = true
|
||||
} catch (e) { ElMessage.error(apiErrorMessage(e)) }
|
||||
}
|
||||
async function downloadAttachment(file: { id: string; fileName: string }) {
|
||||
try {
|
||||
const response = await http.get(`/student-leave-attachments/${attachmentLeaveId.value}/${file.id}`, { responseType: 'blob' })
|
||||
const url = URL.createObjectURL(response.data)
|
||||
const link = document.createElement('a'); link.href = url; link.download = file.fileName; link.click()
|
||||
setTimeout(() => URL.revokeObjectURL(url), 1000)
|
||||
} catch (e) { ElMessage.error(apiErrorMessage(e)) }
|
||||
function showAttachments(id: string) {
|
||||
attachmentLeaveId.value = id
|
||||
attachmentDialog.value = true
|
||||
}
|
||||
async function downloadForm(row: any) {
|
||||
try { await downloadApiFile(`/student-leaves/${row.id}/form.docx`, 'student-leave.docx') }
|
||||
@@ -113,7 +101,7 @@ onMounted(async () => {
|
||||
<el-table-column v-if="student" :label="tr('状态', 'Status')" min-width="100"><template #default="{ row }">{{ label(statuses, row.status) }}</template></el-table-column>
|
||||
<el-table-column v-if="student" prop="reviewComment" :label="tr('审核意见', 'Review comment')" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column :label="tr('操作', 'Actions')" min-width="150"><template #default="{ row }">
|
||||
<el-button link @click="showAttachments(row)">{{ tr('附件', 'Attachments') }}</el-button>
|
||||
<el-button link @click="showAttachments(row.id)">{{ tr('附件', 'Attachments') }}</el-button>
|
||||
<el-button link @click="downloadForm(row)">{{ tr('下载申请表', 'Download form') }}</el-button>
|
||||
<el-button v-if="student && row.status === 'Submitted'" link @click="withdraw(row)">{{ tr('撤回', 'Withdraw') }}</el-button>
|
||||
<template v-if="manager && !student"><el-button link type="primary" @click="review(row, true)">{{ tr('通过', 'Approve') }}</el-button><el-button link type="danger" @click="review(row, false)">{{ tr('驳回', 'Reject') }}</el-button></template>
|
||||
@@ -135,8 +123,11 @@ onMounted(async () => {
|
||||
<template #footer><el-button @click="dialog = false">{{ tr('取消', 'Cancel') }}</el-button><el-button type="primary" :loading="busy" @click="submit">{{ tr('提交', 'Submit') }}</el-button></template>
|
||||
</el-dialog>
|
||||
<el-dialog v-model="attachmentDialog" :title="tr('附件', 'Attachments')" width="min(560px, 95vw)">
|
||||
<el-empty v-if="!attachments.length" :description="tr('暂无附件', 'No attachments')" />
|
||||
<AttachmentFileList v-else :files="attachments" @download="downloadAttachment" />
|
||||
<RecordAttachmentList
|
||||
v-if="attachmentDialog"
|
||||
:key="attachmentLeaveId"
|
||||
:endpoint="`/student-leave-attachments/${attachmentLeaveId}`"
|
||||
/>
|
||||
</el-dialog>
|
||||
</section>
|
||||
</template>
|
||||
@@ -144,5 +135,8 @@ onMounted(async () => {
|
||||
<style scoped>
|
||||
.leave-panel { padding: 20px; margin: 20px 0; background: var(--el-bg-color); border: 1px solid var(--el-border-color-light); border-radius: var(--radius-card); }
|
||||
.leave-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
|
||||
@media (max-width: 600px) {
|
||||
.leave-heading { flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
|
||||
}
|
||||
.leave-heading h2 { margin: 0; font-size: 18px; }.leave-heading p { color: var(--el-text-color-secondary); font-size: 13px; }
|
||||
</style>
|
||||
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user