search.js 2.3 KB

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