Complete cancelling uploading feature

pull/9/head
johnniang 2019-04-15 20:01:34 +08:00
parent ad6ffeb54d
commit b7d1334a0e
3 changed files with 16 additions and 13 deletions

View File

@ -31,18 +31,14 @@ attachmentApi.CancelToken = axios.CancelToken
attachmentApi.isCancel = axios.isCancel
attachmentApi.upload = (formData, uploadProgress, cancelToken) => {
return service(
{
url: `${baseUrl}/upload`,
timeout: 8640000, // 24 hours
data: formData, // form data
onUploadProgress: uploadProgress,
method: 'post'
},
{
cancelToken: cancelToken
}
)
return service({
url: `${baseUrl}/upload`,
timeout: 8640000, // 24 hours
data: formData, // form data
onUploadProgress: uploadProgress,
cancelToken: cancelToken,
method: 'post'
})
}
export default attachmentApi

View File

@ -29,6 +29,12 @@ service.interceptors.response.use(
},
error => {
NProgress.done()
if (axios.isCancel(error)) {
Vue.$log.debug('Cancelled uploading by user.')
return Promise.reject(error)
}
Vue.$log.error('Response failed', error)
const response = error.response

View File

@ -127,6 +127,7 @@
import { PageView } from '@/layouts'
import { mixin, mixinDevice } from '@/utils/mixin.js'
import attachmentApi from '@/api/attachment'
import axios from 'axios'
export default {
components: {
PageView
@ -226,7 +227,7 @@ export default {
},
handleUpload(option) {
this.$log.debug('Uploading option', option)
const CancelToken = attachmentApi.CancelToken
const CancelToken = axios.CancelToken
const source = CancelToken.source()
const data = new FormData()