search.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. import { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-search`;
  12. let Search = class Search extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = [
  16. 'class',
  17. `${prefix}-class`,
  18. `${prefix}-class-input-container`,
  19. `${prefix}-class-input`,
  20. `${prefix}-class-action`,
  21. `${prefix}-class-left`,
  22. `${prefix}-class-right`,
  23. ];
  24. this.options = {
  25. multipleSlots: true,
  26. };
  27. this.properties = props;
  28. this.observers = {
  29. focus(nextValue) {
  30. this.setData({ 'localValue.focus': nextValue });
  31. },
  32. };
  33. this.data = {
  34. classPrefix: name,
  35. prefix,
  36. localValue: {
  37. focus: false,
  38. },
  39. };
  40. }
  41. onInput(e) {
  42. const { value } = e.detail;
  43. this.setData({ value });
  44. this.triggerEvent('change', { value });
  45. }
  46. onFocus(e) {
  47. const { value } = e.detail;
  48. this.setData({ 'localValue.focus': true });
  49. this.triggerEvent('focus', { value });
  50. }
  51. onBlur(e) {
  52. const { value } = e.detail;
  53. this.setData({ 'localValue.focus': false });
  54. this.triggerEvent('blur', { value });
  55. }
  56. handleClear() {
  57. this.setData({ value: '' });
  58. this.triggerEvent('clear', { value: '' });
  59. }
  60. onConfirm(e) {
  61. const { value } = e.detail;
  62. this.triggerEvent('submit', { value });
  63. }
  64. onActionClick() {
  65. this.triggerEvent('action-click');
  66. }
  67. };
  68. Search = __decorate([
  69. wxComponent()
  70. ], Search);
  71. export default Search;