refine imageCropper fetch
This commit is contained in:
parent
0476f25eba
commit
69fe4d1e91
|
@ -105,6 +105,7 @@
|
||||||
<script>
|
<script>
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import {effectRipple, data2blob} from './utils';
|
import {effectRipple, data2blob} from './utils';
|
||||||
|
import fetch from 'utils/fetch';
|
||||||
import langBag from './lang';
|
import langBag from './lang';
|
||||||
const mimes = {
|
const mimes = {
|
||||||
'jpg': 'image/jpeg',
|
'jpg': 'image/jpeg',
|
||||||
|
@ -659,7 +660,8 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// 监听进度回调
|
// 监听进度回调
|
||||||
const uploadProgress = function(event) {
|
function uploadProgress (event) {
|
||||||
|
console.log(event)
|
||||||
if (event.lengthComputable) {
|
if (event.lengthComputable) {
|
||||||
that.progress = 100 * Math.round(event.loaded) / event.total;
|
that.progress = 100 * Math.round(event.loaded) / event.total;
|
||||||
}
|
}
|
||||||
|
@ -669,43 +671,21 @@
|
||||||
that.loading = 1;
|
that.loading = 1;
|
||||||
that.setStep(3);
|
that.setStep(3);
|
||||||
that.$emit('crop-success', createImgUrl, field, ki);
|
that.$emit('crop-success', createImgUrl, field, ki);
|
||||||
new Promise(function(resolve, reject) {
|
fetch({
|
||||||
let client = new XMLHttpRequest();
|
url,
|
||||||
client.open('POST', url, true);
|
method: 'post',
|
||||||
client.onreadystatechange = function() {
|
data: fmData
|
||||||
if (this.readyState !== 4) {
|
}).then(resData=>{
|
||||||
return;
|
that.loading = 2;
|
||||||
}
|
that.$emit('crop-upload-success', resData.data);
|
||||||
if (this.status === 200) {
|
}).catch(err=>{
|
||||||
resolve(JSON.parse(this.responseText));
|
if (that.value) {
|
||||||
} else {
|
|
||||||
reject(this.status);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
client.upload.addEventListener("progress", uploadProgress, false); //监听进度
|
|
||||||
// 设置header
|
|
||||||
if (typeof headers == 'object' && headers) {
|
|
||||||
Object.keys(headers).forEach((k) => {
|
|
||||||
client.setRequestHeader(k, headers[k]);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
client.send(fmData);
|
|
||||||
}).then(
|
|
||||||
// 上传成功
|
|
||||||
function(resData) {
|
|
||||||
that.loading = 2;
|
|
||||||
that.$emit('crop-upload-success', resData);
|
|
||||||
},
|
|
||||||
// 上传失败
|
|
||||||
function(sts) {
|
|
||||||
if (that.value) {
|
|
||||||
that.loading = 3;
|
that.loading = 3;
|
||||||
that.hasError = true;
|
that.hasError = true;
|
||||||
that.errorMsg = lang.fail;
|
that.errorMsg = lang.fail;
|
||||||
that.$emit('crop-upload-fail', sts, field, ki);
|
that.$emit('crop-upload-fail', err, field, ki);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue