index.js 2.0 KB

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