index.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { use } from '../utils';
  2. import { emit, inherit } from '../utils/functional';
  3. // Types
  4. import { CreateElement, RenderContext } from 'vue/types';
  5. import { DefaultSlots } from '../utils/use/sfc';
  6. export type PasswordInputProps = {
  7. mask: boolean;
  8. info?: string;
  9. value: string;
  10. length: number;
  11. errorInfo?: string;
  12. };
  13. const [sfc, bem] = use('password-input');
  14. function PasswordInput(
  15. h: CreateElement,
  16. props: PasswordInputProps,
  17. slots: DefaultSlots,
  18. ctx: RenderContext<PasswordInputProps>
  19. ) {
  20. const info = props.errorInfo || props.info;
  21. const Points = [];
  22. for (let i = 0; i < props.length; i++) {
  23. const char = props.value[i];
  24. Points.push(
  25. <li class="van-hairline">
  26. {props.mask ? (
  27. <i style={{ visibility: char ? 'visible' : 'hidden' }} />
  28. ) : (
  29. char
  30. )}
  31. </li>
  32. );
  33. }
  34. return (
  35. <div class={bem()}>
  36. <ul
  37. class={[bem('security'), 'van-hairline--surround']}
  38. onTouchstart={(event: TouchEvent) => {
  39. event.stopPropagation();
  40. emit(ctx, 'focus', event);
  41. }}
  42. {...inherit(ctx, true)}
  43. >
  44. {Points}
  45. </ul>
  46. {info && (
  47. <div class={bem(props.errorInfo ? 'error-info' : 'info')}>{info}</div>
  48. )}
  49. </div>
  50. );
  51. }
  52. PasswordInput.props = {
  53. info: String,
  54. errorInfo: String,
  55. mask: {
  56. type: Boolean,
  57. default: true
  58. },
  59. value: {
  60. type: String,
  61. default: ''
  62. },
  63. length: {
  64. type: Number,
  65. default: 6
  66. }
  67. };
  68. export default sfc<PasswordInputProps>(PasswordInput);