|
105 | 105 | <script> |
106 | 106 | /* eslint-disable */ |
107 | 107 | import {effectRipple, data2blob} from './utils'; |
| 108 | + import fetch from 'utils/fetch'; |
108 | 109 | import langBag from './lang'; |
109 | 110 | const mimes = { |
110 | 111 | 'jpg': 'image/jpeg', |
|
659 | 660 | }) |
660 | 661 | } |
661 | 662 | // 监听进度回调 |
662 | | - const uploadProgress = function(event) { |
| 663 | + function uploadProgress (event) { |
| 664 | + console.log(event) |
663 | 665 | if (event.lengthComputable) { |
664 | 666 | that.progress = 100 * Math.round(event.loaded) / event.total; |
665 | 667 | } |
|
669 | 671 | that.loading = 1; |
670 | 672 | that.setStep(3); |
671 | 673 | that.$emit('crop-success', createImgUrl, field, ki); |
672 | | - new Promise(function(resolve, reject) { |
673 | | - let client = new XMLHttpRequest(); |
674 | | - client.open('POST', url, true); |
675 | | - client.onreadystatechange = function() { |
676 | | - if (this.readyState !== 4) { |
677 | | - return; |
678 | | - } |
679 | | - if (this.status === 200) { |
680 | | - resolve(JSON.parse(this.responseText)); |
681 | | - } else { |
682 | | - reject(this.status); |
683 | | - } |
684 | | - }; |
685 | | - client.upload.addEventListener("progress", uploadProgress, false); //监听进度 |
686 | | - // 设置header |
687 | | - if (typeof headers == 'object' && headers) { |
688 | | - Object.keys(headers).forEach((k) => { |
689 | | - client.setRequestHeader(k, headers[k]); |
690 | | - }) |
691 | | - } |
692 | | - client.send(fmData); |
693 | | - }).then( |
694 | | - // 上传成功 |
695 | | - function(resData) { |
696 | | - that.loading = 2; |
697 | | - that.$emit('crop-upload-success', resData); |
698 | | - }, |
699 | | - // 上传失败 |
700 | | - function(sts) { |
701 | | - if (that.value) { |
| 674 | + fetch({ |
| 675 | + url, |
| 676 | + method: 'post', |
| 677 | + data: fmData |
| 678 | + }).then(resData=>{ |
| 679 | + that.loading = 2; |
| 680 | + that.$emit('crop-upload-success', resData.data); |
| 681 | + }).catch(err=>{ |
| 682 | + if (that.value) { |
702 | 683 | that.loading = 3; |
703 | 684 | that.hasError = true; |
704 | 685 | that.errorMsg = lang.fail; |
705 | | - that.$emit('crop-upload-fail', sts, field, ki); |
| 686 | + that.$emit('crop-upload-fail', err, field, ki); |
706 | 687 | } |
707 | | - } |
708 | | - ); |
| 688 | + }); |
709 | 689 | } |
710 | 690 | } |
711 | 691 | } |
|
0 commit comments