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