feat:登录注册完成
This commit is contained in:
119
src/components/base-input/index.vue
Normal file
119
src/components/base-input/index.vue
Normal file
@@ -0,0 +1,119 @@
|
||||
<template>
|
||||
<view class="base-input">
|
||||
<view v-if="iconSrc" class="base-input__icon">
|
||||
<image
|
||||
class="base-input__icon-img"
|
||||
:class="{ 'base-input__icon-img--lock': icon === 'lock' }"
|
||||
:src="iconSrc"
|
||||
mode="aspectFit"
|
||||
/>
|
||||
</view>
|
||||
<input
|
||||
class="base-input__field"
|
||||
:type="inputType"
|
||||
:password="password"
|
||||
:value="modelValue"
|
||||
:placeholder="placeholder"
|
||||
:placeholder-class="placeholderClass"
|
||||
:maxlength="maxlength"
|
||||
@input="onInput"
|
||||
/>
|
||||
<view v-if="$slots.suffix" class="base-input__suffix">
|
||||
<slot name="suffix" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { staticAssets } from '@/utils/static-assets'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: string
|
||||
placeholder?: string
|
||||
icon?: 'phone' | 'shield' | 'lock'
|
||||
type?: 'text' | 'password' | 'number'
|
||||
maxlength?: number
|
||||
}>(),
|
||||
{
|
||||
placeholder: '',
|
||||
type: 'text',
|
||||
maxlength: 140,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: string]
|
||||
}>()
|
||||
|
||||
const password = computed(() => props.type === 'password')
|
||||
const inputType = computed(() => {
|
||||
if (props.type === 'number') return 'number'
|
||||
if (props.type === 'password') return 'text'
|
||||
return 'text'
|
||||
})
|
||||
|
||||
const iconSrc = computed(() => {
|
||||
if (!props.icon) return ''
|
||||
if (props.icon === 'phone') return staticAssets.iconPhone
|
||||
if (props.icon === 'lock') return staticAssets.iconPassword
|
||||
return staticAssets.iconCode
|
||||
})
|
||||
|
||||
const placeholderClass = 'base-input__placeholder'
|
||||
|
||||
function onInput(e: Event) {
|
||||
const { value } = (e as CustomEvent<{ value: string }>).detail
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.base-input {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 96rpx;
|
||||
padding: 0 32rpx;
|
||||
background: $color-bg-input;
|
||||
border: 2rpx solid $color-border;
|
||||
border-radius: $radius-input;
|
||||
margin-bottom: 24rpx;
|
||||
}
|
||||
|
||||
.base-input__icon {
|
||||
flex-shrink: 0;
|
||||
margin-right: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.base-input__icon-img {
|
||||
width: 40rpx;
|
||||
height: 40rpx;
|
||||
}
|
||||
|
||||
.base-input__icon-img--lock {
|
||||
width: 32rpx;
|
||||
height: 32rpx;
|
||||
}
|
||||
|
||||
.base-input__field {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
font-size: 28rpx;
|
||||
color: $color-text;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.base-input__suffix {
|
||||
flex-shrink: 0;
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
:deep(.base-input__placeholder) {
|
||||
color: $color-text-placeholder;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user