|
|
@@ -379,6 +379,7 @@
|
|
|
} from '@/api/taskCustomizedRelease.js'
|
|
|
import { dictMixin, regionMixin } from '@/mixins/useDict'
|
|
|
import { uploadFile } from '@/api/file'
|
|
|
+
|
|
|
export default {
|
|
|
components: { CostAuditTable, CostAuditDialog, TemplatePreviewEdit },
|
|
|
mixins: [dictMixin, regionMixin],
|
|
|
@@ -510,6 +511,34 @@
|
|
|
this.loadOpts()
|
|
|
},
|
|
|
methods: {
|
|
|
+ normalizeFileUrl(fileUrl) {
|
|
|
+ if (!fileUrl) return ''
|
|
|
+ const url = String(fileUrl).trim()
|
|
|
+ if (!url) return ''
|
|
|
+
|
|
|
+ // 已经是绝对地址
|
|
|
+ if (/^https?:\/\//i.test(url)) return url
|
|
|
+
|
|
|
+ // 相对地址:确保以 / 开头,避免拼接成 ...formapi/xxx 这种
|
|
|
+ const normalizedPath = url.startsWith('/') ? url : `/${url}`
|
|
|
+ return (window?.context?.form || '') + normalizedPath
|
|
|
+ },
|
|
|
+
|
|
|
+ // 根据URL推测文件扩展名
|
|
|
+ getFileExtFromUrl(url) {
|
|
|
+ try {
|
|
|
+ const clean = String(url || '')
|
|
|
+ .split('?')[0]
|
|
|
+ .split('#')[0]
|
|
|
+ const last = clean.substring(clean.lastIndexOf('/') + 1)
|
|
|
+ const idx = last.lastIndexOf('.')
|
|
|
+ if (idx > -1 && idx < last.length - 1) return last.substring(idx)
|
|
|
+ } catch (e) {
|
|
|
+ // ignore
|
|
|
+ }
|
|
|
+ return ''
|
|
|
+ },
|
|
|
+
|
|
|
// 查看监审文书
|
|
|
handleDocView(row) {
|
|
|
this.document = {
|
|
|
@@ -520,19 +549,11 @@
|
|
|
id: row.id,
|
|
|
}).then((res) => {
|
|
|
if (res.state) {
|
|
|
- // this.fileUrl = res.value || ''
|
|
|
this.handleViewScan(res.value || '')
|
|
|
} else {
|
|
|
this.$message.error('获取文件URL失败')
|
|
|
}
|
|
|
})
|
|
|
- // this.handleTemplateChange()
|
|
|
- // this.documentDialogVisible = true
|
|
|
- // getCostProjectDocumentFile({
|
|
|
- // id: row.id,
|
|
|
- // }).then((res) => {
|
|
|
- // this.costDocumentTemplateFiles = res.value || []
|
|
|
- // })
|
|
|
},
|
|
|
handleDocumentTypeClick(data) {
|
|
|
this.activeDocumentTypeId = data.id
|
|
|
@@ -810,16 +831,26 @@
|
|
|
|
|
|
// 第四步:检查上传结果
|
|
|
if (!uploadRes || !uploadRes.value) {
|
|
|
- // this.$message.error('文件上传失败!');
|
|
|
+ this.$message.error('文件上传失败!')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 第五步:文件上传成功后,再更新数据
|
|
|
const fileInfo = uploadRes.value
|
|
|
- // 创建更新数据对象
|
|
|
+
|
|
|
+ // 兼容:后端返回 savePath/url/path 等字段
|
|
|
+ const uploadedPath =
|
|
|
+ fileInfo?.savePath || fileInfo?.url || fileInfo?.path || ''
|
|
|
+
|
|
|
+ if (!uploadedPath) {
|
|
|
+ this.$message.error('文件上传成功,但未返回文件路径!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建更新数据对象:按传入type写入对应字段
|
|
|
const updateData = {
|
|
|
...row,
|
|
|
- scanDocumentUrl: fileInfo?.savePath, // 更新扫描件URL
|
|
|
+ [type || 'scanDocumentUrl']: uploadedPath,
|
|
|
}
|
|
|
|
|
|
// 第六步:调用更新API
|
|
|
@@ -829,37 +860,34 @@
|
|
|
this.$message.success('文件上传成功并更新数据!')
|
|
|
this.$emit('refresh', this.project.projectId) // 通知父组件刷新
|
|
|
} catch (error) {
|
|
|
- // 错误处理
|
|
|
console.log('操作失败:' + (error.message || '未知错误'))
|
|
|
- // this.$message.error('操作失败:' + (error.message || '未知错误'))
|
|
|
+ this.$message.error('操作失败:' + (error.message || '未知错误'))
|
|
|
} finally {
|
|
|
// 关闭遮罩层
|
|
|
- loading.close()
|
|
|
+ if (loading && typeof loading.close === 'function') loading.close()
|
|
|
}
|
|
|
}
|
|
|
// 触发文件选择
|
|
|
input.click()
|
|
|
},
|
|
|
+
|
|
|
// 查看扫描件
|
|
|
handleViewScan(fileUrl, type) {
|
|
|
- if (!fileUrl) {
|
|
|
+ const normalized = this.normalizeFileUrl(fileUrl)
|
|
|
+ if (!normalized) {
|
|
|
this.$message.error('暂无文件!')
|
|
|
return
|
|
|
}
|
|
|
- let _fileUrl = ''
|
|
|
- if (fileUrl.startsWith('http')) {
|
|
|
- _fileUrl = fileUrl
|
|
|
- } else {
|
|
|
- _fileUrl = window.context.form + fileUrl
|
|
|
- }
|
|
|
+
|
|
|
// 对文件URL进行Base64编码
|
|
|
- const encodedUrl = encodeURIComponent(Base64.encode(_fileUrl))
|
|
|
+ const encodedUrl = encodeURIComponent(Base64.encode(normalized))
|
|
|
|
|
|
// 构建 kkFileView 预览URL
|
|
|
// onlinePreview - 在线预览
|
|
|
// onlinePreview?type=pdf - 强制使用PDF模式预览
|
|
|
window.open(`${host}:8012/onlinePreview?url=${encodedUrl}`)
|
|
|
},
|
|
|
+
|
|
|
// 编辑文档
|
|
|
handleEditDocument(row) {
|
|
|
this.documentDialogVisible = true
|
|
|
@@ -907,7 +935,42 @@
|
|
|
},
|
|
|
|
|
|
// 下载文档
|
|
|
- handleDownloadDocument(row) {},
|
|
|
+ handleDownloadDocument(row) {
|
|
|
+ if (!row || !row.id) {
|
|
|
+ this.$message.error('缺少文书ID,无法下载!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ downDocument({ id: row.id })
|
|
|
+ .then((res) => {
|
|
|
+ if (!res || !res.state || !res.value) {
|
|
|
+ this.$message.error('获取下载地址失败!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const url = this.normalizeFileUrl(res.value)
|
|
|
+ if (!url) {
|
|
|
+ this.$message.error('获取下载地址失败!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const nameBase =
|
|
|
+ row.documentName || this.getDocumenType(row) || '电子文书'
|
|
|
+ const ext = this.getFileExtFromUrl(url)
|
|
|
+ const fileName = `${nameBase}${ext || ''}`
|
|
|
+
|
|
|
+ const a = document.createElement('a')
|
|
|
+ a.href = url
|
|
|
+ a.download = fileName
|
|
|
+ a.target = '_blank'
|
|
|
+ document.body.appendChild(a)
|
|
|
+ a.click()
|
|
|
+ document.body.removeChild(a)
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.$message.error('下载失败!')
|
|
|
+ })
|
|
|
+ },
|
|
|
},
|
|
|
}
|
|
|
</script>
|