[update] 文件上传组件-文件预览的优化
This commit is contained in:
@@ -21,7 +21,8 @@
|
|||||||
<div class="ant-upload-text">{{ text }}</div>
|
<div class="ant-upload-text">{{ text }}</div>
|
||||||
</div>
|
</div>
|
||||||
<a-button v-else-if="buttonVisible">
|
<a-button v-else-if="buttonVisible">
|
||||||
<a-icon type="upload" />{{ text }}
|
<a-icon type="upload"/>
|
||||||
|
{{ text }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</template>
|
</template>
|
||||||
</a-upload>
|
</a-upload>
|
||||||
@@ -34,11 +35,12 @@
|
|||||||
import {ACCESS_TOKEN} from '@/store/mutation-types'
|
import {ACCESS_TOKEN} from '@/store/mutation-types'
|
||||||
import {getFileAccessHttpUrl} from '@/api/manage'
|
import {getFileAccessHttpUrl} from '@/api/manage'
|
||||||
import {getFileInfo} from '@/api/api'
|
import {getFileInfo} from '@/api/api'
|
||||||
|
|
||||||
const Base64 = require('js-base64').Base64
|
const Base64 = require('js-base64').Base64
|
||||||
|
|
||||||
const FILE_TYPE_ALL = 'all'
|
const FILE_TYPE_ALL = 'all'
|
||||||
const FILE_TYPE_IMG = 'image'
|
const FILE_TYPE_IMG = 'image'
|
||||||
const FILE_TYPE_TXT = 'file'
|
// const FILE_TYPE_TXT = 'file'
|
||||||
const uidGenerator = () => {
|
const uidGenerator = () => {
|
||||||
return '-' + parseInt(Math.random() * 10000 + 1, 10)
|
return '-' + parseInt(Math.random() * 10000 + 1, 10)
|
||||||
}
|
}
|
||||||
@@ -138,7 +140,7 @@
|
|||||||
computed: {
|
computed: {
|
||||||
//透传给下级组件的事件,需要排除本组件使用的change事件
|
//透传给下级组件的事件,需要排除本组件使用的change事件
|
||||||
childListeners() {
|
childListeners() {
|
||||||
const vm = this
|
// const vm = this
|
||||||
let result = Object.assign({},
|
let result = Object.assign({},
|
||||||
this.$listeners,
|
this.$listeners,
|
||||||
)
|
)
|
||||||
@@ -161,11 +163,11 @@
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initFileListArr(val) {
|
initFileListArr(val) {
|
||||||
if(!val || val.length==0){
|
if (!val || val.length === 0) {
|
||||||
this.fileList = []
|
this.fileList = []
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for(var a=0;a<val.length;a++){
|
for (let a = 0; a < val.length; a++) {
|
||||||
this.fileList.forEach((item) => {
|
this.fileList.forEach((item) => {
|
||||||
if (item.url === val[a]) {
|
if (item.url === val[a]) {
|
||||||
item.uid = uidGenerator()
|
item.uid = uidGenerator()
|
||||||
@@ -192,34 +194,41 @@
|
|||||||
const fileList = []
|
const fileList = []
|
||||||
for (let a = 0; a < arr.length; a++) {
|
for (let a = 0; a < arr.length; a++) {
|
||||||
// 获取每一个文件的信息,组成fileList
|
// 获取每一个文件的信息,组成fileList
|
||||||
|
// 突然想判断现在的fileList 中是否是历史的信息,如果是的话则先进行匹配
|
||||||
|
let isHistory = this.fileList.find(file => file.response.status === 'history' && (file.response.result || {}).id === arr[a])
|
||||||
|
console.log("isHistory===", isHistory)
|
||||||
|
if (isHistory) {
|
||||||
|
fileList.push(isHistory)
|
||||||
|
} else {
|
||||||
const fileObj = await this.getFileInfo(arr[a])
|
const fileObj = await this.getFileInfo(arr[a])
|
||||||
const url = getFileAccessHttpUrl(arr[a])
|
const url = getFileAccessHttpUrl(arr[a])
|
||||||
fileList.push({
|
fileList.push({
|
||||||
uid: uidGenerator(),
|
uid: uidGenerator(),
|
||||||
name: fileObj.fileName,
|
name: (fileObj || {}).fileName,
|
||||||
status: 'done',
|
status: 'done',
|
||||||
url: url,
|
url: url,
|
||||||
response: {
|
response: {
|
||||||
status: 'history',
|
status: 'history',
|
||||||
message: arr[a]
|
message: arr[a],
|
||||||
|
result: fileObj
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.fileList = [...fileList]
|
this.fileList = [...fileList]
|
||||||
|
|
||||||
},
|
},
|
||||||
handlePathChange() {
|
handlePathChange() {
|
||||||
let uploadFiles = this.fileList
|
let uploadFiles = this.fileList
|
||||||
let path = ''
|
let path = ''
|
||||||
// 文件id
|
// 文件id
|
||||||
let fileIds = ''
|
let fileIds = ''
|
||||||
if(!uploadFiles || uploadFiles.length==0){
|
if (!uploadFiles || uploadFiles.length === 0) {
|
||||||
path = ''
|
path = ''
|
||||||
}
|
}
|
||||||
let arr = []
|
let arr = []
|
||||||
// 如果returnid为true 只返回id
|
// 如果returnid为true 只返回id
|
||||||
if (this.returnId) {
|
if (this.returnId) {
|
||||||
for(var a=0;a<uploadFiles.length;a++){
|
for (let a = 0; a < uploadFiles.length; a++) {
|
||||||
if (uploadFiles[a].status === 'done') {
|
if (uploadFiles[a].status === 'done') {
|
||||||
arr.push(uploadFiles[a].response.result.id)
|
arr.push(uploadFiles[a].response.result.id)
|
||||||
} else {
|
} else {
|
||||||
@@ -233,7 +242,7 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var a=0;a<uploadFiles.length;a++){
|
for (let a = 0; a < uploadFiles.length; a++) {
|
||||||
if (uploadFiles[a].status === 'done') {
|
if (uploadFiles[a].status === 'done') {
|
||||||
arr.push(uploadFiles[a].url)
|
arr.push(uploadFiles[a].url)
|
||||||
} else {
|
} else {
|
||||||
@@ -247,7 +256,7 @@
|
|||||||
},
|
},
|
||||||
beforeUpload(file) {
|
beforeUpload(file) {
|
||||||
this.uploadGoOn = true
|
this.uploadGoOn = true
|
||||||
var fileType = file.type
|
let fileType = file.type
|
||||||
if (this.fileType === FILE_TYPE_IMG) {
|
if (this.fileType === FILE_TYPE_IMG) {
|
||||||
if (fileType.indexOf('image') < 0) {
|
if (fileType.indexOf('image') < 0) {
|
||||||
this.$message.warning('请上传图片')
|
this.$message.warning('请上传图片')
|
||||||
@@ -290,10 +299,10 @@
|
|||||||
} else {
|
} else {
|
||||||
//returnUrl为false时返回文件名称、文件路径及文件大小
|
//returnUrl为false时返回文件名称、文件路径及文件大小
|
||||||
this.newFileList = []
|
this.newFileList = []
|
||||||
for(var a=0;a<fileList.length;a++){
|
for (let a = 0; a < fileList.length; a++) {
|
||||||
// update-begin-author:lvdandan date:20200603 for:【TESTA-514】【开源issue】多个文件同时上传时,控制台报错
|
// update-begin-author:lvdandan date:20200603 for:【TESTA-514】【开源issue】多个文件同时上传时,控制台报错
|
||||||
if (fileList[a].status === 'done') {
|
if (fileList[a].status === 'done') {
|
||||||
var fileJson = {
|
let fileJson = {
|
||||||
fileName: fileList[a].name,
|
fileName: fileList[a].name,
|
||||||
filePath: fileList[a].url,
|
filePath: fileList[a].url,
|
||||||
fileSize: fileList[a].size
|
fileSize: fileList[a].size
|
||||||
@@ -314,9 +323,9 @@
|
|||||||
},
|
},
|
||||||
handlePreview(file) {
|
handlePreview(file) {
|
||||||
if (file && file.url) {
|
if (file && file.url) {
|
||||||
var fileFullUrl = `${window._CONFIG['domianWebSocketURL']}/sys/common/download/${file.response.result.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}`
|
const fileFullUrl = `${window._CONFIG['domianWebSocketURL']}/sys/common/download/${file.response.result.id}?token=${Vue.ls.get(ACCESS_TOKEN)}&fullfilename=${file.name}`
|
||||||
// let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(Base64.encode(fileFullUrl))}`
|
let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(Base64.encode(fileFullUrl))}`
|
||||||
let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(fileFullUrl)}`
|
// let url = `${window._CONFIG['onlinePreviewDomainURL']}?url=${encodeURIComponent(fileFullUrl)}`
|
||||||
window.open(url)
|
window.open(url)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -340,7 +349,8 @@
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted(){},
|
mounted() {
|
||||||
|
},
|
||||||
model: {
|
model: {
|
||||||
prop: 'value',
|
prop: 'value',
|
||||||
event: 'change'
|
event: 'change'
|
||||||
@@ -354,6 +364,7 @@
|
|||||||
.anticon-close {
|
.anticon-close {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.anticon-delete {
|
.anticon-delete {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -76,7 +76,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
devServer: {
|
devServer: {
|
||||||
port: 3000,
|
port: 21825,
|
||||||
proxy: {
|
proxy: {
|
||||||
/* '/api': {
|
/* '/api': {
|
||||||
target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro', //mock API接口系统
|
target: 'https://mock.ihx.me/mock/5baf3052f7da7e07e04a5116/antd-pro', //mock API接口系统
|
||||||
@@ -88,7 +88,7 @@ module.exports = {
|
|||||||
},*/
|
},*/
|
||||||
'/jero-boot': {
|
'/jero-boot': {
|
||||||
// ''
|
// ''
|
||||||
target: 'http://localhost:8080', //请求本地 jero-boot后台项目
|
target: 'http://localhost:21824', //请求本地 jero-boot后台项目
|
||||||
ws: false,
|
ws: false,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user