Browse Source

文件浏览组件--点击预览的时候直接下载,去除下载文件、打印文件按钮

main
buaixuexideshitongxue 3 weeks ago
parent
commit
d77e4e8f67
  1. 34
      src/components/file/list.vue

34
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 v-print="'#printTable'" 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>-->
</div> </div>
</div> </div>
@ -265,6 +265,7 @@ function filePreview(file) {
translateX.value = 0; translateX.value = 0;
translateY.value = 0; translateY.value = 0;
moveFlag = false; moveFlag = false;
downloadFile(file)
// if (!file?.filePath) { // if (!file?.filePath) {
// ElMessage?.warning?.('') // ElMessage?.warning?.('')
// return // return
@ -309,6 +310,15 @@ function filePreview(file) {
// moveFlag = false; // moveFlag = false;
} }
function downloadFile(file) {
const a = document.createElement('a')
a.href = `${BASE_PATH}/file/stream/${file.filePath}`
a.download = file.fileName || ''
a.style.display = 'none'
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
}
function remove(index) { function remove(index) {
const files = [...props.files]; const files = [...props.files];

Loading…
Cancel
Save