修改文件导入

This commit is contained in:
qq787203167
2022-02-25 11:57:29 +08:00
parent d7621fcdc7
commit d29e4ce963
2 changed files with 107 additions and 5 deletions
@@ -0,0 +1,98 @@
<template>
<div>
<a-upload name="file" :showUploadList="false"
:multiple="false" :headers="tokenHeader"
:action="url.importZipUrl"
@change="handleImportZip"
accept=".zip">
<a-icon type="import" :rotate="270"/>
导入
</a-upload>
</div>
</template>
<script>
import Vue from 'vue'
import { ACCESS_TOKEN } from "@/store/mutation-types"
export default {
name: 'index',
props:{
url: {
type: Object,
default: {}
},
},
data(){
return{
tokenHeader: {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)},
}
},
mounted() {
},
methods:{
handleImportZip(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) {
// this.$message.success(`${info.file.name} 文件上传成功`);
if (info.file.response.code === 201) {
let { message, result: { msg,error, fileUrl, fileName } } = info.file.response
let href = window._CONFIG['domianURL'] + fileUrl
let content = []
for (let i = 0; i < error.length; i++) {
content.push(<div>{error[i]}</div>)
}
this.$warning({
title: message,
content: (
<div>
<span>{msg}</span><br/>
{content}
</div>
)
})
} else {
this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
}
this.loadData()
this.spinning = false
} else {
this.$message.error(`${info.file.name} ${info.file.response.message}`);
this.spinning = false
}
} else if (info.file.status === 'error') {
if (info.file.response.status === 500) {
let data = info.file.response
const token = Vue.ls.get(ACCESS_TOKEN)
if (token && data.message.includes("Token失效")) {
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(`文件上传失败: ${info.file.msg} `);
this.spinning = false
}
}
},
},
}
</script>
<style scoped>
</style>
@@ -24,9 +24,8 @@
<a-icon type="download"/>
模板下载
</div>
<div @click="handleImport" class="operator-text">
<a-icon type="import" :rotate="270"/>
导入
<div class="operator-text">
<ImportFile :url="url"/>
</div>
<div @click="handleAdd" class="operator-text">
<a-icon type="plus"/>
@@ -74,14 +73,17 @@
import libraryPush from '@/components/libraryPush/index'
import { getAction, postAction, deleteAction, downloadFile } from '@/api/manage'
import eventBUs from '../../../common/event'
import { ACCESS_TOKEN } from "@/store/mutation-types"
import ImportFile from '@/components/ImportFile/index'
import Vue from 'vue'
export default {
name: 'docLibrary',
components: {
search,
addForm,
tableData,
libraryPush
libraryPush,
ImportFile
},
data() {
return {
@@ -105,6 +107,7 @@
],
selectedRowKeys: [],
loading: false,
tokenHeader: {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)},
//url传参严格按照当前命名
url: {
tableHeader: 'document/bussDocumentLibraryEO/getHeader', //表格头部字段
@@ -116,6 +119,7 @@
getDocumentInfo: 'document/bussDocumentLibraryEO/getDocumentInfoById', //查看
deleteBatch: 'document/bussDocumentLibraryEO/deleteBatch', //删除
pullMessage:'document/bussDocumentLibraryEO/pullMessage',//推送
importZipUrl:'document/bussDocumentLibraryEO/importZip',//导入
},
idList: []
}