Skip to content

fix(NavSprite): Repetitive dependency injection and supplementary notes #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions devui/nav-sprite/nav-sprite.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class NavSpriteComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChildren('items', { read: ElementRef })
items!: QueryList<ElementRef>;

@Output() afterNavInit = new EventEmitter(); // 组件初始化后返回组件实例
@Output() afterNavInit = new EventEmitter<NavSpriteComponent>(); // 组件初始化后返回组件实例

currentTemp: TemplateRef<any>;

Expand All @@ -84,7 +84,7 @@ export class NavSpriteComponent implements OnInit, AfterViewInit, OnDestroy {

itemsInit = false;

contents;
contents: HTMLElement[];

targetContainer: HTMLElement;

Expand All @@ -98,8 +98,6 @@ export class NavSpriteComponent implements OnInit, AfterViewInit, OnDestroy {

timeGap = 60;

document: Document;

get baseUrl() {
if (typeof window === 'undefined') {
return '';
Expand All @@ -112,11 +110,9 @@ export class NavSpriteComponent implements OnInit, AfterViewInit, OnDestroy {
private element: ElementRef,
private router: Router,
private activeRout: ActivatedRoute,
private render2: Renderer2,
private cdr: ChangeDetectorRef,
@Inject(DOCUMENT) private doc: any
@Inject(DOCUMENT) private document: Document
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

构建会有报错,建议将document类型暂时修改为any或采用其它更好解决方式
image

Copy link
Member

@kagol kagol Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

构建会有报错,建议将document类型暂时修改为any或采用其它更好解决方式 image

@Simplelegant 可以考虑将构建加到PR门禁里,这样PR的作者能够立即知道他自己提交的PR是否能通过构建任务,参考vue-devui的:
pull-request.yml

) {
this.document = this.doc;
}

ngOnInit() {
Expand Down Expand Up @@ -176,10 +172,10 @@ export class NavSpriteComponent implements OnInit, AfterViewInit, OnDestroy {
search.push(`h${i + 1}`);
}
this.contents = Array.from(this.target.querySelectorAll(search.join(',')));
this.menus = this.contents.map((i: HTMLElement) => {
this.menus = this.contents.map((i) => {
return {
originEle: i,
level: i.tagName.match(/\d+/)[0],
level: +i.tagName.match(/\d+/)[0],
label: i.innerText,
href: this.baseUrl + '#' + i.innerText,
scrollPosition: this.getScrollPosition(i),
Expand Down Expand Up @@ -260,10 +256,10 @@ export class NavSpriteComponent implements OnInit, AfterViewInit, OnDestroy {
const target = this.menus[this.activeIndex];
this.menus.forEach((i) => {
if (i.originEle) {
this.render2.removeClass(i.originEle, 'nav-active');
this.render.removeClass(i.originEle, 'nav-active');
}
});
this.render2.addClass(target?.originEle, 'nav-active');
this.render.addClass(target?.originEle, 'nav-active');
}

navTo(index) {
Expand Down
1 change: 1 addition & 0 deletions devui/nav-sprite/nav-sprite.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface NavMenu {
originEle: HTMLElement;
label: string;
level: number;
href: string;
scrollPosition: {
top: number;
startLine: number
Expand Down