470 lines
15 KiB
Vue
470 lines
15 KiB
Vue
<template>
|
||
<a-card :bordered="false">
|
||
<div class="table-page-search-wrapper">
|
||
<search ref="searchRef" :flag="'1'" :url="url"/>
|
||
</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>
|
||
<!--
|
||
showAction是否有操作按钮
|
||
OperationList操作列表的list
|
||
onSelectChange 选中的id值
|
||
editTable再传操作按钮的同时把事件定义名称也传过去
|
||
-->
|
||
<table-data
|
||
ref="tableData"
|
||
:flag="'1'"
|
||
:operationList="operationList"
|
||
@editTable="editTable"
|
||
@deleteTable="deleteTable"
|
||
:url="url"
|
||
showAction
|
||
@collection="collection"
|
||
@subscribe="subscribe"
|
||
@onSelectChange="onSelectChange"
|
||
@detailClick="detailClick"
|
||
/>
|
||
</div>
|
||
<library-add-form
|
||
ref="addFormRef"
|
||
:url="url"
|
||
:flag="'1'"
|
||
/>
|
||
<libraryPush
|
||
:url="url"
|
||
ref="libraryPushRef"
|
||
@clearSelected="clearSelected"
|
||
/>
|
||
</a-card>
|
||
</template>
|
||
|
||
<script>
|
||
// 搜索组件
|
||
import Search from '@/components/customField/Search'
|
||
// 表格组件
|
||
import TableData from '@/components/customField/TableData'
|
||
// 新增、编辑组件
|
||
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 eventBus from '@/common/event'
|
||
|
||
export default {
|
||
name: 'DocumentLibrary',
|
||
components: { Search, TableData, LibraryPush, LibraryAddForm },
|
||
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', // 表格头部字段
|
||
getSearchList: 'document/bussDocumentLibraryEO/queryCondition', // 搜索字段
|
||
tableList: '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: '' // 下载导入模板
|
||
},
|
||
idList: []
|
||
}
|
||
},
|
||
computed: {
|
||
importExcelUrl () {
|
||
return `${window._CONFIG.domianURL}${this.url.importZipUrl}`
|
||
}
|
||
},
|
||
methods: {
|
||
// 新增
|
||
handleAdd () {
|
||
this.$refs.addFormRef.add()
|
||
},
|
||
// 批量删除
|
||
handleBatchDel () {
|
||
if (this.idList.length > 0) {
|
||
this.$confirm({
|
||
content: this.$t('confirmBatchDeletion'),
|
||
onOk: () => {
|
||
const idList = JSON.parse(JSON.stringify(this.idList))
|
||
this.verifyBind(idList.join(','), () => {
|
||
getAction(this.url.deleteBatch, { ids: idList.join(',') }).then((res) => {
|
||
if (res.success) {
|
||
this.$message.success(this.$t('operationSuccessful'))
|
||
this.idList = []
|
||
this.$refs.tableData.$emit('searchGetData')
|
||
} else {
|
||
this.$message.warning(this.$t('operationFailed'))
|
||
}
|
||
})
|
||
})
|
||
}
|
||
})
|
||
} else {
|
||
this.$message.warning(this.$t('selectLeastOne'))
|
||
}
|
||
},
|
||
// 验证传入的idList是否都可以删除,不明白具体为什么要判断??
|
||
verifyBind (idList, callBack) {
|
||
getAction(this.url.verifyBind, { ids: idList }).then((res) => {
|
||
if (res.success) {
|
||
callBack && callBack()
|
||
} else {
|
||
this.$message.warning(res.message)
|
||
}
|
||
})
|
||
},
|
||
// 推送
|
||
handleCompare () {
|
||
if (this.idList.length > 0) {
|
||
this.$nextTick(() => {
|
||
this.$refs.libraryPushRef.getPush(this.idList)
|
||
})
|
||
} else {
|
||
this.$message.warning(this.$t('selectLeastOne'))
|
||
}
|
||
},
|
||
// 编辑按钮
|
||
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('confirmCollection') : this.$t('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('confirmSubscribe') : this.$t('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'))
|
||
}
|
||
})
|
||
}
|
||
})
|
||
},
|
||
// 选中的id
|
||
onSelectChange (value) {
|
||
this.idList = value
|
||
},
|
||
// 处理列表中的点击事件
|
||
detailClick (item) {
|
||
const newUrl = this.$router.resolve({
|
||
path: '/documentManage/library/detail',
|
||
query: item
|
||
})
|
||
window.open(newUrl.href, '_blank')
|
||
},
|
||
// 清楚表格选中
|
||
clearSelected () {
|
||
this.idList = []
|
||
},
|
||
// 下载模板
|
||
downTemplate (fileName) {
|
||
if (!fileName || typeof fileName !== 'string') {
|
||
fileName = '模板文件'
|
||
}
|
||
downloadFile(this.url.downTemplateUrl, fileName + '.xlsx')
|
||
},
|
||
deselect () {
|
||
this.$refs.tableDataRef.selectedRowKeys = []
|
||
this.idList = []
|
||
},
|
||
// 带文件导出
|
||
handleFileExport (fileName) {
|
||
if (this.idList.length > 0) {
|
||
if (!fileName || typeof fileName !== 'string') {
|
||
fileName = '导出文件'
|
||
}
|
||
const param = {
|
||
...this.$refs.searchRef.queryParam,
|
||
id: this.idList.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.idList.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
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
@import '~@assets/less/common.less';
|
||
</style>
|