From 0fc90ddcc9b5d478fe3e5bf84e2e780c48a8a341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=91=B8=E9=B1=BC=E5=8E=BB?= <1780903673@qq.com> Date: Thu, 2 Jan 2025 00:36:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20=E4=BF=AE=E5=A4=8D=20InputN?= =?UTF-8?q?umber=20=E5=9C=A8=E8=AE=BE=E7=BD=AE=E4=B8=BA=20allow-null=20?= =?UTF-8?q?=E6=97=B6=E8=A2=AB=E8=B5=8B=E5=80=BC=E4=B8=BA=E7=A9=BA=E6=97=B6?= =?UTF-8?q?=E6=9C=AA=E8=A7=A6=E5=8F=91=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=B9=B6=E6=94=AF=E6=8C=81=E5=BC=82=E6=AD=A5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20(#812)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/component/input-number.md | 31 +++- src/pages/inputNumber/Index.vue | 17 ++ .../components/common/interceptor.ts | 43 +++++ .../components/wd-input-number/types.ts | 13 +- .../wd-input-number/wd-input-number.vue | 162 ++++++++---------- 5 files changed, 173 insertions(+), 93 deletions(-) create mode 100644 src/uni_modules/wot-design-uni/components/common/interceptor.ts diff --git a/docs/component/input-number.md b/docs/component/input-number.md index 23d8bb95..adf89b0d 100644 --- a/docs/component/input-number.md +++ b/docs/component/input-number.md @@ -96,6 +96,34 @@ function handleChange1({ value }) { } ``` +## 异步变更 +通过 `before-change` 可以在输入值变化前进行校验和拦截。 + +```html + +``` + +```typescript +import { ref } from 'vue' +import { useToast } from '@/uni_modules/wot-design-uni' +import type { InputNumberBeforeChange } from '@/uni_modules/wot-design-uni/components/wd-input-number/types' +const { loading, close } = useToast() + +const value = ref(1) + +const beforeChange: InputNumberBeforeChange = (value) => { + loading({ msg: `正在更新到${value}...` }) + return new Promise((resolve) => { + setTimeout(() => { + close() + resolve(true) + }, 500) + }) +} +``` + + + ## Attributes | 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | @@ -109,12 +137,13 @@ function handleChange1({ value }) { | disabled | 禁用 | boolean | - | false | - | | without-input | 不显示输入框 | boolean | - | false | - | | input-width | 输入框宽度 | string | - | 36px | - | -| allow-null | 允许空值 | boolean | - | false | - | +| allow-null | 是否允许输入的值为空,设置为 `true` 后允许传入空字符串 | boolean | - | false | - | | placeholder | 占位文本 | string | - | - | - | | disable-input | 禁用输入框 | boolean | - | false | 0.2.14 | | disable-plus | 禁用增加按钮 | boolean | - | false | 0.2.14 | | disable-minus | 禁用减少按钮 | boolean | - | false | 0.2.14 | | adjustPosition | 原生属性,键盘弹起时,是否自动上推页面 | boolean | - | true | 1.3.11 | +| before-change | 输入框值改变前触发,返回 false 会阻止输入框值改变,支持返回 `Promise` | `(value: number \| string) => boolean \| Promise` | - | - | $LOWEST_VERSION$ | ## Events diff --git a/src/pages/inputNumber/Index.vue b/src/pages/inputNumber/Index.vue index a919168d..d75835de 100644 --- a/src/pages/inputNumber/Index.vue +++ b/src/pages/inputNumber/Index.vue @@ -33,10 +33,16 @@ + + +