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" /> <icon name="el-icon-Close" :size="28" />
</button> </button>
<div class="btn-content"> <div class="btn-content">
<!-- <el-button @click="download" type="primary" plain>--> <el-button @click="download" type="primary" plain>
<!-- <template #icon>--> <template #icon>
<!-- <icon name="el-icon-Download" :size="20" />--> <icon name="el-icon-Download" :size="20" />
<!-- </template>--> </template>
<!-- 下载文件--> 下载文件
<!-- </el-button>--> </el-button>
<!-- <el-button v-print="'#printTable'" type="primary" plain>--> <el-button type="primary" plain @click="handlePrintnew">
<!-- <template #icon>--> <template #icon>
<!-- <icon name="el-icon-Download" :size="20" />--> <icon name="el-icon-Printer" :size="20" />
<!-- </template>--> </template>
<!-- 打印文件--> 打印文件
<!-- </el-button>--> </el-button>
</div> </div>
</div> </div>
@ -257,6 +257,39 @@ let initialX = 0;
let initialY = 0; let initialY = 0;
const fileRrror = ref(false); const fileRrror = ref(false);
const tableDatas = ref([]) 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) { function filePreview(file) {
preview.value = true; preview.value = true;
activeFile.value = file; activeFile.value = file;
@ -265,7 +298,7 @@ function filePreview(file) {
translateX.value = 0; translateX.value = 0;
translateY.value = 0; translateY.value = 0;
moveFlag = false; moveFlag = false;
downloadFile(file) // downloadFile(file)
// if (!file?.filePath) { // if (!file?.filePath) {
// ElMessage?.warning?.('') // ElMessage?.warning?.('')
// return // return

Loading…
Cancel
Save