index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { VantComponent } from '../common/component';
  2. import { getSystemInfoSync } from '../common/utils';
  3. VantComponent({
  4. field: true,
  5. classes: ['input-class', 'right-icon-class'],
  6. props: {
  7. size: String,
  8. icon: String,
  9. label: String,
  10. error: Boolean,
  11. fixed: Boolean,
  12. focus: Boolean,
  13. center: Boolean,
  14. isLink: Boolean,
  15. leftIcon: String,
  16. rightIcon: String,
  17. disabled: Boolean,
  18. autosize: Boolean,
  19. readonly: Boolean,
  20. required: Boolean,
  21. password: Boolean,
  22. iconClass: String,
  23. clearable: Boolean,
  24. clickable: Boolean,
  25. inputAlign: String,
  26. placeholder: String,
  27. customStyle: String,
  28. confirmType: String,
  29. confirmHold: Boolean,
  30. holdKeyboard: Boolean,
  31. errorMessage: String,
  32. arrowDirection: String,
  33. placeholderStyle: String,
  34. errorMessageAlign: String,
  35. selectionEnd: {
  36. type: Number,
  37. value: -1
  38. },
  39. selectionStart: {
  40. type: Number,
  41. value: -1
  42. },
  43. showConfirmBar: {
  44. type: Boolean,
  45. value: true
  46. },
  47. adjustPosition: {
  48. type: Boolean,
  49. value: true
  50. },
  51. cursorSpacing: {
  52. type: Number,
  53. value: 50
  54. },
  55. maxlength: {
  56. type: Number,
  57. value: -1
  58. },
  59. type: {
  60. type: String,
  61. value: 'text'
  62. },
  63. border: {
  64. type: Boolean,
  65. value: true
  66. },
  67. titleWidth: {
  68. type: String,
  69. value: '90px'
  70. }
  71. },
  72. data: {
  73. focused: false,
  74. system: getSystemInfoSync().system.split(' ').shift().toLowerCase()
  75. },
  76. methods: {
  77. onInput(event) {
  78. const { value = '' } = event.detail || {};
  79. this.setData({ value }, () => {
  80. this.emitChange(value);
  81. });
  82. },
  83. onFocus(event) {
  84. this.setData({ focused: true });
  85. this.$emit('focus', event.detail);
  86. },
  87. onBlur(event) {
  88. this.setData({ focused: false });
  89. this.$emit('blur', event.detail);
  90. },
  91. onClickIcon() {
  92. this.$emit('click-icon');
  93. },
  94. onClear() {
  95. this.setData({ value: '' }, () => {
  96. this.emitChange('');
  97. this.$emit('clear', '');
  98. });
  99. },
  100. onConfirm() {
  101. this.$emit('confirm', this.data.value);
  102. },
  103. emitChange(value) {
  104. this.$emit('input', value);
  105. this.$emit('change', value);
  106. }
  107. }
  108. });