|
|
@@ -439,7 +439,7 @@
|
|
|
"
|
|
|
type="text"
|
|
|
size="small"
|
|
|
- @click="$emit('handleFileView', scope.row)"
|
|
|
+ @click="handleFileView(scope.row)"
|
|
|
>
|
|
|
查看
|
|
|
</el-button>
|
|
|
@@ -449,7 +449,7 @@
|
|
|
"
|
|
|
type="text"
|
|
|
size="small"
|
|
|
- @click="$emit('handleFileDownload', scope.row)"
|
|
|
+ @click="handleFileDownload(scope.row)"
|
|
|
>
|
|
|
下载
|
|
|
</el-button>
|
|
|
@@ -919,6 +919,113 @@
|
|
|
this.initData()
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 报送资料-查看(同 taskFillIn)
|
|
|
+ handleFileView(row) {
|
|
|
+ console.log(row, '这一行数据')
|
|
|
+ try {
|
|
|
+ const filePath =
|
|
|
+ row?.filePath ||
|
|
|
+ row?.filepath ||
|
|
|
+ row?.fileUrl ||
|
|
|
+ row?.url ||
|
|
|
+ row?.path ||
|
|
|
+ ''
|
|
|
+ if (!filePath) {
|
|
|
+ this.$message &&
|
|
|
+ this.$message.warning &&
|
|
|
+ this.$message.warning('未找到可预览的文件路径')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const encodedUrl = encodeURIComponent(
|
|
|
+ Base64.encode((window.context && window.context.form) + filePath)
|
|
|
+ )
|
|
|
+ window.open(`${host}:8012/onlinePreview?url=${encodedUrl}`)
|
|
|
+ // 兼容保留:通知父组件
|
|
|
+ this.$emit('handleFileView', row)
|
|
|
+ } catch (e) {
|
|
|
+ console.error('文件预览失败: ', e)
|
|
|
+ this.$message &&
|
|
|
+ this.$message.error &&
|
|
|
+ this.$message.error('文件预览失败')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 报送资料-下载(同 taskFillIn)
|
|
|
+ handleFileDownload(row) {
|
|
|
+ if (!row || !row.fileUrl) {
|
|
|
+ this.$message &&
|
|
|
+ this.$message.warning &&
|
|
|
+ this.$message.warning('该资料暂无文件可下载')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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 &&
|
|
|
+ this.$message.success &&
|
|
|
+ this.$message.success('开始下载文件')
|
|
|
+ } catch (e) {
|
|
|
+ this.$message &&
|
|
|
+ this.$message.error &&
|
|
|
+ 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 ''
|
|
|
+ },
|
|
|
// 初始化数据
|
|
|
initData() {
|
|
|
this.getAllUnitList()
|