|
|
@@ -4,6 +4,15 @@ import { MatButtonModule } from '@angular/material/button';
|
|
4
|
4
|
import { MatIconModule } from '@angular/material/icon';
|
|
5
|
5
|
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|
6
|
6
|
|
|
|
7
|
+export interface StickyHeaderButton {
|
|
|
8
|
+ title: string; // 显示文本
|
|
|
9
|
+ name: string; // 标识符(事件返回)
|
|
|
10
|
+ icon?: string; // 可选图标
|
|
|
11
|
+ color?: 'primary' | 'accent' | 'warn';
|
|
|
12
|
+ disabled?: boolean;
|
|
|
13
|
+ loading?: boolean;
|
|
|
14
|
+}
|
|
|
15
|
+
|
|
7
|
16
|
@Component({
|
|
8
|
17
|
selector: 'app-sticky-header',
|
|
9
|
18
|
standalone: true,
|
|
|
@@ -35,6 +44,9 @@ export class StickyHeaderComponent implements AfterViewInit, OnDestroy {
|
|
35
|
44
|
/** 按钮颜色,默认primary */
|
|
36
|
45
|
@Input() buttonColor: 'primary' | 'accent' | 'warn' = 'primary';
|
|
37
|
46
|
|
|
|
47
|
+ /** 多个按钮配置,如果设置则忽略单个按钮属性 */
|
|
|
48
|
+ @Input() buttons: StickyHeaderButton[] = [];
|
|
|
49
|
+
|
|
38
|
50
|
/** 是否禁用按钮 */
|
|
39
|
51
|
@Input() disabled = false;
|
|
40
|
52
|
|
|
|
@@ -100,15 +112,27 @@ export class StickyHeaderComponent implements AfterViewInit, OnDestroy {
|
|
100
|
112
|
|
|
101
|
113
|
/** 按钮点击事件 */
|
|
102
|
114
|
@Output() buttonClick = new EventEmitter<void>();
|
|
|
115
|
+
|
|
|
116
|
+ /** 多个按钮点击事件,返回按钮name标识符 */
|
|
|
117
|
+ @Output() buttonAction = new EventEmitter<string>();
|
|
103
|
118
|
|
|
104
|
119
|
// 自动滚动检测的私有属性
|
|
105
|
120
|
private scrollListener: (() => void) | null = null;
|
|
106
|
121
|
private canScroll = false;
|
|
107
|
122
|
private isAutoDetecting = false;
|
|
108
|
123
|
|
|
109
|
|
- onButtonClick() {
|
|
110
|
|
- if (!this.disabled && !this.loading) {
|
|
111
|
|
- this.buttonClick.emit();
|
|
|
124
|
+ onButtonClick(name?: string) {
|
|
|
125
|
+ if (this.buttons.length > 0) {
|
|
|
126
|
+ // 多个按钮模式
|
|
|
127
|
+ const button = this.buttons.find(b => b.name === name);
|
|
|
128
|
+ if (button && !button.disabled && !button.loading) {
|
|
|
129
|
+ this.buttonAction.emit(name);
|
|
|
130
|
+ }
|
|
|
131
|
+ } else {
|
|
|
132
|
+ // 单个按钮模式(向后兼容)
|
|
|
133
|
+ if (!this.disabled && !this.loading) {
|
|
|
134
|
+ this.buttonClick.emit();
|
|
|
135
|
+ }
|
|
112
|
136
|
}
|
|
113
|
137
|
}
|
|
114
|
138
|
|