Files
laws-sinotruk-client/src/views/documentManage/DocumentLibrary.vue
T

535 lines
18 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<a-card :bordered="false">
<div class="table-page-search-wrapper">
<search ref="searchRef" :flag="'1'" :url="url" @search="searchQuery" @reset="searchReset" />
</div>
<div class="table-operator">
<div class="operator-text" @click="handleBatchDel">
<a-icon type="delete" />
{{ $t('batchDelete') }}
</div>
<div class="operator-text" @click="handleExportXls">
<a-icon type="export" />
{{ $t('dataExport') }}
</div>
<div class="operator-text" @click="handleFileExport">
<a-icon type="mail" />
{{ $t('exportWithFile') }}
</div>
<div class="operator-text" @click="handleCompare">
<a-icon type="share-alt" />
{{ $t('share') }}
</div>
<div class="operator-text" @click="downTemplate">
<a-icon type="download" />
{{ $t('templateDownload') }}
</div>
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
@change="handleImport">
<div class="operator-text">
<a-icon type="import" />
{{ $t('import') }}
</div>
</a-upload>
<div class="operator-text" @click="handleAdd">
<a-icon type="plus" />
{{ $t('newlyAdded') }}
</div>
</div>
<div>
<j-table
v-if="columns && columns.length > 0"
:columns="columns"
:dataSource="dataSource"
:can-drag="true"
rowKey="id"
:row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
:pagination="ipagination"
:scroll="{x: '100%'}"
@change="tableOnChange">
<!-- 在混入里已经过滤过没有权限的按钮了 -->
<template v-slot:operation="{text, record}">
<a v-for="(operation, index) in operationList.slice(0, operateMaxNum)" :key="index" @click="operationClick(operation,record)">
<template v-if="operation.text === $t('docLibrary.cancelCollection')">
{{ !record.collectFlag || record.collectFlag === '0' ? $t('docLibrary.collection') : $t('docLibrary.cancelCollection')
}}
</template>
<template v-else-if="operation.text === $t('docLibrary.cancelSubscribe')">
{{ !record.subscribeFlag || record.subscribeFlag === '0' ? $t('docLibrary.subscribe') : $t('docLibrary.cancelSubscribe')
}}
</template>
<template v-else>
{{ operation.text }}
</template>
</a>
<a-divider v-if="operationList.length >= operateMaxNum" type="vertical" />
<a-dropdown v-if="operationList.length >= operateMaxNum">
<a class="ant-dropdown-link">
{{ $t('more') }} <a-icon type="down"/>
</a>
<a-menu slot="overlay">
<a-menu-item v-for="(operation, index) in operationList.slice(operateMaxNum)" :key="index">
<a @click="operationClick(operation,record)">
<span v-if="operation.text === $t('docLibrary.cancelCollection')" class="text">
{{ !record.collectFlag || record.collectFlag === '0' ? $t('docLibrary.collection') : $t('docLibrary.cancelCollection')
}}
</span>
<span v-else-if="operation.text === $t('docLibrary.cancelSubscribe')" class="text">
{{ !record.subscribeFlag || record.subscribeFlag === '0' ? $t('docLibrary.subscribe') : $t('docLibrary.cancelSubscribe')
}}
</span>
<span v-else class="text">
{{ operation.text }}
</span>
</a>
</a-menu-item>
</a-menu>
</a-dropdown>
</template>
<!-- 详情-->
<template slot="detailClick" slot-scope="{text, record}">
<a-tooltip overlay-class-name="tooltip-style">
<template slot="title">{{ text || text === 0 ? text : global.emptyLine }}</template>
<a class="table-text textName" @click="detailClick(record)" v-if="text || text === 0">{{ text }}</a>
<div class="table-text" v-else>{{ global.emptyLine }}</div>
</a-tooltip>
</template>
</j-table>
</div>
<library-add-form
ref="addFormRef"
:url="url"
:flag="'1'"
@ok="libraryAddFormOk"
/>
<libraryPush
:url="url"
ref="libraryPushRef"
@clearSelected="clearSelected"
/>
</a-card>
</template>
<script>
// 搜索组件
import Search from '@/components/customField/Search'
// 新增、编辑组件
import LibraryAddForm from './modules/LibraryAddForm'
// 推送组件
import LibraryPush from './modules/LibraryPush'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { downFile, downloadFile, getAction } from '@/api/manage'
import Modal from 'ant-design-vue'
import store from '@/store'
import JTable from '@comp/jero/JTable.vue'
import { ConfigurableTableMixin } from '@/mixins/ConfigurableTableMixin'
export default {
name: 'DocumentLibrary',
components: { JTable, Search, LibraryPush, LibraryAddForm },
mixins: [ConfigurableTableMixin],
data () {
return {
operationList: [
{
text: this.$t('docLibrary.cancelCollection'),
clickEvent: 'collection',
has: 'document:addCollect'
},
{
text: this.$t('docLibrary.cancelSubscribe'),
clickEvent: 'subscribe',
has: 'document:addSubscribe'
},
{
text: this.$t('edit'),
clickEvent: 'editTable',
has: 'document:updateInfo'
},
{
text: this.$t('delete'),
clickEvent: 'deleteTable',
has: 'document:deleteBatch'
}
],
selectedRowKeys: [],
loading: false,
tokenHeader: { 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) },
// url传参严格按照当前命名
url: {
// tableHeader: '/document/bussDocumentLibraryEO/getHeader', // 表格头部字段
tableHeader: '', // 表格头部字段
getSearchList: '/document/bussDocumentLibraryEO/queryCondition', // 搜索字段
list: 'document/bussDocumentLibraryEO/queryPageInfo', // 表格数据
getAddForm: 'document/bussDocumentLibraryEO/getAddForm', // 表单的字段
addInfo: 'document/bussDocumentLibraryEO/addInfo', // 新增
updateInfo: 'document/bussDocumentLibraryEO/updateInfo', // 编辑
getDocumentInfo: 'document/bussDocumentLibraryEO/getDocumentInfoById', // 查看
deleteBatch: 'document/bussDocumentLibraryEO/deleteBatch', // 删除
pullMessage: 'document/bussDocumentLibraryEO/pullMessage', // 推送
importZipUrl: '/document/bussDocumentLibraryEO/importZip', // 导入
verifyBind: '/document/bussDocumentLibraryEO/verifyBind', // 验证当前的数据是否可以删除
getPage: '/document/phasedImplementationDetailsEO/page',
exportXlsUrl: '', // 导出
exportZipUrl: '', // 带文件导出
downTemplateUrl: '' // 下载导入模板
},
showAction: true, // 是否显示操作列
dataSource: [
{
collectFlag: '0',
id: 'fd045f5c5d734087a884a63664ee91f1',
issue_time: '',
region: '',
serial_number: '0621001编号',
state: '现行',
subscribeFlag: '0',
technology_territory: '',
title: '0621001标题',
title_en: '0621001Title'
}
]
}
},
computed: {
importExcelUrl () {
return `${window._CONFIG.domianURL}${this.url.importZipUrl}`
}
},
methods: {
// 新增
handleAdd () {
this.$refs.addFormRef.add()
},
// 批量删除
handleBatchDel () {
if (this.selectedRowKeys.length > 0) {
this.$confirm({
content: this.$t('confirmBatchDeletion'),
onOk: () => {
const selectedRowKeys = JSON.parse(JSON.stringify(this.selectedRowKeys))
this.verifyBind(selectedRowKeys.join(','), () => {
getAction(this.url.deleteBatch, { ids: selectedRowKeys.join(',') }).then((res) => {
if (res.success) {
this.$message.success(this.$t('operationSuccessful'))
this.selectedRowKeys = []
this.$refs.tableData.$emit('searchGetData')
} else {
this.$message.warning(this.$t('operationFailed'))
}
})
})
}
})
} else {
this.$message.warning(this.$t('selectLeastOne'))
}
},
// 验证传入的idList是否都可以删除,不明白具体为什么要判断??
verifyBind (selectedRowKeys, callBack) {
getAction(this.url.verifyBind, { ids: selectedRowKeys }).then((res) => {
if (res.success) {
callBack && callBack()
} else {
this.$message.warning(res.message)
}
})
},
// 推送
handleCompare () {
if (this.selectedRowKeys.length > 0) {
this.$nextTick(() => {
this.$refs.libraryPushRef.getPush(this.selectedRowKeys)
})
} else {
this.$message.warning(this.$t('selectLeastOne'))
}
},
// 表格的操作按钮点击
operationClick (operation, record) {
if (this[operation.clickEvent]) {
this[operation.clickEvent](record)
}
},
// 编辑按钮
editTable (val) {
this.$refs.addFormRef.edit(val)
},
// 删除按钮
deleteTable (val) {
this.$confirm({
content: this.$t('ConfirmDelete'),
onOk: () => {
this.verifyBind(val.id, () => {
getAction(this.url.deleteBatch, { ids: val.id }).then((res) => {
if (res.success) {
this.$message.success(this.$t('operationSuccessful'))
this.$refs.tableData.$emit('searchGetData')
} else {
this.$message.warning(this.$t('operationFailed'))
}
})
})
}
})
},
// 收藏按钮
collection (val) {
this.$confirm({
content: val.collectFlag === '0' || !val.collectFlag ? this.$t('docLibrary.confirmCollection') : this.$t('docLibrary.cancelConfirmCollection'),
onOk: () => {
let url = ''
if (val.collectFlag === '0' || !val.collectFlag) {
url = 'document/bussDocumentLibraryEO/addCollect'
} else {
url = 'document/bussDocumentLibraryEO/cancelCollect'
}
getAction(url, { id: val.id }).then((res) => {
if (res.success) {
this.$message.success(this.$t('operationSuccessful'))
this.$refs.tableData.$emit('searchGetData')
} else {
this.$message.warning(this.$t('operationFailed'))
}
})
}
})
},
// 订阅按钮
subscribe (val) {
this.$confirm({
content: val.subscribeFlag === '0' || !val.subscribeFlag ? this.$t('docLibrary.confirmSubscribe') : this.$t('docLibrary.cancelConfirmSubscribe'),
onOk: () => {
let url = ''
if (val.subscribeFlag === '0' || !val.subscribeFlag) {
url = 'document/bussDocumentLibraryEO/addSubscribe'
} else {
url = 'document/bussDocumentLibraryEO/cancelSubscribe'
}
getAction(url, { id: val.id }).then((res) => {
if (res.success) {
this.$message.success(this.$t('OperationSuccessful'))
this.$refs.tableData.$emit('searchGetData')
} else {
this.$message.warning(this.$t('operationFailed'))
}
})
}
})
},
// 处理列表中的点击事件
detailClick (item) {
const newUrl = this.$router.resolve({
path: '/documentManage/library/detail',
query: item
})
window.open(newUrl.href, '_blank')
},
// 清楚表格选中
clearSelected () {
this.selectedRowKeys = []
},
// 下载模板
downTemplate (fileName) {
if (!fileName || typeof fileName !== 'string') {
fileName = '模板文件'
}
downloadFile(this.url.downTemplateUrl, fileName + '.xlsx')
},
deselect () {
this.$refs.tableDataRef.selectedRowKeys = []
this.selectedRowKeys = []
},
// 带文件导出
handleFileExport (fileName) {
if (this.selectedRowKeys.length > 0) {
if (!fileName || typeof fileName !== 'string') {
fileName = '导出文件'
}
const param = {
...this.$refs.searchRef.queryParam,
id: this.selectedRowKeys.join(','),
flag: 'file'
}
console.log('导出参数', param)
// 加一个大的提示
const modalLoading = this.$info({
title: '提示',
content: <span>正在导出请稍候 <a-spin size="small" /></span>,
keyboard: false
})
// 把知道了这个按钮去掉
this.$nextTick(() => {
document.getElementsByClassName('ant-modal-confirm-btns')[0].style = 'display:none'
})
downFile(this.url.exportZipUrl, param).then((data) => {
if (!data) {
this.$message.warning('文件下载失败')
}
}).finally(() => {
// 销毁这个提示
modalLoading.destroy()
this.deselect()
})
} else {
this.$message.warning(this.$t('selectLeastOne'))
}
},
// 导出
handleExportXls (fileName) {
if (!fileName || typeof fileName !== 'string') {
fileName = '导出文件'
}
const param = {
...this.$refs.searchRef.queryParam,
id: this.selectedRowKeys.join(',')
}
console.log('导出参数', param)
// 加一个大的提示
const modalLoading = this.$info({
title: '提示',
content: <span>正在导出请稍候 <a-spin size="small" /></span>,
keyboard: false
})
// 把知道了这个按钮去掉
this.$nextTick(() => {
document.getElementsByClassName('ant-modal-confirm-btns')[0].style = 'display:none'
})
downFile(this.url.exportXlsUrl, param).then((data) => {
if (!data) {
this.$message.warning('文件下载失败')
return
}
if (typeof window.navigator.msSaveBlob !== 'undefined') {
window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
} else {
const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', fileName + '.xls')
document.body.appendChild(link)
link.click()
document.body.removeChild(link) // 下载完成移除元素
window.URL.revokeObjectURL(url) // 释放掉blob对象
}
}).finally(() => {
// 销毁这个提示
modalLoading.destroy()
this.deselect()
})
},
handleImport (info) {
this.spinning = true
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList)
}
if (info.file.status === 'done') {
if (info.file.response.success) {
if (info.file.response.code === 201) {
let { message } = info.file.response
const { name } = info.file
const content = []
if (message) {
message = message.split('</br>')
message.forEach(res => {
if (res) {
content.push(< div> {res} < /div>)
}
})
}
this.$warning({
title: name,
content: (
< div>
{content}
< /div>
)
})
} else {
this.$refs.tableData.$emit('searchGetData')
this.$message.success(this.$t('operationSuccessful'))
}
this.spinning = false
} else {
const data = info.file.response
const token = Vue.ls.get(ACCESS_TOKEN)
if ((token && data.message.includes('Token失效')) || (token && data.message.includes('token')) || (token && data.message.includes('用户不存在'))) {
this.spinning = false
Modal.error({
title: '登录已过期',
content: '很抱歉,登录已过期,请重新登录',
okText: '重新登录',
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
})
return
}
let { message } = info.file.response
const { name } = info.file
const content = []
if (message) {
message = message.split('</br>')
message.forEach(res => {
if (res) {
content.push(< div> {res} < /div>)
}
})
}
this.$warning({
title: name,
content: (
< div>
{content}
< /div>
)
})
this.spinning = false
}
} else if (info.file.status === 'error') {
if (info.file.response.status === 500) {
const data = info.file.response
const token = Vue.ls.get(ACCESS_TOKEN)
if ((token && data.message.includes('Token失效')) || (token && data.message.includes('token')) || (token && data.message.includes('用户不存在'))) {
Modal.error({
title: '登录已过期',
content: '很抱歉,登录已过期,请重新登录',
okText: '重新登录',
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
})
}
this.spinning = false
} else {
this.$message.error(this.$t('operationFailed'))
this.spinning = false
}
}
},
// 新增和编辑表单成功提交的回调
libraryAddFormOk () {
this.loadData()
}
}
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>