-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ✨ 增加 wd-password-input 输入框 * feat: ✨ 增加 wd-password-input 密码输入框(引入数字键盘) * feat: ✨ 增加 wd-password-input 密码输入框 * feat: ✨ 增加 wd-password-input 密码输入框 --------- Co-authored-by: pangzhaozhao <zhaozhao.pang@sincerecloud.com>
- Loading branch information
Showing
9 changed files
with
425 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<frame/> | ||
|
||
|
||
# PasswordInput 密码输入框 | ||
|
||
带网格的输入框组件,可以用于输入密码、短信验证码等场景,通常与[数字键盘](./number-keyboard.md)组件配合使用。 | ||
|
||
## 基础用法 | ||
|
||
搭配数字键盘组件来实现密码输入功能。 | ||
|
||
```html | ||
<!-- 密码输入框 --> | ||
<wd-password-input | ||
:value="value" | ||
:focused="showKeyboard" | ||
@focus="showKeyboard = true" | ||
/> | ||
<!-- 数字键盘 --> | ||
<wd-number-keyboard | ||
v-model="value" | ||
v-model:visible="showKeyboard" | ||
:maxlength="4" | ||
@blur="showKeyboard = false" | ||
/> | ||
``` | ||
```typescript | ||
import { ref } from 'vue'; | ||
|
||
const value = ref<string>('123'); | ||
const showKeyboard = ref<boolean>(true); | ||
``` | ||
|
||
### 自定义长度 | ||
|
||
通过`length`属性来设置密码长度。 | ||
|
||
```html | ||
<!-- 密码输入框 --> | ||
<wd-password-input | ||
:value="value" | ||
:length="4" | ||
:focused="showKeyboard" | ||
@focus="showKeyboard = true" | ||
/> | ||
<wd-number-keyboard | ||
v-model="value" | ||
v-model:visible="showKeyboard" | ||
:maxlength="4" | ||
@blur="showKeyboard = false" | ||
> | ||
</wd-number-keyboard> | ||
|
||
``` | ||
|
||
|
||
### 格子间距 | ||
|
||
通过`gutter`属性来设置格子之间的间距。 | ||
|
||
```html | ||
<!-- 密码输入框 --> | ||
<wd-password-input | ||
:value="value" | ||
:gutter="10" | ||
:focused="showKeyboard" | ||
@focus="showKeyboard = true" | ||
/> | ||
``` | ||
|
||
### 明文展示 | ||
|
||
将`mask`设置为`false`可以明文展示输入的内容,适用于短信验证码等场景。 | ||
|
||
```html | ||
<!-- 密码输入框 --> | ||
<wd-password-input | ||
:value="value" | ||
:mask="false" | ||
:focused="showKeyboard" | ||
@focus="showKeyboard = true" | ||
/> | ||
``` | ||
|
||
### 提示信息 | ||
|
||
通过`info`属性设置提示信息,通过`error-info`属性设置错误提示,例如当输入六位时提示密码错误。 | ||
|
||
```html | ||
<!-- 密码输入框 --> | ||
<wd-password-input | ||
:value="value" | ||
info="密码为 6 位数字" | ||
:error-info="errorInfo" | ||
:focused="showKeyboard" | ||
@focus="showKeyboard = true" | ||
/> | ||
<!-- 数字键盘 --> | ||
<wd-number-keyboard | ||
v-model="value" | ||
:show="showKeyboard" | ||
:maxlength="6" | ||
@blur="showKeyboard = false" | ||
/> | ||
``` | ||
```typescript | ||
import { ref, watch } from 'vue'; | ||
|
||
const value = ref('123'); | ||
const errorInfo = ref(''); | ||
const showKeyboard = ref(true); | ||
|
||
watch(value, (newVal) => { | ||
if (newVal.length === 6 && newVal !== '123456') { | ||
errorInfo.value = '密码错误'; | ||
} else { | ||
errorInfo.value = ''; | ||
} | ||
}); | ||
``` | ||
|
||
|
||
|
||
## Attributes | ||
|
||
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 | | ||
| ---------- | ----------------------------------------------- | --------------- | ------ | ------ | ------ | | ||
| value | 密码值 | string | - | '' | - | | ||
| info | 输入框下方文字提示 | string | - | - | - | | ||
| error-info | 输入框下方错误提示 | string | - | - | - | | ||
| length | 密码最大长度 | number \| string | - | 6 | - | | ||
| gutter | 输入框格子之间的间距,如 20px 2em,默认单位为px | number \| string | - | 0 | - | | ||
| mask | 是否隐藏密码内容 | boolean | - | true | - | | ||
| focused | 是否已聚焦,聚焦时会显示光标 | boolean | - | false | - | | ||
|
||
|
||
|
||
## Events | ||
|
||
| 事件名 | 说明 | 参数 | 最低版本 | | ||
| ------ | ---------------- | ---- | -------- | | ||
| focus | 输入框聚焦时触发 | | - | | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<template> | ||
<page-wraper> | ||
<view class="password-input"> | ||
<demo-block title="基本用法" transparent> | ||
<wd-password-input v-model="value1" :focused="visible1" @focus="showKeyBoard(1)" /> | ||
<wd-number-keyboard v-model:visible="visible1" v-model="value1" :maxlength="6"></wd-number-keyboard> | ||
</demo-block> | ||
<demo-block title="自定义长度" transparent> | ||
<wd-password-input v-model="value2" :length="4" :focused="visible2" @focus="showKeyBoard(2)" /> | ||
<wd-number-keyboard v-model:visible="visible2" v-model="value2" :maxlength="4"></wd-number-keyboard> | ||
</demo-block> | ||
<demo-block title="限制最大最小值" transparent> | ||
<wd-password-input v-model="value3" :gutter="10" :focused="visible3" @focus="showKeyBoard(3)" /> | ||
<wd-number-keyboard v-model:visible="visible3" v-model="value3" :maxlength="6"></wd-number-keyboard> | ||
</demo-block> | ||
<demo-block title="明文展示" transparent> | ||
<wd-password-input v-model="value4" :mask="false" :focused="visible4" @focus="showKeyBoard(4)" /> | ||
<wd-number-keyboard v-model:visible="visible4" v-model="value4" :maxlength="6"></wd-number-keyboard> | ||
</demo-block> | ||
<demo-block title="提示信息" transparent> | ||
<wd-password-input v-model="value5" info="密码为 6 位数字" :error-info="errorInfo" :focused="visible5" @focus="showKeyBoard(5)" /> | ||
<wd-number-keyboard v-model:visible="visible5" v-model="value5" :maxlength="6"></wd-number-keyboard> | ||
</demo-block> | ||
</view> | ||
</page-wraper> | ||
</template> | ||
<script lang="ts" setup> | ||
import { ref, watch } from 'vue' | ||
const value1 = ref<string>('123') | ||
const value2 = ref<string>('123') | ||
const value3 = ref<string>('123') | ||
const value4 = ref<string>('123') | ||
const value5 = ref<string>('123') | ||
const errorInfo = ref<string>('') | ||
const visible1 = ref<boolean>(true) | ||
const visible2 = ref<boolean>(false) | ||
const visible3 = ref<boolean>(false) | ||
const visible4 = ref<boolean>(false) | ||
const visible5 = ref<boolean>(false) | ||
const visibleArr = [visible1, visible2, visible3, visible4, visible5] | ||
function showKeyBoard(index: number) { | ||
visibleArr.forEach((item, i) => (i === index - 1 ? (item.value = true) : (item.value = false))) | ||
} | ||
watch(value5, (newVal) => { | ||
if (newVal.length === 6 && newVal !== '123456') { | ||
errorInfo.value = '密码错误' | ||
} else { | ||
errorInfo.value = '' | ||
} | ||
}) | ||
</script> | ||
<style lang="scss" scoped> | ||
.password-input { | ||
padding-bottom: 240px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/uni_modules/wot-design-uni/components/wd-password-input/index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
@import "../common/abstracts/variable"; | ||
@import "../common/abstracts/mixin"; | ||
|
||
.wot-theme-dark { | ||
@include b(password-input) { | ||
@include e(item) { | ||
color: $-dark-color; | ||
background: $-dark-background2; | ||
|
||
@include when(border) { | ||
border-color: $-dark-border-color; | ||
} | ||
} | ||
|
||
@include e(mask) { | ||
background-color: $-dark-color; | ||
} | ||
|
||
@include e(cursor) { | ||
background-color: $-dark-color; | ||
} | ||
|
||
@include e(info) { | ||
color: $-dark-color; | ||
|
||
@include when(border) { | ||
color: $-dark-color2; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@include b(password-input) { | ||
position: relative; | ||
margin: 0 16px; | ||
user-select: none; | ||
|
||
@include e(security) { | ||
display: flex; | ||
width: 100%; | ||
height: 50px; | ||
cursor: pointer; | ||
} | ||
|
||
@include e(item) { | ||
position: relative; | ||
display: flex; | ||
flex: 1; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
color: $-password-input-color; | ||
font-size: 20px; | ||
line-height: 1.2; | ||
background: $-password-input-background-color; | ||
|
||
@include when(border) { | ||
border: 1px solid $-password-input-border-color; | ||
|
||
&:not(:last-child) { | ||
border-right: none; | ||
} | ||
|
||
&:first-child { | ||
border-top-left-radius: 6px; | ||
border-bottom-left-radius: 6px; | ||
} | ||
|
||
&:last-child { | ||
border-top-right-radius: 6px; | ||
border-bottom-right-radius: 6px; | ||
} | ||
} | ||
} | ||
|
||
@include e(mask) { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
width: 10px; | ||
height: 10px; | ||
background: $-password-input-color; | ||
border-radius: 100%; | ||
transform: translate(-50%, -50%); | ||
visibility: hidden; | ||
} | ||
|
||
@include e(cursor) { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
width: 1px; | ||
height: 40%; | ||
background: $-password-input-color; | ||
transform: translate(-50%, -50%); | ||
animation: 1s van-cursor-flicker infinite; | ||
} | ||
|
||
@include e(info) { | ||
margin-top: 16px; | ||
font-size: $-fs-content; | ||
text-align: center; | ||
color: $-color-info; | ||
|
||
@include when(error) { | ||
color: $-color-danger; | ||
} | ||
|
||
} | ||
} | ||
|
||
@keyframes van-cursor-flicker { | ||
from { | ||
opacity: 0; | ||
} | ||
|
||
50% { | ||
opacity: 1; | ||
} | ||
|
||
100% { | ||
opacity: 0; | ||
} | ||
} |
Oops, something went wrong.