Commit 2bf39f8d authored by xioln's avatar xioln

附件下载

parent 1ddce051
import {
get, post, del, downloadFile
} from '../utils/http'
// 文件下载
export function downPdf(params) {
return get('/dfs/fileManager/downloadCipher', params, true)
}
// 分片上传准备
export function uploadPartPrepare(params) {
return post('/dfs/fileManager/uploadPartPrepare', params, true)
}
// 获取存储库id
export function getBucketByAppID(params) {
return get('/RepoBucket/getBucketByAppID', params)
}
// 文件下载
export function downloadFileById(id) {
return get(`/dfs/fileManager/download?fileId=${id}`, null, true)
}
// 查询所有上传记录
export function getUploadRecord(params) {
// return post('/RepoFileUpload/find/recursion', params)
return post('/RepoFileUpload/findWithCondition', params)
}
// 删除上传文件
export function delUploadFileOrRecord(id) {
return del(`/RepoFileUpload/${id}`)
}
// 修改文件状态
export function changeFileStatusByUploadId(status, uploadId) {
return post(`/dfs/fileManager/changeFileStatusByUploadId?status=${status}&uploadId=${uploadId}`, null, true)
}
// 下载文件
export function downFileByFileIdMakerFile(objName, objId, linkId) {
return downloadFile(`/ExtAutoTask/downloadMakerFile?objName=${objName}&objId=${objId}&linkId=${linkId}`)
}
export function downFileByFileIdFile(fileId) {
return downloadFile(`/ExtAutoTask/downloadMakerFile?fileId=${fileId}`)
}
export function downFileByFileId(objName, objId, linkId) {
return downloadFile(`/dfs/fileManager/downloadio?objName=${objName}&objId=${objId}&linkId=${linkId}`)
}
export function downFileUseFileId(fileId) {
return downloadFile(`/dfs/fileManager/downloadio?fileId=${fileId}`)
}
export function downMakerFileByFileId(objName, objId, linkId) {
return downloadFile(`/ExtAutoTask/downloadMakerFile?objName=${objName}&objId=${objId}&linkId=${linkId}`)
}
......@@ -27,6 +27,14 @@
{{ getProperty(item, column.key) }}
</a>
</template>
<template v-else-if="column.type==='link'">
<a
@click="$emit('linkToUrl',item)"
style="text-decoration: underline; color: #1b77ea"
>
{{ getProperty(item, column.key)}}
</a>
</template>
<template v-else>
{{ getProperty(item, column.key) || '—' }}
</template>
......
......@@ -359,21 +359,31 @@ export function dynamicIcons (type, rModel, partNumber, model = null, name = '')
return icon
}
export function downLoadFileUrl (url, fileName = null) {
// showNotification('下载中,请稍后...', '提示', 'info')
const name = url.substring(url.lastIndexOf('/') + 1, url.length)
// export function downLoadFileUrl (url, fileName = null) {
// // showNotification('下载中,请稍后...', '提示', 'info')
// const name = url.substring(url.lastIndexOf('/') + 1, url.length)
// const link = document.createElement('a')
// link.style.display = 'none'
// link.href = url
// link.target = '_blank'
// /* link.setAttribute('id', fileName) */
// link.setAttribute('download', fileName || name)
// document.body.appendChild(link)
// link.click()
// document.body.removeChild(link)
// Notify({ type: 'warning', message: '下载中,请稍后...' })
// }
export function downLoadFileUrl(url, fileName = null) {
console.log('###', url)
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.target = '_blank'
/* link.setAttribute('id', fileName) */
link.setAttribute('download', fileName || name)
link.setAttribute('id', fileName)
link.setAttribute('download', fileName)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
Notify({ type: 'warning', message: '下载中,请稍后...' })
}
export function downLoad (url, label = null) {
// Notify({ type: 'warning', message: '下载中,请稍后...' })
downloadFile(url).then(res => {
......
......@@ -4,6 +4,7 @@
ref="tableCell"
:tableData="tableData"
:tableColumns="columns"
@linkToUrl="link"
></table-cell>
<van-loading v-if="!tableData" type="spinner" size="24px" vertical />
<van-empty v-if="tableData.length === 0" description="数据为空" />
......@@ -12,6 +13,8 @@
<script>
import TableCell from '@/components/tableCell'
import { downFileByFileIdFile } from '@/api/file'
export default {
props: {
basicData: {
......@@ -25,8 +28,8 @@ export default {
columns: [
{
title: '文件名',
key: 'originalFileName'
key: 'originalFileName',
type: 'link'
},
{
title: '文件大小',
......@@ -68,6 +71,37 @@ export default {
},
computed: {},
methods: {
link(item) {
downFileByFileIdFile(item.id).then(res => {
this.downLoadFileUrl(res)
}).catch(e => {
var reader = new FileReader()
reader.readAsText(e.data, 'utf-8')
reader.onload = (e) => {
const data = JSON.parse(reader.result)
this.$message.error(data.message)
}
})
},
downLoadFileUrl(res) {
if (res.headers['content-disposition']) {
const fileName = decodeURI(res.headers['content-disposition'].substring(res.headers['content-disposition'].indexOf('=') + 1, res.headers['content-disposition'].length))
const url = window.URL.createObjectURL(new Blob([res.data], { type: res.headers['content-type'] }))
this.$utils.downLoadFileUrl(url, decodeURI(fileName))
} else {
if (res.data instanceof Blob) {
var reader = new FileReader()
reader.addEventListener('loadend', () => {
const message = reader.result && JSON.parse(reader.result)
this.$utils.showMessage(message ? message.message : '数据包下载出错:未找到数据包内容的下载链接,请联系管理员排查问题!', 'warning')
})
reader.readAsText(res.data, 'utf-8')
} else {
const message = res.data && res.data.message
this.$utils.showMessage(message || '数据包下载出错:未找到数据包内容的下载链接,请联系管理员排查问题!', 'warning')
}
}
}
}
}
</script>
......
......@@ -340,6 +340,7 @@ export default {
box-sizing: border-box;
border-bottom: 1px solid #e1e2e4;
height: 180px;
overflow-y: auto;
}
.task {
margin-top: 5x;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment