25 lines
682 B
JavaScript
25 lines
682 B
JavaScript
import {Loading} from "element-ui"
|
|
|
|
export class UploadAdapter {
|
|
constructor(loader, instance, action, params) {
|
|
this.instance = instance
|
|
this.action = action
|
|
this.loader = loader
|
|
this.params = params
|
|
}
|
|
|
|
async upload() {
|
|
const formData = new FormData()
|
|
formData.append('file', await this.loader.file)
|
|
const loading = Loading.service({})
|
|
return this.instance.post(this.action, formData, {...this.params, returnError: true}).then(res => {
|
|
if (res?.data) {
|
|
return res.data.map(m => m.split(";")?.[0])
|
|
} else return this.loader.status = "aborted" && Promise.reject()
|
|
}).finally(() => loading.close())
|
|
}
|
|
|
|
abort() {
|
|
}
|
|
}
|