260 lines
9.1 KiB
Java
260 lines
9.1 KiB
Java
<template>
|
|
<div>
|
|
<a-modal v-model="visible" :maskClosable="false" :footer="[]" :title="title">
|
|
<a-upload-dragger
|
|
:accept='accept'
|
|
:disabled="disabled"
|
|
class="ant-upload-list"
|
|
:class="{'uploadFile':isUploadFile}"
|
|
name="file"
|
|
:file-list="myfileList"
|
|
:multiple="multiple"
|
|
:action="uploadAction+'?state='+state+'&cut='+cut"
|
|
:headers="headers"
|
|
@preview="preview"
|
|
:before-upload="beforeUpload"
|
|
:remove='remove'
|
|
@change="handleChange">
|
|
<p v-if="!isUploadFile">
|
|
<a-icon class="action-upload" type="cloud-upload"/>
|
|
</p>
|
|
<p v-if="!isUploadFile" class="ant-upload-text" style="font-size: 14px;line-height: 30px">
|
|
{{this.$t('clickUpload')}}</p>
|
|
</a-upload-dragger>
|
|
</a-modal>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import Vue from 'vue'
|
|
import { ACCESS_TOKEN } from '@/store/mutation-types'
|
|
import { getAction, postAction, downFile, downloadFile } from '@/api/manage'
|
|
import { Base64 } from 'js-base64'
|
|
import { mapGetters } from 'vuex'
|
|
|
|
export default {
|
|
name: 'file',
|
|
props: ['disableds', 'disabled', 'thisFileUploadUrl','size' ,'acceptcode', 'readonly', 'thisFileType', 'isUploadFile', 'isMultiple', 'restrictUploads', 'Uploadable'],
|
|
data() {
|
|
return {
|
|
visible: false,
|
|
title: this.$t('clickUpload'),
|
|
uploadAction: window._CONFIG['domianURL'] + '/sys/common/upload',
|
|
state: undefined,
|
|
myuploadAction: window._CONFIG['domianURL'] + this.thisFileUploadUrl,
|
|
upDataList: [],
|
|
downLoadFileUrl: window._CONFIG['domianPreviewURL'] + '/sys/common/download',
|
|
fileList: [],
|
|
myfileList: [],
|
|
isLoding: false,
|
|
cut: '',
|
|
multiple: true,
|
|
accept: ''
|
|
}
|
|
},
|
|
created() {
|
|
const token = Vue.ls.get(ACCESS_TOKEN)
|
|
this.headers = { 'X-Access-Token': token }
|
|
this.containerId = 'container-ty-' + new Date().getTime()
|
|
},
|
|
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'
|
|
}
|
|
if (this.isMultiple) {
|
|
this.multiple = false
|
|
}
|
|
this.accept = this.restrictUploads ? this.Uploadable : '*.*'
|
|
// console.log(this.thisFileType,this.thisFileSize,this.thisFileUploadUrl);
|
|
},
|
|
methods: {
|
|
...mapGetters(['userInfo']),
|
|
perentHandleFunc(data) {
|
|
this.myfileList = data
|
|
if (data && data.length > 0) {
|
|
this.myfileList.forEach((res) => {
|
|
res.name = res.fileName
|
|
res.uid = res.id
|
|
})
|
|
} else {
|
|
this.myfileList = []
|
|
}
|
|
},
|
|
beforeUpload(file, fileList) {
|
|
// let thisFileType = this.thisFileType.replace(/\s+/g, "");
|
|
console.log(file)
|
|
this.fileTypeSatus = true
|
|
//根据格式拦截
|
|
if(this.acceptcode){
|
|
let fileNames = file.name.split('.')
|
|
let fileType = fileNames[fileNames.length - 1].toLocaleLowerCase()
|
|
let extList = this.acceptcode.split(',')
|
|
if (!extList.find((item) => item == fileType)) {
|
|
this.$message.error(this.$t('uploadOnly') + this.acceptcode + this.$t('type'))
|
|
return false
|
|
}
|
|
}
|
|
// 根据大小拦截
|
|
if(this.size){
|
|
const isLt2KB = file.size / 1024 /1024 < this.size
|
|
let name = file.name
|
|
if (!isLt2KB) {
|
|
this.$message.error(name + this.$t('uploadedfilelarger') + this.size + 'M')
|
|
return false
|
|
}
|
|
}
|
|
if (this.isMultiple) {
|
|
if ((this.myfileList && this.myfileList.length == 1) || this.myfileList && this.myfileList.length > 1) {
|
|
this.$message.warning(this.$t('onlyOnefileUploaded'))
|
|
return false
|
|
}
|
|
}
|
|
if (this.restrictUploads) {
|
|
let fileName = file.name
|
|
let index1 = fileName.lastIndexOf('.')
|
|
let index2 = fileName.length
|
|
let fileSuffix = fileName.substring(index1, index2)
|
|
fileSuffix = fileSuffix.toLowerCase()
|
|
if (this.Uploadable.includes(fileSuffix)) {
|
|
|
|
} else {
|
|
this.$message.warning(this.$t('uploadOnly') + this.Uploadable + this.$t('file'))
|
|
return false
|
|
}
|
|
}
|
|
//TODO 客户要求不拦截文件
|
|
// if(file.type){
|
|
// if (thisFileType.indexOf(file.type) != -1) {
|
|
// this.fileTypeSatus = true;
|
|
// }else{
|
|
// this.fileTypeSatus = false;
|
|
// }
|
|
// }else{
|
|
// if(file.name.slice(file.name.length - 3 , file.name.length) == 'rar'){
|
|
// this.fileTypeSatus = true
|
|
// }else if(file.type == 'application/x-zip-compressed'){
|
|
// this.fileTypeSatus = true
|
|
// }else{
|
|
// this.fileTypeSatus = false;
|
|
// }
|
|
// }
|
|
// }
|
|
// this.$message.destroy()
|
|
},
|
|
remove() {
|
|
this.fileTypeSatus = true
|
|
},
|
|
mypreview(item) {
|
|
let url = window._CONFIG['onlinePreviewDomainURL'] + '?url=' + encodeURIComponent(this.downLoadFileUrl + '/' + item.ext1)
|
|
window.open(url, '_blank')
|
|
},
|
|
handleChange(info) {
|
|
let { file } = info
|
|
const status = info.file.status
|
|
info.fileList.forEach((val, index) => {
|
|
if (val.response && !val.response.result) {
|
|
this.$message.error(val.response.message)
|
|
info.fileList.splice(index, 1)
|
|
}
|
|
})
|
|
if (status === 'error') {
|
|
this.$emit('uploadSuccess', this.fileList)
|
|
// this.$message.destroy()
|
|
this.$message.error(`${info.file.name}` + this.$t('FileUploadFailed'))
|
|
} else if (status === 'removed') {
|
|
this.myfileList = info.fileList
|
|
this.fileList = []
|
|
this.myfileList.forEach((res) => {
|
|
if (res.response) {
|
|
this.fileList.push(res.response.result)
|
|
} else {
|
|
this.fileList.push(res)
|
|
}
|
|
})
|
|
this.$emit('uploadSuccess', this.fileList)
|
|
if (this.myfileList.length > 0) {
|
|
// this.$message.destroy()
|
|
this.$message.success(`${info.file.name}` + this.$t('DeletedSuccessfully'))
|
|
}
|
|
} else if (status === 'done') {
|
|
this.fileList = []
|
|
this.myfileList = info.fileList
|
|
if (info.fileList.length > 20) {
|
|
info.fileList.splice(20)
|
|
this.myfileList = info.fileList
|
|
this.myfileList.forEach((res) => {
|
|
if (res.response) {
|
|
this.fileList.push(res.response.result)
|
|
} else {
|
|
this.fileList.push(res)
|
|
}
|
|
})
|
|
this.$emit('uploadSuccess', this.fileList)
|
|
// this.$message.destroy()
|
|
this.$message.error(this.$t('UploadMost'))
|
|
return
|
|
}
|
|
this.myfileList.forEach((res) => {
|
|
if (res.response) {
|
|
this.fileList.push(res.response.result)
|
|
} else {
|
|
this.fileList.push(res)
|
|
}
|
|
})
|
|
this.$emit('uploadSuccess', this.fileList)
|
|
if (this.myfileList.length > 0) {
|
|
// this.$message.destroy()
|
|
if (file.response.success) {
|
|
this.$message.success(`${info.file.name}` + this.$t('FileUploadedSuccessfully'))
|
|
}
|
|
}
|
|
} else if (status === 'uploading') {
|
|
this.myfileList = info.fileList
|
|
// this.$message.success(`${info.file.name} 文件上传成功。`);
|
|
}
|
|
},
|
|
resetFileList() {
|
|
this.myfileList = []
|
|
this.fileList = []
|
|
},
|
|
preview(file) {
|
|
let fileQuery = file.response ? file.response.result : file
|
|
let fileName = fileQuery.fileName
|
|
let index1 = fileName.lastIndexOf('.')
|
|
let index2 = fileName.length
|
|
let fileSuffix = fileName.substring(index1, index2)
|
|
downloadFile('/sys/common/downLoadFile', fileQuery.fileName, { id: fileQuery.id })
|
|
// if (fileSuffix === '.pdf') {
|
|
// window.open('/pdf/web/viewer.html?file=' + encodeURIComponent('/jero-boot/sys/common/pdf/viewFile?id=' + fileQuery.id+'&userName='+this.userInfo().username))
|
|
// } else if (fileSuffix === '.docx') {
|
|
// let url = window._CONFIG['onlinePreviewDomainURL'] + '?url=' + Base64.encode(this.downLoadFileUrl + '/' + fileQuery.id + fileSuffix)
|
|
// window.open(url, '_blank')
|
|
// } else if (fileSuffix === '.xlsx' || fileSuffix === '.xls') {
|
|
// let url = window._CONFIG['onlinePreviewDomainURL'] + '?url=' + Base64.encode(this.downLoadFileUrl + '/' + fileQuery.id + fileSuffix)
|
|
// window.open(url, '_blank')
|
|
// } else {
|
|
// downloadFile('/sys/common/downLoadFile', fileQuery.fileName, { id: fileQuery.id })
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.ant-upload-list-item-name {
|
|
color: rgba(0, 0, 0, 0.65) !important;
|
|
}
|
|
|
|
.action-upload {
|
|
font-size: 67px;
|
|
color: #c0c4cc;
|
|
}
|
|
|
|
.uploadFile {
|
|
|
|
}
|
|
</style> |