Skip to content

Commit

Permalink
代码整理
Browse files Browse the repository at this point in the history
  • Loading branch information
1-2-3 committed Feb 4, 2021
1 parent c343369 commit 8960e86
Show file tree
Hide file tree
Showing 50 changed files with 647 additions and 830 deletions.
17 changes: 17 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# add files you wish to ignore here
**/*.md
**/*.svg
**/test.ts

.stylelintrc
.prettierrc

src/index.html
node_modules/
.vscode/
coverage/
dist/
package.json
tslint.json

mock/*
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"printWidth": 120,
"singleQuote": true,
"semi": true,
"trailingComma": "all",
"tabWidth": 2,
"proseWrap": "never"
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import { NsFormErrorTipService } from '../service/ns-form-error-tip.service';
import { NsFormErrorType } from '../service/ns-form-error-type';

@Component({
// tslint:disable-next-line: component-selector
selector: 'ns-form-error-tips',
template: `
<ng-template #errorTpl let-control>
<ng-container *ngFor="let err of errorTypes">
<ng-container *ngIf="control.hasError(err.errorType)">
{{
control.getError(err.errorType)?.msg
? control.getError(err.errorType)?.msg
: err.defaultMessage
}}
{{ control.getError(err.errorType)?.msg ? control.getError(err.errorType)?.msg : err.defaultMessage }}
</ng-container>
</ng-container>
</ng-template>
`
`,
})
export class NsFormErrorTipsComponent {
@ViewChild('errorTpl', { static: true }) _errorTpl;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import {
Directive,
ElementRef,
Input,
Renderer2,
HostListener,
} from '@angular/core';
import { Directive, ElementRef, Input, Renderer2, HostListener, OnInit, AfterViewInit } from '@angular/core';

/**
* 自适应页面高度的Card。
* 将此指令放置到 Card 组件上,Card组件高度即可自适应页面高度,例:<nz-card nsAutoHeightCard>
* 可设置自定义间距值,例:<nz-card nsAutoHeightCard="100">
*/
@Directive({
// tslint:disable-next-line: directive-selector
selector: '[nsAutoHeightCard]',
})
export class NsAutoHeightCardDirective {
export class NsAutoHeightCardDirective implements OnInit, AfterViewInit {
private _offset = 27;

constructor(private el: ElementRef, private renderer: Renderer2) {}
Expand All @@ -23,7 +18,6 @@ export class NsAutoHeightCardDirective {

/**
* 响应浏览器窗体大小变化
* @param event
*/
@HostListener('window:resize', ['$event'])
onResize() {
Expand All @@ -39,11 +33,7 @@ export class NsAutoHeightCardDirective {
const card = this.el.nativeElement;
const bodyDiv = card.querySelector('.ant-card-body');
let bodyTop = 0;
if (
bodyDiv &&
bodyDiv.getBoundingClientRect &&
bodyDiv.getBoundingClientRect().top
) {
if (bodyDiv && bodyDiv.getBoundingClientRect && bodyDiv.getBoundingClientRect().top) {
bodyTop = bodyDiv.getBoundingClientRect().top;
}

Expand All @@ -57,7 +47,7 @@ export class NsAutoHeightCardDirective {

@Input()
set nsAutoHeightCard(v: any) {
const value = parseInt(v);
const value = parseInt(v, 0);
if (!isNaN(value) && value >= 0) {
this._offset = value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import {
Directive,
ElementRef,
Input,
Renderer2,
OnInit,
AfterViewInit,
DoCheck,
} from '@angular/core';
import { Directive, ElementRef, Input, Renderer2, OnInit, AfterViewInit, DoCheck } from '@angular/core';

/**
* 自适应页面高度的Div。
* 将此指令放置到 Div 组件上,Div组件高度即可自适应页面高度,例:<div ncFullHeightDiv>
* 如果希望修改底部间距,可设置自定义间距值,例:<div ncFullHeightDiv="100">
*/
@Directive({
// tslint:disable-next-line: directive-selector
selector: '[nsAutoHeightDiv]',
})
export class NsAutoHeightDivDirective
implements OnInit, AfterViewInit, DoCheck {
export class NsAutoHeightDivDirective implements OnInit, AfterViewInit, DoCheck {
private _offset = 27;
private divTop = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
Input,
HostListener,
ChangeDetectorRef,
OnInit,
AfterViewInit,
} from '@angular/core';
import { STComponent } from '@delon/abc/st';

Expand All @@ -15,24 +17,19 @@ import { STComponent } from '@delon/abc/st';
* 需要自定义偏移量时,可使用:<st nsAutoHeightST="100"></st>
*/
@Directive({
// tslint:disable-next-line: directive-selector
selector: '[nsAutoHeightST]',
host: {},
})
export class NsAutoHeightSTDirective {
export class NsAutoHeightSTDirective implements OnInit, AfterViewInit {
@Input('nsAutoHeightST')
offset: number;

constructor(
private element: ElementRef,
private table: STComponent,
private cd: ChangeDetectorRef
) {}
constructor(private element: ElementRef, private table: STComponent, private cd: ChangeDetectorRef) {}

ngOnInit() {}

/**
* 响应浏览器窗体大小变化
* @param event
*/
@HostListener('window:resize', ['$event'])
onResize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
SimpleChange,
HostListener,
ChangeDetectorRef,
OnInit,
AfterViewInit,
} from '@angular/core';
import { NzTableComponent } from 'ng-zorro-antd/table';

Expand All @@ -16,24 +18,18 @@ import { NzTableComponent } from 'ng-zorro-antd/table';
* 需要自定义偏移量时,可使用:<st ncSimpleTableAutoScroll="100"></st>
*/
@Directive({
// tslint:disable-next-line: directive-selector
selector: '[nsAutoHeightTable]',
host: {},
})
export class NsAutoHeightTableDirective {
export class NsAutoHeightTableDirective implements OnInit, AfterViewInit {
@Input('nsAutoHeightTable')
offset: number;

constructor(
private element: ElementRef,
private table: NzTableComponent,
private cd: ChangeDetectorRef
) {
constructor(private element: ElementRef, private table: NzTableComponent, private cd: ChangeDetectorRef) {
// 当前页码改变时自动回到顶部
if (this.table && this.table.nzPageIndexChange) {
this.table.nzPageIndexChange.subscribe((index) => {
const tableBody = this.element.nativeElement.querySelector(
'.ant-table-body'
);
const tableBody = this.element.nativeElement.querySelector('.ant-table-body');
if (tableBody && tableBody.scrollTop) {
tableBody.scrollTop = 0;
}
Expand All @@ -43,7 +39,6 @@ export class NsAutoHeightTableDirective {

/**
* 响应浏览器窗体大小变化
* @param event
*/
@HostListener('window:resize', ['$event'])
onResize() {
Expand All @@ -66,9 +61,7 @@ export class NsAutoHeightTableDirective {
this.element.nativeElement.parentElement.offsetHeight
) {
if (this.table && this.table.nzScroll && this.table.nzScroll.x) {
const originNzScroll = this.table.nzScroll
? { ...this.table.nzScroll }
: null;
const originNzScroll = this.table.nzScroll ? { ...this.table.nzScroll } : null;
this.table.nzScroll = {
y:
(
Expand All @@ -79,17 +72,11 @@ export class NsAutoHeightTableDirective {
x: this.table.nzScroll.x,
};
this.table.ngOnChanges({
nzScroll: new SimpleChange(
{ originNzScroll },
this.table.nzScroll,
false
),
nzScroll: new SimpleChange({ originNzScroll }, this.table.nzScroll, false),
});
this.cd.detectChanges();
} else {
const originNzScroll = this.table.nzScroll
? { ...this.table.nzScroll }
: null;
const originNzScroll = this.table.nzScroll ? { ...this.table.nzScroll } : null;
this.table.nzScroll = {
...{
y:
Expand All @@ -102,11 +89,7 @@ export class NsAutoHeightTableDirective {
};

this.table.ngOnChanges({
nzScroll: new SimpleChange(
{ originNzScroll },
this.table.nzScroll,
false
),
nzScroll: new SimpleChange({ originNzScroll }, this.table.nzScroll, false),
});
this.cd.detectChanges();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { Directive, ElementRef, Input, Renderer2 } from "@angular/core";
import { NzTabSetComponent } from "ng-zorro-antd/tabs";
import { AfterViewInit, Directive, ElementRef, HostListener, Input, OnInit, Renderer2 } from '@angular/core';
import { NzTabSetComponent } from 'ng-zorro-antd/tabs';

/**
* 自适应页面高度的标签页。
* 将此指令放置到标签页组件上,组件高度即可自适应页面高度,例:<nz-tabset nsAutoHeightTabset>
* 如果希望修改底部间距,可设置自定义间距值,例:<nz-card nsAutoHeightTabset="100">
*/
@Directive({
selector: "[nsAutoHeightTabset]",
// tslint:disable-next-line: directive-selector
selector: '[nsAutoHeightTabset]',
})
export class NsAutoHeightTabsetDirective {
export class NsAutoHeightTabsetDirective implements OnInit, AfterViewInit {
private _offset = 27;

constructor(
private el: ElementRef,
private renderer: Renderer2,
private cmp: NzTabSetComponent
) {}
constructor(private el: ElementRef, private renderer: Renderer2, private cmp: NzTabSetComponent) {}

ngOnInit() {
if (this.cmp && this.cmp.nzSelectChange) {
Expand All @@ -30,32 +27,36 @@ export class NsAutoHeightTabsetDirective {
this.resetHeightOfTabs();
}

/**
* 响应浏览器窗体大小变化
*/
@HostListener('window:resize', ['$event'])
onResize() {
this.resetHeightOfTabs();
}

private resetHeightOfTabs() {
setTimeout(() => {
const tabset = this.el.nativeElement;
const tabpaneList = tabset.querySelectorAll(".ant-tabs-tabpane");
const tabpaneList = tabset.querySelectorAll('.ant-tabs-tabpane');
for (const tabpane of tabpaneList) {
let tabpaneTop = 0;
if (
tabpane &&
tabpane.getBoundingClientRect &&
tabpane.getBoundingClientRect().top
) {
if (tabpane && tabpane.getBoundingClientRect && tabpane.getBoundingClientRect().top) {
tabpaneTop = tabpane.getBoundingClientRect().top;
}

if (tabpane) {
const topOffset = tabpaneTop + this._offset;
tabpane.style.height = `calc(100vh - ${topOffset}px)`;
tabpane.style["overflow-y"] = "auto"; // 自动出竖向滚动条
tabpane.style['overflow-y'] = 'auto'; // 自动出竖向滚动条
}
}
}, 2);
}

@Input()
set nsAutoHeightTabset(v: any) {
const value = parseInt(v);
const value = parseInt(v, 0);
if (!isNaN(value) && value >= 0) {
this._offset = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
ɵstringify as stringify,
ElementRef,
ComponentFactoryResolver,
Type
Type,
OnInit,
} from '@angular/core';
import { FormControl } from '@angular/forms';
import { NzFormControlComponent } from 'ng-zorro-antd/form';
Expand All @@ -19,23 +20,22 @@ import { NsFormErrorTipsComponent } from '../components/ns-form-error-tips.compo
* 自动附加验证错误信息模板
*/
@Directive({
selector: '[nsErrorTip]'
// tslint:disable-next-line: directive-selector
selector: '[nsErrorTip]',
})
export class NsErrorTipDirective {
export class NsErrorTipDirective implements OnInit {
constructor(
private viewContainer: ViewContainerRef,
private formControl: NzFormControlComponent,
private componentFactoryResolver: ComponentFactoryResolver
private componentFactoryResolver: ComponentFactoryResolver,
) {}

ngOnInit() {
this.loadComponent();
}

loadComponent() {
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(
NsFormErrorTipsComponent
);
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(NsFormErrorTipsComponent);
const componentRef = this.viewContainer.createComponent(componentFactory);
const errorTpl = (componentRef.instance as NsFormErrorTipsComponent).errorTpl;
this.formControl.nzErrorTip = errorTpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import { NsFlipDirective } from './ns-flip.directive';
* 标识使用按钮翻转卡片
*/
@Directive({
// tslint:disable-next-line: directive-selector
selector: '[nsFlipTrigger]',
})
export class NsFlipTriggerDirective {
constructor() {}

ngOnInit() {}

ngAfterViewInit() {}

@Input()
set nsFlipTrigger(v: any) {}
}
Loading

0 comments on commit 8960e86

Please sign in to comment.