一般检索 高级检索 点击标题直接预览最新文件

This commit is contained in:
Xia Zekun
2024-03-28 10:30:20 +08:00
committed by fengchenchen
parent 7b0396e065
commit c7bd6afe3e
2 changed files with 265 additions and 4 deletions
+123 -2
View File
@@ -140,7 +140,7 @@
<template v-slot:toDetail="{text, record}">
<a-tooltip overlay-class-name="tooltip-style">
<template slot="title">{{ text || text === 0 ? text : global.emptyLine }}</template>
<a v-if="text" class="link-a" @click="handleGoDetail(record)">{{ text }}</a>
<a v-if="text" class="link-a" @click="filePreview(record)">{{ text }}</a>
<div v-else class="table-text">{{ global.emptyLine }}</div>
</a-tooltip>
</template>
@@ -155,7 +155,7 @@
import { filterObj } from '@/utils/util'
import { StandardSource, FieldType, EnterpriseStandardStatus, StandardStatus } from '@/enums/commonEnums'
import { getAction } from '@/api/manage'
import { getFormDictTreeList, queryDepartTreeList } from '@/api/api'
import { getFormDictTreeList, queryDepartTreeList, getFileInfo } from '@/api/api'
import {
getDomesticStandardList,
getOverseasStandardList,
@@ -165,6 +165,17 @@ import {
getEnterStandardQuery
} from '@/api/dashboard'
import JTable from '@/components/jero/JTable'
import {
getDomesticStandardFormModal,
getDomesticStandardDetail,
getOverseasStandardForm,
getOverseasStandardDocumentInfo
} from '../../../api/standardRegulationLibraryApi'
import { getEnterpriseStandardAddForm, getEnterpriseStandardInfoById } from '../../../api/enterpriseStandardLibraryApi'
import Vue from 'vue'
import { ACCESS_TOKEN } from '../../../store/mutation-types'
import { previewPdf } from '../../../utils/previewPdf'
import { kkFilePreview } from '../../../utils/kkFilePreview'
export default {
name: 'AdvancedSearch',
@@ -244,6 +255,8 @@ export default {
showSizeChanger: true,
total: 0
},
getFormFunc: getDomesticStandardFormModal,
getDocumentInfoFunc: getDomesticStandardDetail,
// 国标和外标的默认标准状态
defaultStandardStatus: `${StandardStatus.CURRENTLY_EFFECTIVE.value},${StandardStatus.BE_IMPLEMENTED_SOON.value},${StandardStatus.RELEASE.value}`,
// 企标的默认标准状态
@@ -257,12 +270,18 @@ export default {
if (val === '1') {
this.getQueryConditionFunc = getDomesticStandardQuery
this.getDataListFunc = getDomesticStandardList
this.getFormFunc = getDomesticStandardFormModal
this.getDocumentInfoFunc = getDomesticStandardDetail
} else if (val === '2') {
this.getQueryConditionFunc = getOverseasStandardQuery
this.getDataListFunc = getOverseasStandardList
this.getFormFunc = getOverseasStandardForm
this.getDocumentInfoFunc = getOverseasStandardDocumentInfo
} else if (val === '3') {
this.getQueryConditionFunc = getEnterStandardQuery
this.getDataListFunc = getEnterStandardList
this.getFormFunc = getEnterpriseStandardAddForm
this.getDocumentInfoFunc = getEnterpriseStandardInfoById
}
this.getSearch()
// this.loadData(1)
@@ -300,6 +319,108 @@ export default {
}
})
},
/**
* 按顺序打开最新的pdf或word
*/
async filePreview (record) {
console.log('filePreview', record)
// 获取并处理过程稿件数据
let res = await this.getFormFunc({ type: 1 })
if (!res.success) {
this.$message.warn(res.message)
console.log('getFormFunc error:', res)
return
}
console.log('res.result', res.result)
const data = res.result || {}
const form = data
const partList = Object.keys(data)
let part
const partZh = '过程稿件'
const partEn = 'Process Manuscript'
if (partList.includes(partEn))part = partEn
if (partList.includes(partZh))part = partZh
console.log('part', part)
const processManuscript = form[part]
console.log('过程稿件', processManuscript)
// 获取并处理详情数据
res = await this.getDocumentInfoFunc({ id: record.id, type: 1 })
if (!res.success) {
this.$message.warn(res.message)
console.log('getDocumentInfoFunc error:', res)
return
}
const detailData = Object.assign({}, res.result || {})
console.log('detailData', detailData)
// 选择合适的文件
let file = null
const pdfFileList = []
const docFileList = []
let newestFileList = []
// 按照过程稿件顺序寻找文件
for (const formItem of processManuscript) {
const keyId = formItem.dbFieldName
const keyName = formItem.dbFieldName + '_dictText'
if (!detailData[keyId]) continue
const idArray = detailData[keyId].split(',')
const nameArray = detailData[keyName].split(',')
// 每个过程中可能有多个文件
for (let i = 0; i < idArray.length; i++) {
const id = idArray[i]
const name = nameArray[i]
var suffix = name.substring(name.lastIndexOf('.') + 1).toLowerCase()
if (suffix === 'pdf') {
pdfFileList.push({ id, name, suffix })
}
if (suffix === 'doc' || suffix === 'docx') {
docFileList.push({ id, name, suffix })
}
}
// 一旦一个过程中找到pdf或者doc,就可以退出
if (pdfFileList.length > 0 || docFileList.length > 0) {
break
}
}
newestFileList = pdfFileList // 默认从pdf里选最新的文件
if (pdfFileList.length === 0)newestFileList = docFileList // 如果没有pdf文件,就从doc文件里选
file = await this.selectNewestFile(newestFileList)
if (file === null) { // 没有找到文件就退出
console.log('没有找到符合要求的文件!')
this.$message.error('该标准暂无预览文件,请联系标准管理员。')
return
}
console.log('seletedFile', file)
// 预览选择的文件
const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}`
console.log(fileFullUrl)
if (file.suffix === 'pdf') { // pdf预览
const url = previewPdf(file.id)
window.open(url)
return
}
kkFilePreview(fileFullUrl)// 其余可预览文件仍使用KKFile进行预览
},
/**
* 从文件列表里选择最新文件
* @param fileList
*/
async selectNewestFile (fileList) {
if (!fileList || fileList.length === 0) return null
if (fileList.length === 1) return fileList[0]
const newFileList = []
// 获取时间信息
for (const file of fileList) {
const res = await getFileInfo(file)
newFileList.push({ ...file, ...res.result })
}
// 排序取出最新
newFileList.sort((a, b) => b.id - a.id) // 日期只精确到天,用id更能区分
console.log('newFileList', newFileList)
return newFileList[0]
},
// 标准类型改变
standardTypeChange (value) {
this.currStandardType = value
+142 -2
View File
@@ -80,7 +80,7 @@
<template #title>
<span v-html="item.title"></span>
</template>
<p class="result-title" v-html="item.title" @click="goDetail(item)"></p>
<p class="result-title" v-html="item.title" @click="filePreviewAll(item)"></p>
</a-tooltip>
<div class="result-source-wrapper">
<p class="result-source">{{ resourceTypeOptions.find(i => i.key === item.resourceType).label }}</p>
@@ -135,6 +135,18 @@ import {
import { isHasPermission } from '@/utils/hasPermission'
import { mapGetters } from 'vuex'
import { StandardStatus } from '@/enums/commonEnums'
import {
getDomesticStandardFormModal,
getDomesticStandardDetail,
getOverseasStandardForm,
getOverseasStandardDocumentInfo
} from '../../../api/standardRegulationLibraryApi'
import { getEnterpriseStandardAddForm, getEnterpriseStandardInfoById } from '../../../api/enterpriseStandardLibraryApi'
import Vue from 'vue'
import { previewPdf } from '../../../utils/previewPdf'
import { kkFilePreview } from '../../../utils/kkFilePreview'
import { ACCESS_TOKEN } from '../../../store/mutation-types'
import { getFileInfo } from '../../../api/api'
export default {
name: 'GeneralSearch',
@@ -195,7 +207,9 @@ export default {
showQuickJumper: true,
showSizeChanger: true
},
StandardStatus: StandardStatus
StandardStatus: StandardStatus,
getFormFunc: getDomesticStandardFormModal,
getDocumentInfoFunc: getDomesticStandardDetail
}
},
mounted () {
@@ -473,6 +487,132 @@ export default {
}
})
},
// 根据类型,选择调用的函数
adjustFunc (type) {
switch (type) {
case '1':
this.getFormFunc = getDomesticStandardFormModal
this.getDocumentInfoFunc = getDomesticStandardDetail
break
case '2':
this.getFormFunc = getOverseasStandardForm
this.getDocumentInfoFunc = getOverseasStandardDocumentInfo
break
case '3':
this.getFormFunc = getEnterpriseStandardAddForm
this.getDocumentInfoFunc = getEnterpriseStandardInfoById
break
}
},
filePreviewAll (record) {
if (record.resourceType === '4') {
this.goDetail(record)
} else {
this.filePreview13(record)
}
},
/**
* 按顺序打开最新的pdf或word
*/
async filePreview13 (record) {
console.log('filePreview', record)
// 获取并处理过程稿件数据
let res = await this.getFormFunc({ type: 1 })
if (!res.success) {
this.$message.warn(res.message)
console.log('getFormFunc error:', res)
return
}
console.log('res.result', res.result)
const data = res.result || {}
const form = data
const partList = Object.keys(data)
let part
const partZh = '过程稿件'
const partEn = 'Process Manuscript'
if (partList.includes(partEn))part = partEn
if (partList.includes(partZh))part = partZh
console.log('part', part)
const processManuscript = form[part]
console.log('过程稿件', processManuscript)
// 获取并处理详情数据
res = await this.getDocumentInfoFunc({ id: record.id, type: 1 })
if (!res.success) {
this.$message.warn(res.message)
console.log('getDocumentInfoFunc error:', res)
return
}
const detailData = Object.assign({}, res.result || {})
console.log('detailData', detailData)
// 选择合适的文件
let file = null
const pdfFileList = []
const docFileList = []
let newestFileList = []
// 按照过程稿件顺序寻找文件
for (const formItem of processManuscript) {
const keyId = formItem.dbFieldName
const keyName = formItem.dbFieldName + '_dictText'
if (!detailData[keyId]) continue
const idArray = detailData[keyId].split(',')
const nameArray = detailData[keyName].split(',')
// 每个过程中可能有多个文件
for (let i = 0; i < idArray.length; i++) {
const id = idArray[i]
const name = nameArray[i]
var suffix = name.substring(name.lastIndexOf('.') + 1).toLowerCase()
if (suffix === 'pdf') {
pdfFileList.push({ id, name, suffix })
}
if (suffix === 'doc' || suffix === 'docx') {
docFileList.push({ id, name, suffix })
}
}
// 一旦一个过程中找到pdf或者doc,就可以退出
if (pdfFileList.length > 0 || docFileList.length > 0) {
break
}
}
newestFileList = pdfFileList // 默认从pdf里选最新的文件
if (pdfFileList.length === 0)newestFileList = docFileList // 如果没有pdf文件,就从doc文件里选
file = await this.selectNewestFile(newestFileList)
if (file === null) { // 没有找到文件就退出
console.log('没有找到符合要求的文件!')
this.$message.error('该标准暂无预览文件,请联系标准管理员。')
return
}
console.log('seletedFile', file)
// 预览选择的文件
const fileFullUrl = `${window._CONFIG.domianWebSocketURL}/sys/common/view/${file.id}?at=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}`
console.log(fileFullUrl)
if (file.suffix === 'pdf') { // pdf预览
const url = previewPdf(file.id)
window.open(url)
return
}
kkFilePreview(fileFullUrl)// 其余可预览文件仍使用KKFile进行预览
},
/**
* 从文件列表里选择最新文件
* @param fileList
*/
async selectNewestFile (fileList) {
if (!fileList || fileList.length === 0) return null
if (fileList.length === 1) return fileList[0]
const newFileList = []
// 获取时间信息
for (const file of fileList) {
const res = await getFileInfo(file)
newFileList.push({ ...file, ...res.result })
}
// 排序取出最新
newFileList.sort((a, b) => b.id - a.id) // 日期只精确到天,用id更能区分
console.log('newFileList', newFileList)
return newFileList[0]
},
// 检索弹框点击历史查数据
historySearch (searchObj) {
console.log('--------historySearch--------', searchObj)