修复上传时不显示进度条的问题

master
toesbieya 6 years ago
parent 08a6567e23
commit 38859853be
  1. 21
      vue/src/bizComponents/UploadFile/index.vue
  2. 2
      vue/src/utils/file.js

@ -63,9 +63,7 @@
}, },
data() { data() {
return { return {
data: this.fileList, data: this.fileList
index: 0,
show: false
} }
}, },
computed: { computed: {
@ -89,11 +87,6 @@
return return
} }
this.data = [...this.fileList.map(file => ({...file, url: autoCompleteUrl(file.url)}))] this.data = [...this.fileList.map(file => ({...file, url: autoCompleteUrl(file.url)}))]
//index
if (this.data[this.index]) {
this.index = this.data.findIndex(i => i === this.data[this.index])
}
} }
} }
}, },
@ -169,23 +162,17 @@
elError(`${file.name}的大小超出${numberFormatter(maxSize)}`) elError(`${file.name}的大小超出${numberFormatter(maxSize)}`)
return false return false
} }
/*return getToken()
.then(token => {
let now = new Date()
file.token = token
file.key = timeFormat('yyyy/MM/dd/', now) + now.getTime() + '/' + file.name
})*/
}, },
httpRequest(option) { httpRequest({file, onProgress}) {
const CancelToken = axios.CancelToken const CancelToken = axios.CancelToken
const source = CancelToken.source() const source = CancelToken.source()
const promise = upload(option.file, option.file.name, { const promise = upload(file, file.name, {
onUploadProgress(e) { onUploadProgress(e) {
if (e.total > 0) { if (e.total > 0) {
e.percent = (Number)((e.loaded / e.total * 100).toFixed(2)) e.percent = (Number)((e.loaded / e.total * 100).toFixed(2))
} }
option.onProgress(e) onProgress(e)
}, },
cancelToken: source.token cancelToken: source.token
}) })

@ -42,7 +42,7 @@ export function upload(blob, filename = '快照.png', options = defaultOptions)
return getToken() return getToken()
.then(token => { .then(token => {
const param = new FormData() const param = new FormData()
options = {...options, ...defaultOptions} options = {...defaultOptions, ...options}
param.append('token', token) param.append('token', token)
param.append('key', options.generateKey(filename)) param.append('key', options.generateKey(filename))
param.append('file', blob, filename) param.append('file', blob, filename)

Loading…
Cancel
Save