Files
laws_weilai/jero-web/src/views/projectManagement/components/resultReportedUpload.vue
T
2022-10-09 20:49:04 +08:00

245 lines
8.4 KiB
Java

<template>
<div>
<a-modal v-model="visible"
:maskClosable="false"
@ok="handleOk"
:confirm-loading="confirmLoading"
@cancel="handleCancel"
:title="title">
<a-upload-dragger
accept='*.*'
:disabled="disabled"
class="ant-upload-list"
:class="{'uploadFile':isUploadFile}"
name="file"
:file-list="myfileList"
:multiple="true"
:action="uploadAction+'?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, putAction } from '@/api/manage'
import { Base64 } from 'js-base64'
import { mapGetters } from 'vuex'
export default {
name: 'resultReportedUpload',
props: ['disableds', 'disabled', 'thisFileUploadUrl', 'readonly', 'thisFileType', 'isUploadFile'],
data() {
return {
visible: false,
title: this.$t('upload1') + this.$t('resultReported'),
uploadAction: window._CONFIG['domianURL'] + '/sys/common/upload',
state: undefined,
myuploadAction: window._CONFIG['domianURL'] + this.thisFileUploadUrl,
upDataList: [],
downLoadFileUrl: window._CONFIG['domianPreviewURL'] + '/sys/common/download',
downLoadImgUrl: window._CONFIG['domianWebImgURL'] + '/sys/common/download',
fileList: [],
myfileList: [],
isLoding: false,
cut: '',
confirmLoading: false,
uploadQuery: {},
url: {
editModel: '/project/projectLawsInventoryEO/edit'
}
}
},
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'
}
},
methods: {
...mapGetters(['userInfo']),
clickButtonToUploadFile(item) {
this.uploadQuery = item
this.myfileList = []
this.visible = true
getAction('sys/common/getFileInfos', { id: item.fileId }).then((res) => {
if (res.success) {
this.myfileList = res.result
if (this.myfileList && this.myfileList.length > 0) {
this.myfileList.forEach((val) => {
val.name = val.fileName
val.uid = val.id
if (val.response) {
this.fileList.push(val.response.result)
} else {
this.fileList.push(val)
}
})
} else {
this.myfileList = []
}
}
})
},
handleOk() {
if (this.myfileList && this.myfileList.length == 0) {
this.$message.warning(this.$t('pleaseUpload') + this.$t('resultReported'))
} else {
let content = []
this.fileList.forEach(res => {
content.push(res.id || res.name)
})
let formInline = JSON.parse(JSON.stringify(this.uploadQuery))
Object.keys(formInline).forEach(res => {
if (formInline[res] && formInline[res] instanceof Array) {
formInline[res] = formInline[res].join(',')
}
})
formInline.fileId = content.join(',')
this.confirmLoading = true
putAction(this.url.editModel, formInline).then((res) => {
if (res.success) {
this.$message.success(this.$t('OperationSuccessful'))
this.visible = false
this.confirmLoading = false
this.$emit('resultReportedUploadForm')
} else {
this.$message.warning(this.$t('operationFailed'))
this.confirmLoading = false
}
})
}
},
handleCancel() {
this.visible = false
},
beforeUpload(file) {
this.fileTypeSatus = true
this.$message.destroy()
},
remove() {
this.fileTypeSatus = true
},
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.$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)
}
})
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.$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)
}
})
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)
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' || fileSuffix === '.doc') {
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 if(fileSuffix == '.png' || fileSuffix == '.jpeg' || fileSuffix == '.gif' || fileSuffix == '.jpg'){
let url = window._CONFIG['onlinePreviewDomainURL'] + '?url=' + Base64.encode(this.downLoadImgUrl + '/' + fileQuery.id + fileSuffix)
window.open(url, '_blank')
} else {
downloadFile('/sys/common/downLoadFile', fileQuery.fileName, { id: fileQuery.id,userName:this.userInfo().username })
}
}
}
}
</script>
<style>
.ant-upload-list-item-name {
color: rgba(0, 0, 0, 0.65) !important;
}
.action-upload {
font-size: 67px;
color: #c0c4cc;
}
.uploadFile {
}
</style>