index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. 'use strict';
  2. var __assign =
  3. (this && this.__assign) ||
  4. function () {
  5. __assign =
  6. Object.assign ||
  7. function (t) {
  8. for (var s, i = 1, n = arguments.length; i < n; i++) {
  9. s = arguments[i];
  10. for (var p in s)
  11. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  12. }
  13. return t;
  14. };
  15. return __assign.apply(this, arguments);
  16. };
  17. Object.defineProperty(exports, '__esModule', { value: true });
  18. var component_1 = require('../common/component');
  19. var props_1 = require('./props');
  20. component_1.VantComponent({
  21. field: true,
  22. classes: ['input-class', 'right-icon-class', 'label-class'],
  23. props: __assign(
  24. __assign(
  25. __assign(__assign({}, props_1.commonProps), props_1.inputProps),
  26. props_1.textareaProps
  27. ),
  28. {
  29. size: String,
  30. icon: String,
  31. label: String,
  32. error: Boolean,
  33. center: Boolean,
  34. isLink: Boolean,
  35. leftIcon: String,
  36. rightIcon: String,
  37. autosize: [Boolean, Object],
  38. required: Boolean,
  39. iconClass: String,
  40. clickable: Boolean,
  41. inputAlign: String,
  42. customStyle: String,
  43. errorMessage: String,
  44. arrowDirection: String,
  45. showWordLimit: Boolean,
  46. errorMessageAlign: String,
  47. readonly: {
  48. type: Boolean,
  49. observer: 'setShowClear',
  50. },
  51. clearable: {
  52. type: Boolean,
  53. observer: 'setShowClear',
  54. },
  55. border: {
  56. type: Boolean,
  57. value: true,
  58. },
  59. titleWidth: {
  60. type: String,
  61. value: '6.2em',
  62. },
  63. }
  64. ),
  65. data: {
  66. focused: false,
  67. innerValue: '',
  68. showClear: false,
  69. },
  70. created: function () {
  71. this.value = this.data.value;
  72. this.setData({ innerValue: this.value });
  73. },
  74. methods: {
  75. onInput: function (event) {
  76. var _a = (event.detail || {}).value,
  77. value = _a === void 0 ? '' : _a;
  78. this.value = value;
  79. this.setShowClear();
  80. this.emitChange();
  81. },
  82. onFocus: function (event) {
  83. this.focused = true;
  84. this.setShowClear();
  85. this.$emit('focus', event.detail);
  86. },
  87. onBlur: function (event) {
  88. this.focused = false;
  89. this.setShowClear();
  90. this.$emit('blur', event.detail);
  91. },
  92. onClickIcon: function () {
  93. this.$emit('click-icon');
  94. },
  95. onClear: function () {
  96. var _this = this;
  97. this.setData({ innerValue: '' });
  98. this.value = '';
  99. this.setShowClear();
  100. wx.nextTick(function () {
  101. _this.emitChange();
  102. _this.$emit('clear', '');
  103. });
  104. },
  105. onConfirm: function (event) {
  106. var _a = (event.detail || {}).value,
  107. value = _a === void 0 ? '' : _a;
  108. this.value = value;
  109. this.setShowClear();
  110. this.$emit('confirm', value);
  111. },
  112. setValue: function (value) {
  113. this.value = value;
  114. this.setShowClear();
  115. if (value === '') {
  116. this.setData({ innerValue: '' });
  117. }
  118. this.emitChange();
  119. },
  120. onLineChange: function (event) {
  121. this.$emit('linechange', event.detail);
  122. },
  123. onKeyboardHeightChange: function (event) {
  124. this.$emit('keyboardheightchange', event.detail);
  125. },
  126. emitChange: function () {
  127. var _this = this;
  128. this.setData({ value: this.value });
  129. wx.nextTick(function () {
  130. _this.$emit('input', _this.value);
  131. _this.$emit('change', _this.value);
  132. });
  133. },
  134. setShowClear: function () {
  135. var _a = this.data,
  136. clearable = _a.clearable,
  137. readonly = _a.readonly;
  138. var _b = this,
  139. focused = _b.focused,
  140. value = _b.value;
  141. this.setData({
  142. showClear: !!clearable && !!focused && !!value && !readonly,
  143. });
  144. },
  145. noop: function () {},
  146. },
  147. });