Skip to content

Commit 7115f5c

Browse files
hpyourdkmaster
authored andcommitted
[新增]Box增加viewInit静态事件,用于监听box整体布局样式的初始化 (#722)
1 parent f0c678e commit 7115f5c

File tree

6 files changed

+93
-1
lines changed

6 files changed

+93
-1
lines changed

src/app/demo/box/demo-set.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {BoxLayoutScrollDemoComponent} from "./scroll/demo.component";
1010
import {BoxLayoutScrollDemoModule} from "./scroll/demo.module";
1111
import {BoxMiddleResizeLineDemoComponent} from "./middle-resize-line/demo.component";
1212
import {BoxMiddleResizeLineDemoModule} from "./middle-resize-line/demo.module";
13+
import {BoxViewInitDemoComponent} from "./view-init/demo.component";
14+
import {BoxViewInitDemoModule} from "./view-init/demo.module";
1315

1416
export const routerConfig = [
1517
{
@@ -27,6 +29,9 @@ export const routerConfig = [
2729
{
2830
path: 'middle-resize-line', component: BoxMiddleResizeLineDemoComponent
2931
},
32+
{
33+
path: 'view-init', component: BoxViewInitDemoComponent
34+
},
3035
];
3136

3237
@NgModule({
@@ -36,7 +41,8 @@ export const routerConfig = [
3641
BoxLayoutDemoModule,
3742
FormDemoModule,
3843
BoxLayoutScrollDemoModule,
39-
BoxMiddleResizeLineDemoModule
44+
BoxMiddleResizeLineDemoModule,
45+
BoxViewInitDemoModule
4046
]
4147
})
4248
export class BoxDemoModule {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
j-box {
3+
border: 1px solid #bbb;
4+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!-- ignore the following lines, they are not important to this demo -->
2+
<jigsaw-demo-description [summary]="summary" [content]="description">
3+
</jigsaw-demo-description>
4+
5+
6+
<!-- start to learn the demo from here -->
7+
<div class="live-demo-wrap">
8+
<h2>Box</h2>
9+
<div class="demo-1 live-demo">
10+
<h3>ViewInit事件</h3>
11+
<p class="comment">ViewInit事件是box框架初始化完成,即整个布局初始化完成。有时graph会在box渲染完成之前先渲染,
12+
导致graph的尺寸和box最终的尺寸不一致。这个时候可以监听box的ViewInit事件来进行resize</p>
13+
<j-box height="400">
14+
<j-box>
15+
<jigsaw-graph [data]="lineBarData"></jigsaw-graph>
16+
</j-box>
17+
<j-box>
18+
<jigsaw-graph [data]="lineBarData"></jigsaw-graph>
19+
</j-box>
20+
</j-box>
21+
</div>
22+
</div>
23+
24+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {Component} from "@angular/core";
2+
import {LineGraphData} from "../../../../jigsaw/core/data/graph-data";
3+
import {JigsawBox} from "../../../../jigsaw/component/box/box";
4+
5+
@Component({
6+
templateUrl: './demo.component.html',
7+
styleUrls: ['./demo.component.css']
8+
})
9+
export class BoxViewInitDemoComponent {
10+
lineBarData: LineGraphData;
11+
constructor() {
12+
this.lineBarData = new LineGraphData();
13+
this.lineBarData.rowDescriptor = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
14+
this.lineBarData.header = ['邮件营销', '联盟广告', '视频广告', '直接访问', '搜索引擎'];
15+
this.lineBarData.data = [
16+
[120, 220, 150, 320, 820],
17+
[132, 182, 232, 332, 932],
18+
[101, 191, 201, 301, 901],
19+
[134, 234, 154, 334, 934],
20+
[90, 290, 190, 390, 1290],
21+
[230, 330, 330, 330, 1330],
22+
[210, 310, 410, 320, 1320]
23+
];
24+
JigsawBox.viewInit.subscribe(() => {
25+
let e = document.createEvent("Event");
26+
e.initEvent("resize", true, true);
27+
window.dispatchEvent(e);
28+
})
29+
}
30+
31+
// ====================================================================
32+
// ignore the following lines, they are not important to this demo
33+
// ====================================================================
34+
summary: string = '这个DEMO演示了在内容溢出后,j-box在滚动条方面的行为,以及如何添加自定义滚动条';
35+
description: string = '';
36+
tags: string[] = [
37+
'JigsawBox',
38+
'PerfectScrollbarDirective'
39+
];
40+
}
41+
42+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {NgModule} from "@angular/core";
2+
import {JigsawBoxModule} from "jigsaw/component/box/index";
3+
import {JigsawDemoDescriptionModule} from "app/demo-description/demo-description";
4+
import {BoxViewInitDemoComponent} from "./demo.component";
5+
import {JigsawGraphModule} from "jigsaw/component/graph/index";
6+
7+
@NgModule({
8+
declarations: [BoxViewInitDemoComponent],
9+
exports: [BoxViewInitDemoComponent],
10+
imports: [JigsawDemoDescriptionModule, JigsawBoxModule, JigsawGraphModule]
11+
})
12+
export class BoxViewInitDemoModule {
13+
14+
}

src/jigsaw/component/box/box.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class JigsawBox extends JigsawResizableBoxBase implements AfterContentIni
2323

2424
public static resizeEnd = new EventEmitter();
2525
public static resizeStart = new EventEmitter();
26+
public static viewInit = new EventEmitter();
2627

2728
@Input()
2829
public resizable: boolean;
@@ -169,6 +170,7 @@ export class JigsawBox extends JigsawResizableBoxBase implements AfterContentIni
169170

170171
this.callLater(() => {
171172
this._$isFlicker = false;
173+
if(!this.parent) JigsawBox.viewInit.emit();
172174
});
173175
}
174176

0 commit comments

Comments
 (0)