index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // input/input.js
  2. import rules from '../behaviors/rules';
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. behaviors: ['wx://form-field', rules],
  8. externalClasses: ['l-class', 'l-error-text', 'l-error-text-class', 'l-inner-class'],
  9. properties: {
  10. // 占位文本
  11. placeholder: {
  12. type: String,
  13. value: ''
  14. },
  15. // 输入框的值
  16. value: {
  17. type: String,
  18. value: ''
  19. },
  20. // 获取焦点
  21. focus: {
  22. type: Boolean,
  23. value: false
  24. },
  25. // 最大输入长度
  26. maxlength: {
  27. type: Number,
  28. value: 140
  29. },
  30. // 表显示文字长度的计数器
  31. indicator: {
  32. type: Boolean,
  33. value: true
  34. },
  35. // label标题的显示位置 left top right
  36. autoHeight: {
  37. type: Boolean,
  38. value: false
  39. },
  40. // 是否禁用
  41. disabled: {
  42. type: Boolean,
  43. value: false
  44. },
  45. // 是否显示边框
  46. border: {
  47. type: Boolean,
  48. value: true
  49. },
  50. // 校验
  51. rules: {
  52. type: Object,
  53. },
  54. // 占位文字的样式
  55. placeholderStyle: {
  56. type: String,
  57. value: ''
  58. }
  59. },
  60. /**
  61. * 组件的初始数据
  62. */
  63. data: {
  64. },
  65. attached() {
  66. this.initRules();
  67. },
  68. /**
  69. * 组件的方法列表
  70. */
  71. methods: {
  72. handleInputChange(event) {
  73. const {
  74. detail = {}
  75. } = event;
  76. const {
  77. value = ''
  78. } = detail;
  79. this.setData({
  80. value
  81. });
  82. this.triggerEvent('lininput', event.detail);
  83. },
  84. handleInputFocus(event) {
  85. this.triggerEvent('linfocus', event.detail);
  86. },
  87. handleInputBlur(event) {
  88. this.validatorData({
  89. value: event.detail.value
  90. });
  91. this.triggerEvent('linblur', event.detail);
  92. },
  93. handleInputConfirm(event) {
  94. this.triggerEvent('linconfirm', event.detail);
  95. },
  96. // onClearTap(e) {
  97. // this.setData({ value: '' })
  98. // },
  99. }
  100. });