Browse Source

附件上传做限制,下载做个性处理

main
buaixuexideshitongxue 2 months ago
parent
commit
1a4b6f01bc
  1. 37
      src/components/file/list.vue
  2. 10
      src/components/file/upload.vue

37
src/components/file/list.vue

@ -231,6 +231,7 @@ import "@vue-office/docx/lib/index.css";
import "@vue-office/excel/lib/index.css"; import "@vue-office/excel/lib/index.css";
import VueOfficeDocx from "@vue-office/docx"; import VueOfficeDocx from "@vue-office/docx";
import VueOfficeExcel from "@vue-office/excel"; import VueOfficeExcel from "@vue-office/excel";
import {ElMessage} from "element-plus";
const props = defineProps({ const props = defineProps({
files: { files: {
@ -257,9 +258,43 @@ let initialY = 0;
const fileRrror = ref(false); const fileRrror = ref(false);
const tableDatas = ref([]) const tableDatas = ref([])
function filePreview(file) { function filePreview(file) {
if (!file?.filePath) {
ElMessage?.warning?.('文件路径不存在,无法下载')
return
}
const url = `${BASE_PATH}/file/stream/${file.filePath}`
const type = getFileType(file.fileName)
// 1. PDF
if (type === FileType.PDF) {
window.open(url, '_blank')
return
}
// 2. Word / Excel
if (
type === FileType.WORD ||
type === FileType.EXCEL
) {
const a = document.createElement('a')
a.href = url
a.download = file.fileName || ''
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
return
}
preview.value = true; // 3.
const a = document.createElement('a')
a.href = url
a.download = file.fileName || ''
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
activeIndex.value = index;
activeFile.value = file; activeFile.value = file;
console.log(activeFile.value)
preview.value = true;
rotate.value = 0; rotate.value = 0;
scale.value = 1; scale.value = 1;
translateX.value = 0; translateX.value = 0;

10
src/components/file/upload.vue

@ -73,6 +73,16 @@ watch(files, () => {
},{immediate:true}); },{immediate:true});
function beforeUpload(file) { function beforeUpload(file) {
const allowExt = ['doc', 'docx', 'pdf', 'xls', 'xlsx']
const name = (file?.name || '').toLowerCase()
const ext = name.includes('.') ? name.split('.').pop() : ''
if (!allowExt.includes(ext)) {
feedback.msgWarning(
'只能上传 Word / PDF / Excel 文件(.doc .docx .pdf .xls .xlsx)'
)
return false
}
// 1024 * 1024 * 100 100MB // 1024 * 1024 * 100 100MB
if (file.size >= 104857600) { if (file.size >= 104857600) {
feedback.msgError('文件大小不能超过100MB'); feedback.msgError('文件大小不能超过100MB');

Loading…
Cancel
Save