(component): 新增 input 组件 password 属性

This commit is contained in:
就眠儀式 2022-07-16 22:42:59 +08:00
parent f11412de0b
commit 0e8edc23c0
5 changed files with 50 additions and 13 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@layui/layui-vue", "name": "@layui/layui-vue",
"version": "1.2.11", "version": "1.3.0-alpha.3",
"author": "就眠儀式", "author": "就眠儀式",
"license": "MIT", "license": "MIT",
"description": "a component library for Vue 3 base on layui-vue", "description": "a component library for Vue 3 base on layui-vue",

View File

@ -70,6 +70,7 @@
padding: 0 15px; padding: 0 15px;
} }
.layui-input-password,
.layui-input-clear { .layui-input-clear {
flex: none; flex: none;
display: flex; display: flex;

View File

@ -22,6 +22,7 @@ export interface LayInputProps {
autofocus?: boolean; autofocus?: boolean;
disabled?: boolean; disabled?: boolean;
readonly?: boolean; readonly?: boolean;
password?: boolean;
} }
const props = withDefaults(defineProps<LayInputProps>(), { const props = withDefaults(defineProps<LayInputProps>(), {
@ -29,6 +30,7 @@ const props = withDefaults(defineProps<LayInputProps>(), {
readonly: false, readonly: false,
allowClear: false, allowClear: false,
autofocus: false, autofocus: false,
password: false,
modelValue: "", modelValue: "",
}); });
@ -45,10 +47,14 @@ const emit = defineEmits<InputEmits>();
const { t } = useI18n(); const { t } = useI18n();
const slots = useSlots(); const slots = useSlots();
const currentValue = ref<string>( const type = ref(props.type);
String(props.modelValue == null ? "" : props.modelValue) const currentValue = ref<string>(String(props.modelValue == null ? "" : props.modelValue));
);
const hasContent = computed(() => (props.modelValue as string)?.length > 0); const hasContent = computed(() => (props.modelValue as string)?.length > 0);
const isPassword = computed(() => type.value == "password")
watch(() => props.type, () => {
type.value = props.type;
})
watch( watch(
() => props.modelValue, () => props.modelValue,
@ -93,6 +99,14 @@ const onBlur = (event: Event) => {
const classes = computed(() => { const classes = computed(() => {
return { "layui-disabled": props.disabled }; return { "layui-disabled": props.disabled };
}); });
const showPassword = () => {
if(isPassword.value) {
type.value = "text";
} else {
type.value = "password";
}
}
</script> </script>
<template> <template>
@ -132,6 +146,9 @@ const classes = computed(() => {
class="layui-input-suffix-icon" class="layui-input-suffix-icon"
></lay-icon> ></lay-icon>
</span> </span>
<span class="layui-input-password" v-if="password">
<lay-icon :type="isPassword ? 'layui-icon-face-smile' : 'layui-icon-face-cry'" @click="showPassword"></lay-icon>
</span>
<span class="layui-input-clear" v-if="allowClear && hasContent"> <span class="layui-input-clear" v-if="allowClear && hasContent">
<lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon> <lay-icon type="layui-icon-close-fill" @click.stop="onClear"></lay-icon>
</span> </span>

View File

@ -7,15 +7,7 @@ export default {
<script setup lang="ts"> <script setup lang="ts">
import "./index.less"; import "./index.less";
import LaySelectOption from "../selectOption/index.vue"; import LaySelectOption from "../selectOption/index.vue";
import { import { provide, ref, watch, computed, Ref, nextTick, shallowRef } from "vue";
provide,
ref,
watch,
computed,
Ref,
nextTick,
shallowRef,
} from "vue";
import LayBadge from "../badge/index.vue"; import LayBadge from "../badge/index.vue";
import LayInput from "../input/index.vue"; import LayInput from "../input/index.vue";
import LayScroll from "../scroll/index.vue"; import LayScroll from "../scroll/index.vue";

View File

@ -111,6 +111,33 @@ export default {
::: :::
::: title 输入密码
:::
::: demo
<template>
<lay-input v-model="inputValue" type="password" password></lay-input>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const inputValue = ref("");
return {
inputValue
}
}
}
</script>
:::
::: title 设置图标 ::: title 设置图标
::: :::