Complate theme upload.

pull/9/head
ruibaby 6 years ago
parent 769118ae06
commit b90ea3d0bf

@ -1,3 +1,4 @@
import axios from 'axios'
import service from '@/utils/service'
const baseUrl = '/admin/api/themes'
@ -75,4 +76,18 @@ themeApi.getProperty = themeId => {
})
}
themeApi.CancelToken = axios.CancelToken
themeApi.isCancel = axios.isCancel
themeApi.upload = (formData, uploadProgress, cancelToken) => {
return service({
url: `${baseUrl}/upload`,
timeout: 8640000, // 24 hours
data: formData, // form data
onUploadProgress: uploadProgress,
cancelToken: cancelToken,
method: 'post'
})
}
export default themeApi

@ -1,10 +0,0 @@
<template>
<div class="page-header-index-wide"> Attachment Detail </div>
</template>
<script>
export default {}
</script>
<style scoped>
</style>

@ -146,9 +146,9 @@
<a-upload-dragger
name="file"
:multiple="true"
action="http://localhost:8090/admin/api/attachments/uploads"
accept="application/zip"
:customRequest="handleUpload"
@change="handleChange"
accept=".zip"
>
<p class="ant-upload-drag-icon">
<a-icon type="inbox"/>
@ -258,6 +258,39 @@ export default {
},
handleActivateClick(theme) {
this.activeTheme(theme.id)
},
handleUpload(option) {
this.$log.debug('Uploading option', option)
const CancelToken = themeApi.CancelToken
const source = CancelToken.source()
const data = new FormData()
data.append('file', option.file)
themeApi
.upload(
data,
progressEvent => {
if (progressEvent.total > 0) {
progressEvent.percent = (progressEvent.loaded / progressEvent.total) * 100
}
this.$log.debug('Uploading percent: ', progressEvent.percent)
option.onProgress(progressEvent)
},
source.token
)
.then(response => {
option.onSuccess(response, option.file)
this.loadThemes()
})
.catch(error => {
option.onError(error, error.response)
})
return {
abort: () => {
source.cancel('Upload operation canceled by the user.')
}
}
}
}
}

Loading…
Cancel
Save