diff --git a/src/components/jero/JUpload.vue b/src/components/jero/JUpload.vue index 81a465b5..cc16a00e 100644 --- a/src/components/jero/JUpload.vue +++ b/src/components/jero/JUpload.vue @@ -32,6 +32,12 @@ + +
+
+ +
+
@@ -74,7 +80,9 @@ export default { fileList: [], newFileList: [], uploadGoOn: true, - fileTypes: this.fileType + fileTypes: this.fileType, + image: false, + imageUrl: null } }, props: { diff --git a/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue b/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue index 2c2d618f..f4a0f314 100644 --- a/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue +++ b/src/views/standardRegulationLibrary/commonPage/StandardDetailPage.vue @@ -26,7 +26,26 @@
- {{ detailData[needDictFieldList.includes(formItem.fieldShowType) ? formItem.dbFieldName + '_dictText' : formItem.dbFieldName] }} + + {{ detailData[needDictFieldList.includes(formItem.fieldShowType) ? formItem.dbFieldName + '_dictText' : formItem.dbFieldName] + }} +
+
+
+ +
{{ file.fileName }}
+
+ + {{ $t('download') + }} + + + + + + +
+
@@ -35,18 +54,23 @@
{{ formItem.dbFieldTxt }} - + {{ $t('standardRegulationLibrary.standardResolutionSheet') }}
-
+
{{ file.fileName }}
- {{ $t('download') }} + {{ $t('download') }} @@ -59,6 +83,12 @@
+
+
+ +
+
+ @@ -78,6 +108,12 @@ import UpdateRecordModal from './modules/UpdateRecordModal.vue' import SubmitQuestionModal from './modules/SubmitQuestionModal.vue' import UserSelectModal from '../../../components/selection/UserSelectModal.vue' import StandardResolutionSheetModal from './modules/StandardResolutionSheetModal.vue' +import { getFileInfo } from '../../../api/api.js' +import Vue from 'vue' +import { ACCESS_TOKEN } from '../../../store/mutation-types.js' +import { downloadFile, getFileAccessHttpUrl } from '../../../api/manage.js' +import { previewPdf } from '../../../utils/previewPdf.js' +import { Base64 } from 'js-base64' // 国内标准权限 const DomesticStandardPermission = { @@ -95,6 +131,9 @@ const DomesticApi = { getDetailData: getDomesticStandardDetail // 获取详情数据 } +const FILE_TYPE_IMGS = ['jpg', 'jpeg', 'png', 'raw'] +const FILE_TYPE_PDF = 'pdf' + export default { name: 'StandardDetailPage', components: { UpdateRecordModal, SubmitQuestionModal, UserSelectModal, StandardResolutionSheetModal }, @@ -104,20 +143,13 @@ export default { partList: [], // 页面模块列表 form: {}, // 页面字段 // 页面数据 - detailData: { - // 修改单 - modification_list: [], - // 报批稿 - draft_for_review: [], - // 送审稿 - draft_for_approval: [], - // 征求意见稿 - draft_for_comment: [], - // 草案 - draft: [] - }, + detailData: {}, + // 文件的字段 + fileField: ['associated_file', 'modification_list', 'draft_for_review', 'draft_for_approval', 'draft_for_comment', 'draft'], // 需要数据字段翻译的属性类型 - needDictFieldList: [FieldType.USER_SINGLE.value, FieldType.ORGAN_SINGLE.value, FieldType.STANDARD_MORE.value, FieldType.ORGAN_MORE.value, FieldType.OPTION_SINGLE.value, FieldType.OPTION_MORE.value, FieldType.TREE.value] + needDictFieldList: [FieldType.USER_SINGLE.value, FieldType.ORGAN_SINGLE.value, FieldType.STANDARD_MORE.value, FieldType.ORGAN_MORE.value, FieldType.OPTION_SINGLE.value, FieldType.OPTION_MORE.value, FieldType.TREE.value], + image: false, + imageUrl: null } }, computed: { @@ -160,7 +192,7 @@ export default { * 获取页面字段 */ initForm () { - this.operateApiFunc.getFormFunc().then(res => { + this.operateApiFunc.getFormFunc({ type: 1 }).then(res => { if (res.success) { const data = res.result || {} this.partList = Object.keys(data) @@ -173,9 +205,23 @@ export default { // 获取数据 initDetailData () { this.loading = true - this.operateApiFunc.getDetailData({ id: this.$route.query.id }).then(res => { + this.operateApiFunc.getDetailData({ id: this.$route.query.id, type: 1 }).then(res => { if (res.success) { this.detailData = Object.assign({}, res.result || {}) + this.fileField.forEach(item => { + if (this.detailData[item]) { + const fileList = this.detailData[item].split(',') + const fileInfoList = [] + fileList.forEach(async id => { + const fileInfo = await this.getFileInfo(id) + if (fileInfo) { + fileInfoList.push(fileInfo) + } + }) + this.$set(this.detailData, item + 'List', fileInfoList) + } + }) + console.log(this.detailData) } else { this.$message.warn(res.message) } @@ -183,6 +229,18 @@ export default { this.loading = false }) }, + getFileInfo (fileId) { + return new Promise(resolve => { + let fileInfo + getFileInfo({ id: fileId }).then(res => { + if (res.success) { + fileInfo = res.result + } + }).finally(() => { + resolve(fileInfo) + }) + }) + }, /** * 更新记录 */ @@ -227,11 +285,63 @@ export default { */ previewStandardResolutionSheet () { this.$refs.standardResolutionSheetModal.open() + }, + handlePreview (file) { + if (!file || !file.url) { + return + } + // 截取文件后缀名 + const fileSuffix = file.fileName ? file.fileName.split('.')[file.fileName.split('.').length - 1] : '' + const canPreview = FILE_TYPE_IMGS.some(tt => fileSuffix.toLowerCase() === tt) || fileSuffix.toLowerCase() === FILE_TYPE_PDF + // 判断是否为可预览格式的文件 + if (!canPreview) { + this.$message.loading('该文件类型不支持预览,正在为您准备下载...').then(() => { + this.handleDownload(file) + }) + return + } + const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/download/${file.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.fileName}` + // 图片预览,使用自己添加的组件 + if (canPreview && FILE_TYPE_IMGS.includes(fileSuffix.toLowerCase())) { + this.imageUrl = getFileAccessHttpUrl(file.id) + // 获取viewer实例 + const viewer = this.$el.querySelector('.image').$viewer + // 调用show方法进行显示预览图 + viewer.show() + // this.$refs.imagePreviewModal.open(file) + return + } + // pdf预览 + if (canPreview && FILE_TYPE_PDF.includes(fileSuffix)) { + const url = previewPdf(file.response.result.id) + window.open(url) + return + } + // 其余可预览文件仍使用KKFile进行预览 + const url = `${window._CONFIG.onlinePreviewDomainURL}?url=${encodeURIComponent(Base64.encode(fileFullUrl))}` + window.open(url) + }, + /** + * 单个文件的下载功能 + * @param file + */ + handleDownload (file) { + // 下载文件 + downloadFile(`/sys/common/download/${file.id}`, file.fileName) } } }