tab-bar-item.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 './tab-bar-item-props';
  10. const { prefix } = config;
  11. const classPrefix = `${prefix}-tab-bar-item`;
  12. let TabbarItem = class TabbarItem extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.parent = null;
  16. this.relations = {
  17. './tab-bar': {
  18. type: 'ancestor',
  19. linked(parent) {
  20. this.parent = parent;
  21. this.setData({
  22. split: parent.data.split,
  23. currentName: this.properties.value ? this.properties.value : parent.initName(),
  24. });
  25. parent.updateChildren();
  26. },
  27. },
  28. };
  29. this.options = {
  30. multipleSlots: true,
  31. };
  32. this.data = {
  33. prefix,
  34. classPrefix,
  35. isSpread: false,
  36. isChecked: false,
  37. hasChildren: false,
  38. currentName: '',
  39. split: true,
  40. };
  41. this.properties = props;
  42. this.observers = {
  43. subTabBar(value) {
  44. this.setData({
  45. hasChildren: value.length > 0,
  46. });
  47. },
  48. };
  49. this.methods = {
  50. showSpread() {
  51. this.setData({
  52. isSpread: true,
  53. });
  54. },
  55. toggle() {
  56. const { parent } = this;
  57. const { currentName, hasChildren, isSpread } = this.data;
  58. if (hasChildren) {
  59. this.setData({
  60. isSpread: !isSpread,
  61. });
  62. }
  63. parent.updateValue(currentName);
  64. parent.changeOtherSpread(currentName);
  65. },
  66. selectChild(event) {
  67. const { parent } = this;
  68. const { value } = event.target.dataset;
  69. parent.updateValue(value);
  70. this.setData({
  71. isSpread: false,
  72. });
  73. },
  74. checkActive(value) {
  75. const { currentName, subTabBar } = this.data;
  76. const isChecked = (subTabBar === null || subTabBar === void 0 ? void 0 : subTabBar.some((item) => item.value === value)) || currentName === value;
  77. this.setData({
  78. isChecked,
  79. });
  80. },
  81. closeSpread() {
  82. this.setData({
  83. isSpread: false,
  84. });
  85. },
  86. };
  87. }
  88. };
  89. TabbarItem = __decorate([
  90. wxComponent()
  91. ], TabbarItem);
  92. export default TabbarItem;