tab-bar-item.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.relations = {
  16. './tab-bar': {
  17. type: 'ancestor',
  18. linked(parent) {
  19. const [activeColor, color] = parent.data.color;
  20. this.setData({
  21. parent,
  22. color,
  23. activeColor,
  24. split: parent.data.split,
  25. currentName: this.properties.value ? this.properties.value : parent.initName(),
  26. });
  27. parent.updateChildren();
  28. },
  29. },
  30. };
  31. this.data = {
  32. prefix,
  33. classPrefix,
  34. isSpread: false,
  35. isChecked: false,
  36. parent: null,
  37. hasChildren: false,
  38. currentName: '',
  39. color: '',
  40. activeColor: '',
  41. split: true,
  42. };
  43. this.properties = props;
  44. this.observers = {
  45. subTabBar(value) {
  46. this.setData({
  47. hasChildren: value.length > 0,
  48. });
  49. },
  50. };
  51. this.methods = {
  52. showSpread() {
  53. this.setData({
  54. isSpread: true,
  55. });
  56. },
  57. toggle() {
  58. const { parent, currentName, hasChildren, isSpread } = this.data;
  59. if (hasChildren) {
  60. this.setData({
  61. isSpread: !isSpread,
  62. });
  63. }
  64. parent.updateValue(currentName);
  65. parent.changeOtherSpread(currentName);
  66. },
  67. selectChild(event) {
  68. const { parent, currentName } = this.data;
  69. const childName = event.target.dataset.name;
  70. if (!(Array.isArray(parent.value) && parent.value[1] === childName)) {
  71. parent.updateValue([currentName, childName]);
  72. }
  73. this.setData({
  74. isSpread: false,
  75. });
  76. },
  77. checkActive(value) {
  78. const { currentName, hasChildren } = this.data;
  79. const isChecked = currentName === value;
  80. if (hasChildren && Array.isArray(value)) {
  81. return value.indexOf(currentName) > -1;
  82. }
  83. this.setData({
  84. isChecked,
  85. });
  86. },
  87. closeSpread() {
  88. this.setData({
  89. isSpread: false,
  90. });
  91. },
  92. };
  93. }
  94. };
  95. TabbarItem = __decorate([
  96. wxComponent()
  97. ], TabbarItem);
  98. export default TabbarItem;
  99. //# sourceMappingURL=tab-bar-item.js.map