|
@@ -1479,18 +1479,7 @@
|
|
|
this.$message.warning('该文书暂无文件可下载')
|
|
this.$message.warning('该文书暂无文件可下载')
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 创建隐藏的a标签进行下载
|
|
|
|
|
- const link = document.createElement('a')
|
|
|
|
|
- link.style.display = 'none'
|
|
|
|
|
- link.href = row.fileUrl
|
|
|
|
|
- // 设置下载文件名
|
|
|
|
|
- link.download = row.name || '文书文件'
|
|
|
|
|
- document.body.appendChild(link)
|
|
|
|
|
- link.click()
|
|
|
|
|
- document.body.removeChild(link)
|
|
|
|
|
-
|
|
|
|
|
- this.$message.success('开始下载文件')
|
|
|
|
|
|
|
+ this.downloadByFetch(row.fileUrl, row.name || '文书文件')
|
|
|
},
|
|
},
|
|
|
// 上传附件
|
|
// 上传附件
|
|
|
handleUpload(row) {
|
|
handleUpload(row) {
|
|
@@ -1513,18 +1502,70 @@
|
|
|
this.$message.warning('该资料暂无文件可下载')
|
|
this.$message.warning('该资料暂无文件可下载')
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- // 创建隐藏的a标签进行下载
|
|
|
|
|
- const link = document.createElement('a')
|
|
|
|
|
- link.style.display = 'none'
|
|
|
|
|
- link.href = row.fileUrl
|
|
|
|
|
- // 设置下载文件名,优先使用资料名称
|
|
|
|
|
- link.download = row.informationName || '下载文件'
|
|
|
|
|
- document.body.appendChild(link)
|
|
|
|
|
- link.click()
|
|
|
|
|
- document.body.removeChild(link)
|
|
|
|
|
-
|
|
|
|
|
- this.$message.success('开始下载文件')
|
|
|
|
|
|
|
+ this.downloadByFetch(row.fileUrl, row.informationName || '下载文件')
|
|
|
|
|
+ },
|
|
|
|
|
+ async downloadByFetch(rawUrl, fallbackName) {
|
|
|
|
|
+ const url = this.normalizeUrl(rawUrl)
|
|
|
|
|
+ let loading
|
|
|
|
|
+ try {
|
|
|
|
|
+ loading = this.$baseLoading
|
|
|
|
|
+ ? this.$baseLoading(1, '文件下载中...')
|
|
|
|
|
+ : this.$loading({
|
|
|
|
|
+ lock: true,
|
|
|
|
|
+ text: '文件下载中...',
|
|
|
|
|
+ spinner: 'el-icon-loading',
|
|
|
|
|
+ background: 'rgba(0,0,0,0.7)',
|
|
|
|
|
+ })
|
|
|
|
|
+ const res = await fetch(url, { method: 'GET' })
|
|
|
|
|
+ if (!res.ok) throw new Error('下载失败')
|
|
|
|
|
+ const blob = await res.blob()
|
|
|
|
|
+ let fileName =
|
|
|
|
|
+ this.extractFileName(res.headers.get('content-disposition')) ||
|
|
|
|
|
+ fallbackName ||
|
|
|
|
|
+ '下载文件'
|
|
|
|
|
+ if (!/\.[a-zA-Z0-9]+$/.test(fileName)) {
|
|
|
|
|
+ const extFromUrl = (
|
|
|
|
|
+ url.split('?')[0].split('#')[0].split('.').pop() || ''
|
|
|
|
|
+ ).toLowerCase()
|
|
|
|
|
+ fileName = extFromUrl ? `${fileName}.${extFromUrl}` : fileName
|
|
|
|
|
+ }
|
|
|
|
|
+ const objectUrl = window.URL.createObjectURL(blob)
|
|
|
|
|
+ const link = document.createElement('a')
|
|
|
|
|
+ link.style.display = 'none'
|
|
|
|
|
+ link.href = objectUrl
|
|
|
|
|
+ link.download = fileName
|
|
|
|
|
+ document.body.appendChild(link)
|
|
|
|
|
+ link.click()
|
|
|
|
|
+ document.body.removeChild(link)
|
|
|
|
|
+ window.URL.revokeObjectURL(objectUrl)
|
|
|
|
|
+ this.$message.success('开始下载文件')
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ this.$message.error(e.message || '文件下载失败')
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ if (loading && loading.close) loading.close()
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ normalizeUrl(u) {
|
|
|
|
|
+ if (!u) return ''
|
|
|
|
|
+ if (/^https?:\/\//i.test(u)) return u
|
|
|
|
|
+ const base = (window.context && window.context.form) || ''
|
|
|
|
|
+ if (!base) return u
|
|
|
|
|
+ if (u.startsWith('/')) return base + u
|
|
|
|
|
+ return base.replace(/\/$/, '') + '/' + u
|
|
|
|
|
+ },
|
|
|
|
|
+ extractFileName(contentDisposition) {
|
|
|
|
|
+ if (!contentDisposition) return ''
|
|
|
|
|
+ const match = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/i.exec(
|
|
|
|
|
+ contentDisposition
|
|
|
|
|
+ )
|
|
|
|
|
+ if (match && match[1]) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return decodeURIComponent(match[1].replace(/['"]/g, ''))
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ return match[1].replace(/['"]/g, '')
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ''
|
|
|
},
|
|
},
|
|
|
// 报送资料文件上传
|
|
// 报送资料文件上传
|
|
|
async handleFileUpload(row, acceptFromChild) {
|
|
async handleFileUpload(row, acceptFromChild) {
|