|
|
@@ -1,8 +1,8 @@
|
|
1
|
|
-import { Component, OnInit } from '@angular/core';
|
|
|
1
|
+import { Component, OnInit, HostListener, ChangeDetectorRef, AfterViewInit, ElementRef, Renderer2, OnDestroy, ViewChild } from '@angular/core';
|
|
|
2
|
+import { StickyHeaderComponent } from '../../components/sticky-header/sticky-header.component';
|
|
2
|
3
|
import { CommonModule } from '@angular/common';
|
|
3
|
4
|
import { MatCard, MatCardContent } from '@angular/material/card';
|
|
4
|
|
-import { MatButton } from '@angular/material/button';
|
|
5
|
|
-import { MatIcon } from '@angular/material/icon';
|
|
|
5
|
+
|
|
6
|
6
|
import { MatTableModule } from '@angular/material/table';
|
|
7
|
7
|
import { MatProgressSpinner } from '@angular/material/progress-spinner';
|
|
8
|
8
|
import { ConfigMetaService } from '../../services/config-meta.service';
|
|
|
@@ -13,16 +13,26 @@ import { HttpErrorResponse } from '@angular/common/http';
|
|
13
|
13
|
|
|
14
|
14
|
@Component({
|
|
15
|
15
|
selector: 'app-service-register-config',
|
|
16
|
|
- imports: [CommonModule, MatCard, MatCardContent, MatButton, MatIcon, MatTableModule, MatProgressSpinner],
|
|
|
16
|
+ imports: [CommonModule, MatCard, MatCardContent, MatTableModule, MatProgressSpinner, StickyHeaderComponent],
|
|
17
|
17
|
templateUrl: './service-register-config.component.html',
|
|
18
|
18
|
styleUrl: './service-register-config.component.scss'
|
|
19
|
19
|
})
|
|
20
|
|
-export class ServiceRegisterConfigComponent implements OnInit {
|
|
|
20
|
+export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, OnDestroy {
|
|
21
|
21
|
title = '注册服务配置';
|
|
|
22
|
+ hintText = '点击"注册"按钮将同步所有配置元信息到数据库,并显示配置列表。';
|
|
22
|
23
|
displayedColumns: string[] = ['configName', 'fieldName', 'fieldType', 'yamlName', 'fieldDesc'];
|
|
23
|
24
|
configMetaList: ConfigMeta[] = [];
|
|
24
|
25
|
loading = false;
|
|
25
|
26
|
registering = false;
|
|
|
27
|
+ isScrolled = false; // 向后兼容
|
|
|
28
|
+ isLocked = false; // 是否锁定在顶部
|
|
|
29
|
+ isCompact = false; // 是否缩小状态
|
|
|
30
|
+ scrollThreshold = 2; // 锁定阈值
|
|
|
31
|
+ compactThreshold = 50; // 缩小阈值(锁定后进一步滚动多少像素开始缩小)
|
|
|
32
|
+
|
|
|
33
|
+ private scrollContainer: HTMLElement | Window = window;
|
|
|
34
|
+ private scrollListener: (() => void) | null = null;
|
|
|
35
|
+ private rafId: number | null = null;
|
|
26
|
36
|
|
|
27
|
37
|
debugInfo = {
|
|
28
|
38
|
dataSource: '',
|
|
|
@@ -31,19 +41,212 @@ export class ServiceRegisterConfigComponent implements OnInit {
|
|
31
|
41
|
useMockData: false
|
|
32
|
42
|
};
|
|
33
|
43
|
|
|
|
44
|
+ @ViewChild('matCard', { read: ElementRef }) matCardRef!: ElementRef;
|
|
|
45
|
+ headerWidth: number | null = null;
|
|
|
46
|
+ headerLeft: number | null = null;
|
|
|
47
|
+ private resizeListener: (() => void) | null = null;
|
|
|
48
|
+
|
|
34
|
49
|
lastRegisterUrl = '';
|
|
35
|
50
|
lastListUrl = '';
|
|
36
|
51
|
|
|
37
|
52
|
constructor(
|
|
38
|
53
|
private configMetaService: ConfigMetaService,
|
|
39
|
54
|
private configService: ConfigService,
|
|
40
|
|
- private toastService: ToastService
|
|
|
55
|
+ private toastService: ToastService,
|
|
|
56
|
+ private cdRef: ChangeDetectorRef,
|
|
|
57
|
+ private elementRef: ElementRef,
|
|
|
58
|
+ private renderer: Renderer2
|
|
41
|
59
|
) {}
|
|
42
|
60
|
|
|
43
|
61
|
ngOnInit() {
|
|
44
|
62
|
this.loadConfigMeta();
|
|
45
|
63
|
}
|
|
46
|
64
|
|
|
|
65
|
+ ngAfterViewInit() {
|
|
|
66
|
+ this.findScrollContainer();
|
|
|
67
|
+ this.setupScrollListener();
|
|
|
68
|
+ this.checkScroll();
|
|
|
69
|
+
|
|
|
70
|
+ // 添加窗口resize监听器
|
|
|
71
|
+ this.resizeListener = () => this.onResize();
|
|
|
72
|
+ window.addEventListener('resize', this.resizeListener, { passive: true });
|
|
|
73
|
+ }
|
|
|
74
|
+
|
|
|
75
|
+ private onResize() {
|
|
|
76
|
+ // 只在锁定状态时更新尺寸
|
|
|
77
|
+ if (this.isLocked && this.matCardRef?.nativeElement) {
|
|
|
78
|
+ console.log('窗口大小变化,更新标题栏尺寸');
|
|
|
79
|
+ this.updateHeaderDimensions();
|
|
|
80
|
+ }
|
|
|
81
|
+ }
|
|
|
82
|
+
|
|
|
83
|
+ ngOnDestroy() {
|
|
|
84
|
+ this.cleanupScrollListener();
|
|
|
85
|
+
|
|
|
86
|
+ // 清理resize监听器
|
|
|
87
|
+ if (this.resizeListener) {
|
|
|
88
|
+ window.removeEventListener('resize', this.resizeListener);
|
|
|
89
|
+ this.resizeListener = null;
|
|
|
90
|
+ }
|
|
|
91
|
+ }
|
|
|
92
|
+
|
|
|
93
|
+ @HostListener('window:scroll', [])
|
|
|
94
|
+ onWindowScroll() {
|
|
|
95
|
+ // 保留window滚动监听作为备用
|
|
|
96
|
+ if (this.scrollContainer === window) {
|
|
|
97
|
+ this.onScroll();
|
|
|
98
|
+ }
|
|
|
99
|
+ }
|
|
|
100
|
+
|
|
|
101
|
+ private findScrollContainer() {
|
|
|
102
|
+ // 向上查找最近的滚动容器
|
|
|
103
|
+ let element: HTMLElement | null = this.elementRef.nativeElement.parentElement;
|
|
|
104
|
+
|
|
|
105
|
+ while (element && element !== document.body) {
|
|
|
106
|
+ const style = getComputedStyle(element);
|
|
|
107
|
+ const hasOverflow = style.overflow === 'auto' || style.overflow === 'scroll' ||
|
|
|
108
|
+ style.overflowY === 'auto' || style.overflowY === 'scroll';
|
|
|
109
|
+
|
|
|
110
|
+ if (hasOverflow) {
|
|
|
111
|
+ console.log('找到滚动容器:', element, 'clientHeight:', element.clientHeight, 'scrollHeight:', element.scrollHeight);
|
|
|
112
|
+ this.scrollContainer = element;
|
|
|
113
|
+ return;
|
|
|
114
|
+ }
|
|
|
115
|
+
|
|
|
116
|
+ element = element.parentElement;
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ // 未找到合适的容器,使用window
|
|
|
120
|
+ console.log('未找到滚动容器,使用window');
|
|
|
121
|
+ this.scrollContainer = window;
|
|
|
122
|
+ }
|
|
|
123
|
+
|
|
|
124
|
+ private setupScrollListener() {
|
|
|
125
|
+ if (this.scrollContainer === window) {
|
|
|
126
|
+ this.scrollListener = () => this.onScroll();
|
|
|
127
|
+ window.addEventListener('scroll', this.scrollListener, { passive: true });
|
|
|
128
|
+ } else {
|
|
|
129
|
+ this.scrollListener = () => this.onScroll();
|
|
|
130
|
+ (this.scrollContainer as HTMLElement).addEventListener('scroll', this.scrollListener, { passive: true });
|
|
|
131
|
+ }
|
|
|
132
|
+ }
|
|
|
133
|
+
|
|
|
134
|
+ private cleanupScrollListener() {
|
|
|
135
|
+ if (this.scrollListener) {
|
|
|
136
|
+ if (this.scrollContainer === window) {
|
|
|
137
|
+ window.removeEventListener('scroll', this.scrollListener);
|
|
|
138
|
+ } else {
|
|
|
139
|
+ (this.scrollContainer as HTMLElement).removeEventListener('scroll', this.scrollListener);
|
|
|
140
|
+ }
|
|
|
141
|
+ this.scrollListener = null;
|
|
|
142
|
+ }
|
|
|
143
|
+
|
|
|
144
|
+ if (this.rafId !== null) {
|
|
|
145
|
+ cancelAnimationFrame(this.rafId);
|
|
|
146
|
+ this.rafId = null;
|
|
|
147
|
+ }
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
|
150
|
+ private onScroll() {
|
|
|
151
|
+ if (this.rafId !== null) {
|
|
|
152
|
+ cancelAnimationFrame(this.rafId);
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
|
155
|
+ this.rafId = requestAnimationFrame(() => {
|
|
|
156
|
+ this.checkScroll();
|
|
|
157
|
+ });
|
|
|
158
|
+ }
|
|
|
159
|
+
|
|
|
160
|
+ private updateHeaderDimensions() {
|
|
|
161
|
+ if (!this.matCardRef?.nativeElement) return;
|
|
|
162
|
+
|
|
|
163
|
+ const matCard = this.matCardRef.nativeElement;
|
|
|
164
|
+ const rect = matCard.getBoundingClientRect();
|
|
|
165
|
+
|
|
|
166
|
+ // 计算mat-card在视口中的位置和宽度
|
|
|
167
|
+ this.headerWidth = rect.width;
|
|
|
168
|
+ this.headerLeft = rect.left;
|
|
|
169
|
+
|
|
|
170
|
+ console.log('更新标题栏尺寸:', {
|
|
|
171
|
+ width: this.headerWidth,
|
|
|
172
|
+ left: this.headerLeft,
|
|
|
173
|
+ matCardRect: rect
|
|
|
174
|
+ });
|
|
|
175
|
+
|
|
|
176
|
+ this.cdRef.detectChanges();
|
|
|
177
|
+ }
|
|
|
178
|
+
|
|
|
179
|
+ private checkScroll() {
|
|
|
180
|
+ if (!this.scrollContainer) return;
|
|
|
181
|
+
|
|
|
182
|
+ let scrollTop = 0;
|
|
|
183
|
+ let containerType = 'unknown';
|
|
|
184
|
+
|
|
|
185
|
+ if (this.scrollContainer === window) {
|
|
|
186
|
+ scrollTop = window.scrollY || document.documentElement.scrollTop;
|
|
|
187
|
+ containerType = 'window';
|
|
|
188
|
+ } else {
|
|
|
189
|
+ scrollTop = (this.scrollContainer as HTMLElement).scrollTop;
|
|
|
190
|
+ containerType = 'element';
|
|
|
191
|
+ }
|
|
|
192
|
+
|
|
|
193
|
+ // 向后兼容:保持isScrolled逻辑
|
|
|
194
|
+ const scrolled = scrollTop > this.scrollThreshold;
|
|
|
195
|
+
|
|
|
196
|
+
|
|
|
197
|
+
|
|
|
198
|
+ // 阶段1: 检测是否锁定(开始滚动就锁定)
|
|
|
199
|
+ const shouldLock = scrollTop > 0;
|
|
|
200
|
+
|
|
|
201
|
+ // 阶段2: 检测是否缩小(锁定后继续滚动)
|
|
|
202
|
+ const shouldCompact = shouldLock && scrollTop > this.compactThreshold;
|
|
|
203
|
+
|
|
|
204
|
+ console.log('滚动检测:', {
|
|
|
205
|
+ container: containerType,
|
|
|
206
|
+ scrollTop,
|
|
|
207
|
+ scrollThreshold: this.scrollThreshold,
|
|
|
208
|
+ compactThreshold: this.compactThreshold,
|
|
|
209
|
+ shouldLock,
|
|
|
210
|
+ shouldCompact,
|
|
|
211
|
+ scrolled, // 向后兼容
|
|
|
212
|
+ isLocked: this.isLocked,
|
|
|
213
|
+ isCompact: this.isCompact
|
|
|
214
|
+ });
|
|
|
215
|
+
|
|
|
216
|
+ // 更新状态
|
|
|
217
|
+ let needsUpdate = false;
|
|
|
218
|
+
|
|
|
219
|
+ if (this.isScrolled !== scrolled) {
|
|
|
220
|
+ this.isScrolled = scrolled;
|
|
|
221
|
+ needsUpdate = true;
|
|
|
222
|
+ }
|
|
|
223
|
+
|
|
|
224
|
+ if (this.isLocked !== shouldLock) {
|
|
|
225
|
+ this.isLocked = shouldLock;
|
|
|
226
|
+ needsUpdate = true;
|
|
|
227
|
+ console.log('锁定状态变化:', this.isLocked);
|
|
|
228
|
+
|
|
|
229
|
+ if (this.isLocked) {
|
|
|
230
|
+ // 锁定状态:计算并更新标题栏尺寸
|
|
|
231
|
+ this.updateHeaderDimensions();
|
|
|
232
|
+ } else {
|
|
|
233
|
+ // 解锁状态:清除尺寸,让标题栏恢复原始定位
|
|
|
234
|
+ this.headerWidth = null;
|
|
|
235
|
+ this.headerLeft = null;
|
|
|
236
|
+ }
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+ if (this.isCompact !== shouldCompact) {
|
|
|
240
|
+ this.isCompact = shouldCompact;
|
|
|
241
|
+ needsUpdate = true;
|
|
|
242
|
+ console.log('缩小状态变化:', this.isCompact);
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ if (needsUpdate) {
|
|
|
246
|
+ this.cdRef.detectChanges();
|
|
|
247
|
+ }
|
|
|
248
|
+ }
|
|
|
249
|
+
|
|
47
|
250
|
onRegister() {
|
|
48
|
251
|
this.lastRegisterUrl = this.configMetaService.getInitUrl();
|
|
49
|
252
|
console.debug('[注册] 请求URL:', this.lastRegisterUrl);
|