index.js 5.2 KB

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