From 01cf735453bb4f2757615beab5ee72480c07e417 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Wed, 20 Mar 2024 10:13:27 +0800 Subject: [PATCH] 优化图片预览组件,支持缩略图加载失败回退 --- forms/form/CForm.vue | 51 ++++++++++++++++++++++++++++++++++----------------- 1 files changed, 34 insertions(+), 17 deletions(-) diff --git a/forms/form/CForm.vue b/forms/form/CForm.vue index 065bea8..944feef 100644 --- a/forms/form/CForm.vue +++ b/forms/form/CForm.vue @@ -90,7 +90,7 @@ title: validation.msg, icon: 'none', mask: false, - duration: 2000, + duration: validation.msg.length < 16 ? 2000 : 3000, }); return; } @@ -124,7 +124,7 @@ title: validation.msg, icon: 'none', mask: false, - duration: 2000, + duration: validation.msg.length < 16 ? 2000 : 3000, }); // 检查失败 callback && callback(false); @@ -138,30 +138,47 @@ // 直接设定错误 $setErrors(errors) { const checklist = []; + const unchecks = []; Object.keys(errors).forEach(errorKey => { if (typeof this.validators[errorKey] !== 'undefined') { checklist.push( this.validators[errorKey]('setError', errors[errorKey]) ); + } else { + unchecks.push(errors[errorKey]); } }); - Promise.all(checklist).then(validations => { - for (let validation of validations) { - // 第一个不通过项提示 - if (!validation.passed) { - if (this.autoScrollToError === 'on') { - this.scrollTop = validation.offset.top - this.offsetTop; + if (checklist.length > 0) { + Promise.all(checklist).then(validations => { + for (let validation of validations) { + // 第一个不通过项提示 + if (!validation.passed) { + if (this.autoScrollToError === 'on') { + this.scrollTop = validation.offset.top - this.offsetTop; + } + Taro.showToast({ + title: validation.msg, + icon: 'none', + mask: false, + duration: validation.msg.length < 16 ? 2000 : 3000, + }); + return; } - Taro.showToast({ - title: validation.msg, - icon: 'none', - mask: false, - duration: 2000, - }); - return; } - } - }); + }); + } else if (unchecks.length > 0) { + Taro.showToast({ + title: unchecks[0], + icon: 'none', + mask: false, + duration: unchecks[0] < 16 ? 2000 : 3000, + }); + } + }, + $setScrollTop(top) { + if (this.autoScrollToError === 'on') { + this.scrollTop = top; + } }, }, mounted() { -- Gitblit v1.9.1