From bc606166a04e34d5c90f5ab5b470e35abef8ffcb Mon Sep 17 00:00:00 2001 From: hobeas Date: Fri, 17 Sep 2021 17:28:39 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20before-upload=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20async=20=E8=BF=94=E5=9B=9E=20false=20?= =?UTF-8?q?=E4=BB=8D=E6=89=A7=E8=A1=8C=E4=B8=8A=E4=BC=A0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uview-ui/components/u-upload/u-upload.vue | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/uview-ui/components/u-upload/u-upload.vue b/uview-ui/components/u-upload/u-upload.vue index f4d4b763..6efd75ae 100644 --- a/uview-ui/components/u-upload/u-upload.vue +++ b/uview-ui/components/u-upload/u-upload.vue @@ -394,12 +394,9 @@ export default { let beforeResponse = this.beforeUpload.bind(this.$u.$parent.call(this))(index, this.lists); // 判断是否返回了promise if (!!beforeResponse && typeof beforeResponse.then === 'function') { - await beforeResponse.then(res => { - // promise返回成功,不进行动作,继续上传 - }).catch(err => { - // 进入catch回调的话,继续下一张 - return this.uploadFile(index + 1); - }) + // promise 或 async 返回 false,或进入 catch 回调,继续下一张;否则不进行动作,继续上传 + const result = await beforeResponse.catch(() => false); + if (result === false) return this.uploadFile(index + 1); } else if(beforeResponse === false) { // 如果返回false,继续下一张图片的上传 return this.uploadFile(index + 1); From 7475a9535f7a9a41cbb0081d72d13a92b979211a Mon Sep 17 00:00:00 2001 From: hobeas Date: Fri, 17 Sep 2021 17:53:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BD=BF=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E7=BC=A9=E8=BF=9B=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uview-ui/components/u-upload/u-upload.vue | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uview-ui/components/u-upload/u-upload.vue b/uview-ui/components/u-upload/u-upload.vue index 6efd75ae..0e480ef9 100644 --- a/uview-ui/components/u-upload/u-upload.vue +++ b/uview-ui/components/u-upload/u-upload.vue @@ -394,9 +394,9 @@ export default { let beforeResponse = this.beforeUpload.bind(this.$u.$parent.call(this))(index, this.lists); // 判断是否返回了promise if (!!beforeResponse && typeof beforeResponse.then === 'function') { - // promise 或 async 返回 false,或进入 catch 回调,继续下一张;否则不进行动作,继续上传 - const result = await beforeResponse.catch(() => false); - if (result === false) return this.uploadFile(index + 1); + // promise 或 async 返回 false,或进入 catch 回调,继续下一张;否则不进行动作,继续上传 + const result = await beforeResponse.catch(() => false); + if (result === false) return this.uploadFile(index + 1); } else if(beforeResponse === false) { // 如果返回false,继续下一张图片的上传 return this.uploadFile(index + 1); From 9834f3b5fdad64a62339a38ab5adc215aa7b2abd Mon Sep 17 00:00:00 2001 From: hobeas Date: Fri, 17 Sep 2021 18:10:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20before-remove=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20async=20=E8=BF=94=E5=9B=9E=20false=20?= =?UTF-8?q?=E4=BB=8D=E6=89=A7=E8=A1=8C=E5=88=A0=E9=99=A4=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uview-ui/components/u-upload/u-upload.vue | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/uview-ui/components/u-upload/u-upload.vue b/uview-ui/components/u-upload/u-upload.vue index 0e480ef9..f59e8e0e 100644 --- a/uview-ui/components/u-upload/u-upload.vue +++ b/uview-ui/components/u-upload/u-upload.vue @@ -470,13 +470,10 @@ export default { let beforeResponse = this.beforeRemove.bind(this.$u.$parent.call(this))(index, this.lists); // 判断是否返回了promise if (!!beforeResponse && typeof beforeResponse.then === 'function') { - await beforeResponse.then(res => { - // promise返回成功,不进行动作,继续上传 - this.handlerDeleteItem(index); - }).catch(err => { - // 如果进入promise的reject,终止删除操作 - this.showToast('已终止移除'); - }) + // promise 或 async 返回 false,或进入 catch 回调,终止删除操作;否则执行删除 + const result = await beforeResponse.catch(() => false); + if (result === false) return this.showToast('已终止移除'); + this.handlerDeleteItem(index); } else if(beforeResponse === false) { // 返回false,终止删除 this.showToast('已终止移除');