index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var component_1 = require("../common/component");
  4. var version_1 = require("../common/version");
  5. (0, component_1.VantComponent)({
  6. field: true,
  7. classes: ['field-class', 'input-class', 'cancel-class'],
  8. props: {
  9. value: {
  10. type: String,
  11. value: '',
  12. },
  13. label: String,
  14. focus: Boolean,
  15. error: Boolean,
  16. disabled: Boolean,
  17. readonly: Boolean,
  18. inputAlign: String,
  19. showAction: Boolean,
  20. useActionSlot: Boolean,
  21. useLeftIconSlot: Boolean,
  22. useRightIconSlot: Boolean,
  23. leftIcon: {
  24. type: String,
  25. value: 'search',
  26. },
  27. rightIcon: String,
  28. placeholder: String,
  29. placeholderStyle: String,
  30. actionText: {
  31. type: String,
  32. value: '取消',
  33. },
  34. background: {
  35. type: String,
  36. value: '#ffffff',
  37. },
  38. maxlength: {
  39. type: Number,
  40. value: -1,
  41. },
  42. shape: {
  43. type: String,
  44. value: 'square',
  45. },
  46. clearable: {
  47. type: Boolean,
  48. value: true,
  49. },
  50. clearTrigger: {
  51. type: String,
  52. value: 'focus',
  53. },
  54. clearIcon: {
  55. type: String,
  56. value: 'clear',
  57. },
  58. cursorSpacing: {
  59. type: Number,
  60. value: 0,
  61. },
  62. },
  63. methods: {
  64. onChange: function (event) {
  65. if ((0, version_1.canIUseModel)()) {
  66. this.setData({ value: event.detail });
  67. }
  68. this.$emit('change', event.detail);
  69. },
  70. onCancel: function () {
  71. var _this = this;
  72. /**
  73. * 修复修改输入框值时,输入框失焦和赋值同时触发,赋值失效
  74. * https://github.com/youzan/vant-weapp/issues/1768
  75. */
  76. setTimeout(function () {
  77. if ((0, version_1.canIUseModel)()) {
  78. _this.setData({ value: '' });
  79. }
  80. _this.$emit('cancel');
  81. _this.$emit('change', '');
  82. }, 200);
  83. },
  84. onSearch: function (event) {
  85. this.$emit('search', event.detail);
  86. },
  87. onFocus: function (event) {
  88. this.$emit('focus', event.detail);
  89. },
  90. onBlur: function (event) {
  91. this.$emit('blur', event.detail);
  92. },
  93. onClear: function (event) {
  94. this.$emit('clear', event.detail);
  95. },
  96. onClickInput: function (event) {
  97. this.$emit('click-input', event.detail);
  98. },
  99. },
  100. });