index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. errorMessage: String,
  31. arrowDirection: String,
  32. placeholderStyle: String,
  33. errorMessageAlign: String,
  34. selectionEnd: {
  35. type: Number,
  36. value: -1
  37. },
  38. selectionStart: {
  39. type: Number,
  40. value: -1
  41. },
  42. showConfirmBar: {
  43. type: Boolean,
  44. value: true
  45. },
  46. adjustPosition: {
  47. type: Boolean,
  48. value: true
  49. },
  50. cursorSpacing: {
  51. type: Number,
  52. value: 50
  53. },
  54. maxlength: {
  55. type: Number,
  56. value: -1
  57. },
  58. type: {
  59. type: String,
  60. value: 'text'
  61. },
  62. border: {
  63. type: Boolean,
  64. value: true
  65. },
  66. titleWidth: {
  67. type: String,
  68. value: '90px'
  69. }
  70. },
  71. data: {
  72. focused: false,
  73. system: getSystemInfoSync().system.split(' ').shift().toLowerCase()
  74. },
  75. methods: {
  76. onInput(event) {
  77. const { value = '' } = event.detail || {};
  78. this.setData({ value }, () => {
  79. this.emitChange(value);
  80. });
  81. },
  82. onFocus(event) {
  83. this.setData({ focused: true });
  84. this.$emit('focus', event.detail);
  85. },
  86. onBlur(event) {
  87. this.setData({ focused: false });
  88. this.$emit('blur', event.detail);
  89. },
  90. onClickIcon() {
  91. this.$emit('click-icon');
  92. },
  93. onClear() {
  94. this.setData({ value: '' }, () => {
  95. this.emitChange('');
  96. this.$emit('clear', '');
  97. });
  98. },
  99. onConfirm() {
  100. this.$emit('confirm', this.data.value);
  101. },
  102. emitChange(value) {
  103. this.$emit('input', value);
  104. this.$emit('change', value);
  105. }
  106. }
  107. });