Files
laws_weilai/jero-web/src/components/ImportFile/index.vue
T

165 lines
4.6 KiB
Java

<template>
<div>
<a-upload name="file" :showUploadList="false"
class="upload-text"
:multiple="false" :headers="tokenHeader"
:action="importUrl"
@change="handleImport"
:accept="accept">
<a-icon type="import" :rotate="270"/>
{{$t('import')}}
</a-upload>
</div>
</template>
<script>
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import eventBUs from '../../common/event'
export default {
name: 'index',
props: {
url: {
type: Object,
default: {}
},
//判断当前文档库还是其余的页面
isTrue: {
type: Boolean,
default: false
},
accept: {
type: String,
default: ''
},
projectId: {
type: String,
default: ''
},
dummyInventoryBaseId: {
type: String,
default: ''
}
},
data() {
return {
tokenHeader: { 'X-Access-Token': Vue.ls.get(ACCESS_TOKEN) },
cut: ''
}
},
computed: {
importUrl() {
if (this.projectId) {
return window._CONFIG['domianURL'] + '/' + this.url.importZipUrl + '?cut=' + this.cut + '&projectId=' + this.projectId
} else if (this.dummyInventoryBaseId) {
return window._CONFIG['domianURL'] + '/' + this.url.importZipUrl + '?cut=' + this.cut + '&dummyInventoryBaseId=' + this.dummyInventoryBaseId
}
return window._CONFIG['domianURL'] + '/' + this.url.importZipUrl + '?cut=' + this.cut
}
},
mounted() {
let long = localStorage.getItem('language')
this.cut = ''
if (long && long == 'zh-cn') {
this.cut = 'cn'
} else if (long && long == 'en-us') {
this.cut = 'en'
}
},
methods: {
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
let { name } = info.file
let 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 {
if (this.isTrue) {
this.$emit('getList')
} else {
eventBUs.$emit('searchReset')
}
this.$message.success(info.file.response.message || `${info.file.name} 文件导入成功`)
}
this.spinning = false
} else {
let { message } = info.file.response
let { name } = info.file
let 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) {
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>
.upload-text .ant-upload {
font-size: 14px !important;
font-weight: 400 !important;
color: #040B29 !important;
}
</style>