index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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: [Number, String],
  26. value: 300
  27. },
  28. max: {
  29. type: Number,
  30. value: Infinity
  31. }
  32. },
  33. data: {
  34. subItems: []
  35. },
  36. methods: {
  37. // 当一个子项被选择时
  38. onSelectItem: function (event) {
  39. var item = event.currentTarget.dataset.item;
  40. var isArray = Array.isArray(this.data.activeId);
  41. // 判断有没有超出右侧选择的最大数
  42. var isOverMax = isArray && this.data.activeId.length >= this.data.max;
  43. // 判断该项有没有被选中, 如果有被选中,则忽视是否超出的条件
  44. var isSelected = isArray
  45. ? this.data.activeId.indexOf(item.id) > -1
  46. : this.data.activeId === item.id;
  47. if (!item.disabled && (!isOverMax || isSelected)) {
  48. this.$emit('click-item', item);
  49. }
  50. },
  51. // 当一个导航被点击时
  52. onClickNav: function (event) {
  53. var index = event.detail;
  54. var item = this.data.items[index];
  55. if (!item.disabled) {
  56. this.$emit('click-nav', { index: index });
  57. }
  58. },
  59. // 更新子项列表
  60. updateSubItems: function () {
  61. var _a = this.data, items = _a.items, mainActiveIndex = _a.mainActiveIndex;
  62. var _b = (items[mainActiveIndex] || {}).children, children = _b === void 0 ? [] : _b;
  63. return this.set({ subItems: children });
  64. }
  65. }
  66. });