Skip to content

Commit

Permalink
perf: 完善左侧组件
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeard30 committed Mar 29, 2024
1 parent 637a6c9 commit d502711
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/app/pages/home/register.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Injectable, Input, OnChanges, signal, SimpleChanges, ViewContainerRef } from '@angular/core';
import { TreeNode } from '../../core/models';
import { NgIf } from '@angular/common';

@Component({
selector: 'app-field',
Expand Down Expand Up @@ -36,6 +37,56 @@ export class FieldWidget implements OnChanges {
}
}

@Component({
selector: 'app-card',
template: `
<div [style]="currentStyle()">
<span *ngIf="!hasContent()">拖拽字段进入该区域</span>
<ng-content></ng-content>
</div>
`,
imports: [NgIf],
standalone: true
})
export class CardWidget implements OnChanges {
@Input() node: TreeNode;

@Input() style: { [p: string]: any };

currentStyle = signal({
width: '200px',
height: '100px',
background: '#eee',
border: '1px solid #ddd',
display: 'flex',
padding: '10px',
justifyContent: 'center',
alignItems: 'center'
});

constructor(private viewContainerRef: ViewContainerRef) {}

hasContent() {
return !!this.viewContainerRef.length;
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.style && changes.style.currentValue) {
this.currentStyle.set({
width: '200px',
height: '100px',
background: '#eee',
border: '1px solid #ddd',
display: 'flex',
padding: '10px',
justifyContent: 'center',
alignItems: 'center',
...this.style
});
}
}
}

@Injectable({
providedIn: 'root'
})
Expand All @@ -44,6 +95,7 @@ export class WidgetFactory {

constructor() {
this.register('Field', FieldWidget);
this.register('Card', CardWidget);
}

register(name: string, component: any) {
Expand Down

0 comments on commit d502711

Please sign in to comment.