tab-bar.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 { wxComponent, SuperComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. const { prefix } = config;
  11. const classPrefix = `${prefix}-tab-bar`;
  12. let Tabbar = class Tabbar extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.relations = {
  16. './tab-bar-item': {
  17. type: 'descendant',
  18. },
  19. };
  20. this.externalClasses = [`${prefix}-class`];
  21. this.data = {
  22. prefix,
  23. classPrefix,
  24. };
  25. this.properties = props;
  26. this.controlledProps = [
  27. {
  28. key: 'value',
  29. event: 'change',
  30. },
  31. ];
  32. this.observers = {
  33. value() {
  34. this.updateChildren();
  35. },
  36. };
  37. this.methods = {
  38. showChildren() {
  39. const items = this.getRelationNodes('./tab-bar-item');
  40. const len = items.length;
  41. const { value } = this.data;
  42. if (len > 0) {
  43. items.forEach((child) => {
  44. if (child.properties.value === value) {
  45. child.showSpread();
  46. }
  47. });
  48. }
  49. },
  50. updateChildren() {
  51. const items = this.getRelationNodes('./tab-bar-item');
  52. const len = items.length;
  53. const { value } = this.data;
  54. if (len > 0) {
  55. items.forEach((child) => {
  56. child.checkActive(value);
  57. });
  58. }
  59. },
  60. updateValue(value) {
  61. this._trigger('change', { value });
  62. },
  63. changeOtherSpread(value) {
  64. const items = this.getRelationNodes('./tab-bar-item');
  65. items.forEach((child) => {
  66. if (child.properties.value !== value) {
  67. child.closeSpread();
  68. }
  69. });
  70. },
  71. initName() {
  72. return (this.backupValue += 1);
  73. },
  74. };
  75. }
  76. ready() {
  77. this.showChildren();
  78. }
  79. };
  80. Tabbar = __decorate([
  81. wxComponent()
  82. ], Tabbar);
  83. export default Tabbar;