修改文件导入
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user