From 892e25b242a7ad73dc3717d4cc84191795e0080d Mon Sep 17 00:00:00 2001 From: RUI <946667296@qq.com> Date: Thu, 22 Aug 2019 16:02:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E5=89=8D=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- upload-2.vue | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/upload-2.vue b/upload-2.vue index d4a62be..462cc3c 100644 --- a/upload-2.vue +++ b/upload-2.vue @@ -196,6 +196,10 @@ export default { method: { type: String, 'default': 'POST' + }, + beforeUpload: { + type: Function, + 'default': () => null } }, data() { @@ -780,7 +784,7 @@ export default { ctx.drawImage(sourceImg, x / scale, y / scale, width / scale, height / scale); that.createImgUrl = canvas.toDataURL(mime); }, - prepareUpload(){ + async prepareUpload(){ let { url, createImgUrl, @@ -789,13 +793,15 @@ export default { } = this; this.$emit('crop-success', createImgUrl, field, ki); if(typeof url == 'string' && url){ - this.upload(); + await this.upload(); }else{ this.off(); } }, // 上传图片 - upload() { + async upload() { + await beforeUpload() + let that = this, { lang, From 50bf084b175dad8eeaeb9551ae9e784acbb45dcf Mon Sep 17 00:00:00 2001 From: zyn Date: Thu, 22 Aug 2019 18:35:33 +0800 Subject: [PATCH 2/5] flx oss --- package.json | 7 +++++-- upload-2.vue | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e8275c5..b6168ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "vue-image-crop-upload", - "version": "2.5.0", + "name": "rui-vue-image-crop-upload", + "version": "2.5.12", "description": "a vue plgin for image upload and crop(vue图片剪裁上传插件)", "main": "upload-2.vue", "scripts": { @@ -71,5 +71,8 @@ "vue-style-loader": "^1.0.0", "webpack": "^1.13.1", "webpack-stream": "^3.2.0" + }, + "directories": { + "example": "example" } } diff --git a/upload-2.vue b/upload-2.vue index 462cc3c..bbf11cb 100644 --- a/upload-2.vue +++ b/upload-2.vue @@ -199,7 +199,11 @@ export default { }, beforeUpload: { type: Function, - 'default': () => null + 'default': () => {} + }, + cropUploadSuccess: { + type: Function, + 'default': () => {} } }, data() { @@ -800,7 +804,7 @@ export default { }, // 上传图片 async upload() { - await beforeUpload() + await this.beforeUpload(this.createImgUrl, this.field, this.ki) let that = this, { @@ -817,7 +821,6 @@ export default { method } = this, fmData = new FormData(); - fmData.append(field, data2blob(createImgUrl, mime), field + '.' + imgFormat); // 添加其他参数 if (typeof params == 'object' && params) { @@ -826,6 +829,8 @@ export default { }) } + fmData.append(field, data2blob(createImgUrl, mime), field + '.' + imgFormat); + // 监听进度回调 const uploadProgress = function(event) { if (event.lengthComputable) { @@ -864,7 +869,7 @@ export default { function(resData) { if (that.value) { that.loading = 2; - that.$emit('crop-upload-success', resData, field, ki); + that.$emit('crop-upload-success', resData, field, ki, that.reset); } }, // 上传失败 @@ -873,7 +878,7 @@ export default { that.loading = 3; that.hasError = true; that.errorMsg = lang.fail; - that.$emit('crop-upload-fail', sts, field, ki); + that.$emit('crop-upload-fail', sts, field, ki, that.reset); } } ); From b59fce51cd7b111910b34f671bd3d7bb5276ecad Mon Sep 17 00:00:00 2001 From: zyn Date: Thu, 22 Aug 2019 19:20:12 +0800 Subject: [PATCH 3/5] add off back --- package.json | 2 +- upload-2.vue | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index b6168ab..a0a5634 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rui-vue-image-crop-upload", - "version": "2.5.12", + "version": "2.5.15", "description": "a vue plgin for image upload and crop(vue图片剪裁上传插件)", "main": "upload-2.vue", "scripts": { diff --git a/upload-2.vue b/upload-2.vue index bbf11cb..83557c7 100644 --- a/upload-2.vue +++ b/upload-2.vue @@ -200,10 +200,6 @@ export default { beforeUpload: { type: Function, 'default': () => {} - }, - cropUploadSuccess: { - type: Function, - 'default': () => {} } }, data() { @@ -869,7 +865,7 @@ export default { function(resData) { if (that.value) { that.loading = 2; - that.$emit('crop-upload-success', resData, field, ki, that.reset); + that.$emit('crop-upload-success', resData, field, ki, that.off); } }, // 上传失败 @@ -878,7 +874,7 @@ export default { that.loading = 3; that.hasError = true; that.errorMsg = lang.fail; - that.$emit('crop-upload-fail', sts, field, ki, that.reset); + that.$emit('crop-upload-fail', sts, field, ki, that.off); } } ); From 759bd17fe709c94c82acbd9abec67e4350adc38a Mon Sep 17 00:00:00 2001 From: zyn Date: Fri, 23 Aug 2019 09:36:51 +0800 Subject: [PATCH 4/5] add success back img --- package.json | 2 +- upload-2.vue | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a0a5634..a7d2bf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rui-vue-image-crop-upload", - "version": "2.5.15", + "version": "2.5.16", "description": "a vue plgin for image upload and crop(vue图片剪裁上传插件)", "main": "upload-2.vue", "scripts": { diff --git a/upload-2.vue b/upload-2.vue index 83557c7..106d9f9 100644 --- a/upload-2.vue +++ b/upload-2.vue @@ -865,7 +865,7 @@ export default { function(resData) { if (that.value) { that.loading = 2; - that.$emit('crop-upload-success', resData, field, ki, that.off); + that.$emit('crop-upload-success', resData, createImgUrl, field, ki, that.off); } }, // 上传失败 @@ -874,7 +874,7 @@ export default { that.loading = 3; that.hasError = true; that.errorMsg = lang.fail; - that.$emit('crop-upload-fail', sts, field, ki, that.off); + that.$emit('crop-upload-fail', sts, createImgUrl, field, ki, that.off); } } ); From bb93f20a35d2799b7c417cd7fc663859d0797e33 Mon Sep 17 00:00:00 2001 From: zyn Date: Fri, 23 Aug 2019 09:45:31 +0800 Subject: [PATCH 5/5] edit no url --- package.json | 2 +- upload-2.vue | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a7d2bf2..f6ea4fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rui-vue-image-crop-upload", - "version": "2.5.16", + "version": "2.5.18", "description": "a vue plgin for image upload and crop(vue图片剪裁上传插件)", "main": "upload-2.vue", "scripts": { diff --git a/upload-2.vue b/upload-2.vue index 106d9f9..6579fcb 100644 --- a/upload-2.vue +++ b/upload-2.vue @@ -792,11 +792,8 @@ export default { ki } = this; this.$emit('crop-success', createImgUrl, field, ki); - if(typeof url == 'string' && url){ - await this.upload(); - }else{ - this.off(); - } + + await this.upload(); }, // 上传图片 async upload() { @@ -818,6 +815,12 @@ export default { } = this, fmData = new FormData(); + // 检查是否有url + if(typeof url != 'string' || !url){ + this.off(); + return; + } + // 添加其他参数 if (typeof params == 'object' && params) { Object.keys(params).forEach((k) => {