From fea53abb77922d8f7cfb6554dd093ad801f529e0 Mon Sep 17 00:00:00 2001 From: xcsoft <42080379+soxft@users.noreply.github.com> Date: Thu, 17 Oct 2024 10:34:03 +0800 Subject: [PATCH 1/3] fix(wd-form): empty toast when reject is Error --- src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue index 4e8232ade..8f9b3aa21 100644 --- a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue +++ b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue @@ -97,7 +97,7 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM .catch((error) => { errors.push({ prop, - message: error || rule.message + message: error.message || error || rule.message }) valid = false }) From 215d5fe56d0a19eee0c416fa81d7b3db7ae03bfa Mon Sep 17 00:00:00 2001 From: soxft Date: Thu, 17 Oct 2024 11:37:08 +0800 Subject: [PATCH 2/3] perf: preemptively determine error types --- .../components/wd-form/wd-form.vue | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue index 8f9b3aa21..3c9f87810 100644 --- a/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue +++ b/src/uni_modules/wot-design-uni/components/wd-form/wd-form.vue @@ -94,11 +94,23 @@ async function validate(prop?: string): Promise<{ valid: boolean; errors: ErrorM valid = false } }) - .catch((error) => { - errors.push({ - prop, - message: error.message || error || rule.message - }) + .catch((error: any) => { + if (error instanceof Error) { + errors.push({ + prop, + message: error.message || rule.message + }) + } else if (typeof error === 'string') { + errors.push({ + prop, + message: error + }) + } else { + errors.push({ + prop, + message: rule.message + }) + } valid = false }) ) From d4525d065550cbc44fcd7d47fb17503cf8804862 Mon Sep 17 00:00:00 2001 From: soxft Date: Tue, 29 Oct 2024 09:20:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20wd-form=20validator=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/uni_modules/wot-design-uni/components/wd-form/types.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uni_modules/wot-design-uni/components/wd-form/types.ts b/src/uni_modules/wot-design-uni/components/wd-form/types.ts index 176b14620..d93b490b9 100644 --- a/src/uni_modules/wot-design-uni/components/wd-form/types.ts +++ b/src/uni_modules/wot-design-uni/components/wd-form/types.ts @@ -35,7 +35,10 @@ export interface FormItemRule { required: boolean message: string pattern?: RegExp - validator?: (value: any, rule: FormItemRuleWithoutValidator) => boolean | Promise | Promise | Promise | Promise + validator?: ( + value: any, + rule: FormItemRuleWithoutValidator + ) => boolean | Promise | Promise | Promise | Promise | Promise } export type FormItemRuleWithoutValidator = Omit