index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var component_1 = require('../common/component');
  4. component_1.VantComponent({
  5. classes: [
  6. 'main-item-class',
  7. 'content-item-class',
  8. 'main-active-class',
  9. 'content-active-class',
  10. 'main-disabled-class',
  11. 'content-disabled-class',
  12. ],
  13. props: {
  14. items: {
  15. type: Array,
  16. observer: 'updateSubItems',
  17. },
  18. activeId: null,
  19. mainActiveIndex: {
  20. type: Number,
  21. value: 0,
  22. observer: 'updateSubItems',
  23. },
  24. height: {
  25. type: null,
  26. value: 300,
  27. },
  28. max: {
  29. type: Number,
  30. value: Infinity,
  31. },
  32. selectedIcon: {
  33. type: String,
  34. value: 'success',
  35. },
  36. },
  37. data: {
  38. subItems: [],
  39. },
  40. methods: {
  41. // 当一个子项被选择时
  42. onSelectItem: function (event) {
  43. var item = event.currentTarget.dataset.item;
  44. var isArray = Array.isArray(this.data.activeId);
  45. // 判断有没有超出右侧选择的最大数
  46. var isOverMax = isArray && this.data.activeId.length >= this.data.max;
  47. // 判断该项有没有被选中, 如果有被选中,则忽视是否超出的条件
  48. var isSelected = isArray
  49. ? this.data.activeId.indexOf(item.id) > -1
  50. : this.data.activeId === item.id;
  51. if (!item.disabled && (!isOverMax || isSelected)) {
  52. this.$emit('click-item', item);
  53. }
  54. },
  55. // 当一个导航被点击时
  56. onClickNav: function (event) {
  57. var index = event.detail;
  58. var item = this.data.items[index];
  59. if (!item.disabled) {
  60. this.$emit('click-nav', { index: index });
  61. }
  62. },
  63. // 更新子项列表
  64. updateSubItems: function () {
  65. var _a = this.data,
  66. items = _a.items,
  67. mainActiveIndex = _a.mainActiveIndex;
  68. var _b = (items[mainActiveIndex] || {}).children,
  69. children = _b === void 0 ? [] : _b;
  70. this.setData({ subItems: children });
  71. },
  72. },
  73. });