wd-password-input.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <view :class="`wd-password-input ${customClass}`" :style="customStyle">
  3. <view @touchstart="onTouchStart" class="wd-password-input__security">
  4. <view
  5. v-for="(_, index) in length"
  6. :key="index"
  7. :class="`wd-password-input__item ${gutter ? '' : 'is-border'}`"
  8. :style="{ marginLeft: index !== 0 && gutter ? addUnit(gutter) : 0 }"
  9. >
  10. <view v-if="focused && index === modelValue.length" class="wd-password-input__cursor"></view>
  11. <view v-else :class="`wd-password-input__value`">
  12. <view :style="{ visibility: mask && modelValue[index] ? 'visible' : 'hidden' }" class="wd-password-input__mask"></view>
  13. <text v-if="!mask && modelValue[index]">{{ modelValue[index] }}</text>
  14. </view>
  15. </view>
  16. </view>
  17. <view v-if="info || errorInfo" :class="`wd-password-input__info ${errorInfo ? 'is-error' : ''}`">
  18. {{ errorInfo || info }}
  19. </view>
  20. </view>
  21. </template>
  22. <script lang="ts">
  23. export default {
  24. name: 'wd-password-input',
  25. options: {
  26. virtualHost: true,
  27. addGlobalClass: true,
  28. styleIsolation: 'shared'
  29. }
  30. }
  31. </script>
  32. <script lang="ts" setup>
  33. import { addUnit } from '../common/util'
  34. import { passwordInputProps } from './types'
  35. defineProps(passwordInputProps)
  36. const emit = defineEmits(['focus'])
  37. function onTouchStart(event: Event) {
  38. emit('focus', event)
  39. }
  40. </script>
  41. <style lang="scss" scoped>
  42. @import './index.scss';
  43. </style>