Browse Source

打印文件pdf和图片支持在线 world和excle不支持

main
buaixuexideshitongxue 3 weeks ago
parent
commit
70c406afc7
  1. 59
      src/components/file/list.vue

59
src/components/file/list.vue

@ -205,18 +205,18 @@
<icon name="el-icon-Close" :size="28" />
</button>
<div class="btn-content">
<!-- <el-button @click="download" type="primary" plain>-->
<!-- <template #icon>-->
<!-- <icon name="el-icon-Download" :size="20" />-->
<!-- </template>-->
<!-- 下载文件-->
<!-- </el-button>-->
<!-- <el-button v-print="'#printTable'" type="primary" plain>-->
<!-- <template #icon>-->
<!-- <icon name="el-icon-Download" :size="20" />-->
<!-- </template>-->
<!-- 打印文件-->
<!-- </el-button>-->
<el-button @click="download" type="primary" plain>
<template #icon>
<icon name="el-icon-Download" :size="20" />
</template>
下载文件
</el-button>
<el-button type="primary" plain @click="handlePrintnew">
<template #icon>
<icon name="el-icon-Printer" :size="20" />
</template>
打印文件
</el-button>
</div>
</div>
@ -257,6 +257,39 @@ let initialX = 0;
let initialY = 0;
const fileRrror = ref(false);
const tableDatas = ref([])
function canPrint(file) {
if (!file?.fileName) return false
const type = getFileType(file.fileName)
return type === FileType.IMG || type === FileType.PDF
}
function handlePrintnew() {
const file = activeFile.value
if (!file) return
// 1
if (!canPrint(file)) {
ElMessage.warning('该文件格式不支持打印,请下载后打印')
downloadFile(file)
return
}
// 2
if (getFileType(file.fileName) === FileType.IMG) {
window.print()
return
}
// 3 PDF
if (getFileType(file.fileName) === FileType.PDF) {
const url = `${BASE_PATH}/file/stream/${file.filePath}`
const win = window.open(url)
win && win.print()
}
}
function filePreview(file) {
preview.value = true;
activeFile.value = file;
@ -265,7 +298,7 @@ function filePreview(file) {
translateX.value = 0;
translateY.value = 0;
moveFlag = false;
downloadFile(file)
// downloadFile(file)
// if (!file?.filePath) {
// ElMessage?.warning?.('')
// return

Loading…
Cancel
Save