Add attachments to assessment and course applications
This commit is contained in:
1 parent
bdfbf49f40
commit
d36c0ff7b8
17 files changed
+12906
-39
No files matched your search
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import http, { apiErrorMessage } from '../api/http'
|
||||
const props = defineProps<{ type: string; id: string }>()
|
||||
const { locale } = 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)) } })
|
||||
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 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>{{ locale.startsWith('zh') ? '附件' : 'Attachments' }}</strong><p v-if="!files.length">{{ locale.startsWith('zh') ? '暂无附件' : 'No attachments' }}</p><div v-for="file in files" :key="file.id"><el-button link type="primary" @click="download(file)">{{ file.fileName }}</el-button> ({{ (file.length / 1024).toFixed(1) }} KiB)</div></section>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import http, { apiErrorMessage } from '../api/http'
|
||||
|
||||
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)) }
|
||||
})
|
||||
function change(event: Event) {
|
||||
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.')
|
||||
input.value = ''; emit('change', []); return
|
||||
}
|
||||
emit('change', files)
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<div>
|
||||
<input type="file" multiple :disabled="!ready" :accept="policy.allowedExtensions" @change="change" />
|
||||
<p v-if="ready">{{ policy.allowedExtensions }} · {{ (policy.maxFileBytes / 1048576).toFixed(1) }} MiB / {{ locale.startsWith('zh') ? '文件' : 'file' }} · {{ locale.startsWith('zh') ? '最多' : 'up to' }} {{ policy.maxFileCount }} · {{ locale.startsWith('zh') ? '总计不超过 100 MiB' : '100 MiB total' }}</p>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user