Files
bbq/src/app/routes/commom/components/basic-table/basic-table.component.ts
Taric Xin ca11cf85f4 edit
2022-04-25 10:29:41 +08:00

93 lines
2.7 KiB
TypeScript

import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { SFComponent, SFSchema } from '@delon/form';
import { fromEvent, Subscription } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { SearchDrawerService } from 'src/app/shared/components/search-drawer/search-drawer.service';
@Component({
template: ''
})
export class BasicTableComponent implements AfterViewInit, OnDestroy {
scrollY = '400px';
sf!: SFComponent;
sfValue: Record<string, any> = {};
drawer: Subscription[] = [];
schema: SFSchema = {};
constructor(public searchDrawerService: SearchDrawerService) {}
ngAfterViewInit(): void {
setTimeout(() => {
this.getScrollY();
}, 100);
fromEvent(window, 'resize')
.pipe(debounceTime(100))
.subscribe(event => {
this.getScrollY();
});
}
ngOnDestroy(): void {
this.drawer.forEach(sub => sub.unsubscribe());
}
openDrawer() {
if (this.drawer?.length > 0) {
this.searchDrawerService.create(this.sfValue, this.schema);
} else {
const drawer = this.searchDrawerService.create(this.sfValue, this.schema);
this.drawer.push(
drawer.initEvent.subscribe(sf => {
if (sf) {
this.sf = sf;
}
})
);
this.drawer.push(
drawer.closeEvent.subscribe(res => {
this.sfValue = res;
if (res) {
this.search();
}
})
);
}
}
getScrollY() {
const windowHeight = window.innerHeight || Math.max(document.documentElement.clientHeight, document.body.clientHeight);
const header = document.getElementsByTagName('layout-pro-header')?.[0];
if (windowHeight && header) {
let scrollY = windowHeight - header.clientHeight - 35 - 49;
// 剔除页头高度
const headerWrapper = document.getElementsByTagName('page-header-wrapper')?.[0];
if (headerWrapper) {
scrollY -= headerWrapper.clientHeight;
}
// 计算所有tabs高度
const tabset = document.getElementsByTagName('nz-tabset');
let tabsetHeight = 0;
for (let index = 0; index < tabset.length; index++) {
tabsetHeight += tabset[index].clientHeight;
}
if (tabset) {
scrollY -= tabsetHeight;
}
// 剔除高度容器
// 计算所有tabs高度
const headerBox = document.getElementsByClassName('header_box');
let headerBoxHeight = 0;
for (let index = 0; index < headerBox.length; index++) {
headerBoxHeight += headerBox[index].clientHeight;
}
if (headerBox) {
scrollY -= headerBoxHeight;
}
this.scrollY = scrollY + 'px';
}
}
search() {}
}