input.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. /*
  8. * @Author: rileycai
  9. * @Date: 2021-09-21 19:10:10
  10. * @LastEditTime: 2021-09-28 10:26:57
  11. * @LastEditors: Please set LastEditors
  12. * @Description: textarea从input组件拆分出去
  13. * @FilePath: /tdesign-miniprogram/src/input/input.ts
  14. */
  15. import { SuperComponent, wxComponent } from '../common/src/index';
  16. import config from '../common/config';
  17. import props from './props';
  18. import { getCharacterLength } from '../common/utils';
  19. const { prefix } = config;
  20. const name = `${prefix}-input`;
  21. let Input = class Input extends SuperComponent {
  22. constructor() {
  23. super(...arguments);
  24. this.options = {
  25. multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  26. };
  27. this.externalClasses = ['t-class', 't-class-input', 't-class-placeholder', 't-class-error-msg'];
  28. this.behaviors = ['wx://form-field'];
  29. this.properties = props;
  30. this.controlledProps = [
  31. {
  32. key: 'value',
  33. event: 'change',
  34. },
  35. ];
  36. this.data = {
  37. classPrefix: name,
  38. classBasePrefix: prefix,
  39. characterLength: 0,
  40. };
  41. this.methods = {
  42. onInput(event) {
  43. const { value } = event.detail;
  44. const { maxcharacter } = this.properties;
  45. if (maxcharacter && maxcharacter > 0 && !Number.isNaN(maxcharacter)) {
  46. const { characters = '', length = 0 } = getCharacterLength(value, maxcharacter);
  47. this._trigger('change', { value: characters });
  48. this.setData({
  49. characterLength: length,
  50. });
  51. }
  52. else {
  53. this._trigger('change', { value });
  54. }
  55. },
  56. onFocus(event) {
  57. this.triggerEvent('focus', event.detail);
  58. },
  59. onBlur(event) {
  60. this.triggerEvent('blur', event.detail);
  61. },
  62. onConfirm(event) {
  63. this.triggerEvent('enter', event.detail);
  64. },
  65. clearInput(event) {
  66. this.triggerEvent('clear', event.detail);
  67. this.setData({ value: '' });
  68. },
  69. };
  70. }
  71. };
  72. Input = __decorate([
  73. wxComponent()
  74. ], Input);
  75. export default Input;
  76. //# sourceMappingURL=input.js.map