index.js 2.6 KB

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