import { Component, ViewChild, OnInit, AfterViewInit } from '@angular/core'; import { FarrisTabsComponent } from '../../../../projects/tabs/src/lib/'; import { TestTabsComponent } from './testtab/testtab.component'; @Component({ selector: 'tabs', templateUrl: './tabs.component.html' }) export class TabsComponent implements OnInit, AfterViewInit { @ViewChild('withToolbarTab') withToolbarTab: FarrisTabsComponent; selectId = 'b'; toolbarA = { position: 'inHead', contents: [ { id: 'a', // disabled: false, title: '新增', click: 'addRecord', appearance: { class: 'btn btn-link' }, visible: true }, { id: 'b', // disabled: false, title: '删除删除', click: 'deleteRecord', appearance: { class: 'btn btn-link' }, visible: true }, { id: 'c', // disabled: false, title: '更新', click: 'updateRecord', appearance: { class: 'btn btn-link' }, visible: true }, { id: 'd', // disabled: true, title: '查询', click: 'selectRecord', appearance: { class: 'btn btn-link' }, visible: false } ] }; toolbarB = { position: 'inHead', contents: [ { id: 'a', // disabled: false, title: '新增', click: 'addRecord', appearance: { class: 'btn btn-link' }, visible: true }, { id: 'b', // disabled: false, title: '删除', click: 'deleteRecord', appearance: { class: 'btn btn-link' }, visible: true } ] }; toolbarC = { position: 'inHead', contents: [ { id: 'a', disabled: false, title: '新增', click: 'addRecord', appearance: { class: 'k-button k-flat mr-2' }, visible: true } ] }; constructor(private testTabs: TestTabsComponent) { } ngOnInit() { } ngAfterViewInit() { } changeTabShow() { const numbers = Math.round(Math.random() * 10); switch (numbers) { case 1: case 2: this.selectId = 'c'; break; case 3: case 4: this.selectId = 'd'; break; case 5: case 6: this.selectId = 'e'; break; case 8: case 7: this.selectId = 'f'; break; case 9: case 10: this.selectId = 'g'; break; } } addOneTab() { const str = 's' + Math.random(); this.withToolbarTab.addTabs([{ id: str, disabled: false, title: '标签' + str, content: '标签内容' + str, removeable: true, show: true }], this.withToolbarTab.tabs.length - 1, str); } setDisable(str: any, isDisabled: boolean) { if (this.withToolbarTab.toolbarConf) { this.withToolbarTab.toolbarConf.contents.forEach((item) => { if (item.id === str) { item.disable = isDisabled; } }); } } tabToolbarPos(farrisTab, pos) { if (pos && farrisTab.toolbarConf) { farrisTab.toolbarConf.position = pos; } } hideSecondTab() { this.withToolbarTab.hideTab('b'); } showSecondTab() { this.withToolbarTab.showTab('b'); this.withToolbarTab.showTab('c'); } tabChange(e) { console.log(e); } tabRemove(e) { console.log(e); } addTabs(tabs) { } closeTab(tabs) { tabs.closeTab('d'); } }