import {Component, Prop, Vue, Emit, Watch} from 'vue-property-decorator'; import index from "@/store"; @Component export default class EflyNavMenuAdmin extends Vue { @Prop({default: () => ''}) private defaultActive!: any[]; @Prop({default: () => 'icon-down'}) private downIcon!: any[]; private status: any = { stretch: false, } private activeItem: any; private mounted() { window.addEventListener('click', () => { this.hideGroup() }) this.resetDefaultActive(); } @Watch('defaultActive') private watchDefaultActivity(value: any) { this.resetDefaultActive(); } /** * 重置所有状态 * @param that * @param tier */ private resetDefaultActive(that: any = this) { let children: any = that.$children; for (let i in children) { if (children[i].$options._componentTag === 'efly-nav-menu-admin-group') { this.resetDefaultActive(children[i]) } else if (children[i].$options._componentTag === 'efly-nav-menu-admin-item') { children[i].defaultActive = this.defaultActive; children[i].getDefaultActive() if (children[i].status.group) { this.resetDefaultActive(children[i]) } } } } /** * 隐藏 */ private hideGroup() { if (!this.activeItem) { return; } if (this.activeItem.tier > 1) { this.activeItem.$parent.$parent.status.groupShow = false; } else { this.activeItem.status.groupShow = false; } } /** * 隐藏显示 */ private stretch() { this.status.stretch = !this.status.stretch; this.updateStretch(this); this.$emit('indentChange', this.status.stretch) } /** * 重置所有状态 * @param that * @param tier */ private resetActive(that: any = this) { let children: any = that.$children; for (let i in children) { if (children[i].$options._componentTag === 'efly-nav-menu-admin-group') { // this.resetActive(children[i]) } else if (children[i].$options._componentTag === 'efly-nav-menu-admin-item') { children[i].status.active = false; children[i].status.groupShow = false; } } } /** * 更新 * @param that */ private updateStretch(that: any) { let children: any = that.$children; for (let i in children) { if (children[i].$options._componentTag === 'efly-nav-menu-admin-group') { } else if (children[i].$options._componentTag === 'efly-nav-menu-admin-item') { children[i].status.stretch = this.status.stretch; children[i].$forceUpdate(); } } } private getActiceItem(item: any) { this.activeItem = item; } private selectItem(index: any) { if(index !== this.defaultActive){ this.$emit('change', index); } } }