Browse Source

添加按钮

qdy 1 month ago
parent
commit
1e0ea898a3

+ 2
- 4
src/app/pages/service-register-config/service-register-config.component.html View File

@@ -2,16 +2,14 @@
2 2
   <app-sticky-header
3 3
     [title]="title"
4 4
     [hintText]="hintText"
5
-    [buttonText]="'注册'"
6
-    [buttonIcon]="'add'"
7
-    [buttonColor]="'primary'"
5
+    [buttons]="headerButtons"
8 6
     [showDebugInfo]="true"
9 7
     [autoDetect]="true"
10 8
     [scrollContainer]="'.content-area'"
11 9
     [scrollThreshold]="20"
12 10
     [compactThreshold]="80"
13 11
     [widthTarget]="'#tabulator-table'"
14
-    (buttonClick)="onRegister()"
12
+    (buttonAction)="onHeaderButtonAction($event)"
15 13
   ></app-sticky-header>
16 14
   <!-- Tabulator 容器 -->
17 15
   <div id="tabulator-table" #matCard class="flex-1" ></div>

+ 65
- 36
src/app/pages/service-register-config/service-register-config.component.ts View File

@@ -3,7 +3,7 @@ import { Component, AfterViewInit, inject } from '@angular/core';
3 3
 import { ConfigMetaService } from '../../services/config-meta.service';
4 4
 import { AuthService } from '../../services/auth.service';
5 5
 import { TabulatorMapper } from '../../utils/tabulator-mapper.util';
6
-import { ConfigService, StickyHeaderComponent } from 'base-core';
6
+import { ConfigService, StickyHeaderComponent, StickyHeaderButton } from 'base-core';
7 7
 import { CommonModule } from '@angular/common';
8 8
 
9 9
 // 声明全局类型
@@ -23,9 +23,13 @@ export class ServiceRegisterConfigComponent implements AfterViewInit {
23 23
   private config = inject(ConfigService);
24 24
   private authService = inject(AuthService);
25 25
   
26
-  title = '注册服务配置';
27
-  hintText = '点击"注册"按钮将同步所有配置元信息到数据库,并显示配置列表。';
28
-  registering = false;
26
+   title = '注册服务配置';
27
+   hintText = '点击"注册"按钮将同步所有配置元信息到数据库,并显示配置列表。';
28
+   headerButtons: StickyHeaderButton[] = [
29
+     { title: '注册', name: 'register', icon: 'add', color: 'primary' },
30
+     { title: '刷新', name: 'refresh', icon: 'refresh', color: 'accent' }
31
+   ];
32
+   registering = false;
29 33
 
30 34
   ngAfterViewInit(): void {
31 35
     console.log('ServiceRegisterConfigComponent ngAfterViewInit');
@@ -207,40 +211,65 @@ export class ServiceRegisterConfigComponent implements AfterViewInit {
207 211
   }
208 212
   
209 213
 
210
-  onRegister() {
211
-     console.log('注册按钮被点击');
212
-     this.registering = true;
213
-     
214
-     this.configMetaService.initConfigMeta().subscribe({
215
-       next: (result: any) => {
216
-         this.registering = false;
217
-         //this.errorMessage = null;
218
-         if (result.success) {
219
-           console.log('注册完成:', result.data);
220
-           
221
-           // 注册后切换到真实API数据
222
-           //this.debugInfo.useMockData = false;
223
-           //this.updateDataConfig();
224
-           
225
-           // 重新加载数据
226
-           //this.loadData(1);
227
-           
228
-           console.log('注册成功,数据已重新加载');
229
-         } else {
230
-           console.error('注册失败:', result);
231
-         }
232
-       },
214
+   onRegister() {
215
+      console.log('注册按钮被点击');
216
+      this.registering = true;
217
+      this.headerButtons[0].loading = true;
233 218
       
234
-     });
235
-   }
236
-  /**
237
-   * 刷新表格 - 重新加载数据
238
-   */
239
-  refresh(): void {
240
-    if (this.tabulator) {
241
-      this.tabulator.replaceData();
219
+      this.configMetaService.initConfigMeta().subscribe({
220
+        next: (result: any) => {
221
+          this.registering = false;
222
+          this.headerButtons[0].loading = false;
223
+          //this.errorMessage = null;
224
+          if (result.success) {
225
+            console.log('注册完成:', result.data);
226
+            
227
+            // 注册后切换到真实API数据
228
+            //this.debugInfo.useMockData = false;
229
+            //this.updateDataConfig();
230
+            
231
+            // 重新加载数据
232
+            //this.loadData(1);
233
+            
234
+            console.log('注册成功,数据已重新加载');
235
+          } else {
236
+            console.error('注册失败:', result);
237
+          }
238
+        },
239
+        error: (error) => {
240
+          this.registering = false;
241
+          this.headerButtons[0].loading = false;
242
+          console.error('注册请求失败:', error);
243
+        }
244
+      });
242 245
     }
243
-  }
246
+    
247
+    onHeaderButtonAction(name: string) {
248
+      console.log(`头部按钮点击: ${name}`);
249
+      switch (name) {
250
+        case 'register':
251
+          this.onRegister();
252
+          break;
253
+        case 'refresh':
254
+          this.refresh();
255
+          break;
256
+        default:
257
+          console.warn(`未知按钮操作: ${name}`);
258
+      }
259
+    }
260
+   /**
261
+    * 刷新表格 - 重新加载数据
262
+    */
263
+   refresh(): void {
264
+     if (this.tabulator) {
265
+       this.headerButtons[1].loading = true;
266
+       this.tabulator.replaceData();
267
+       // 简单延迟后清除loading状态
268
+       setTimeout(() => {
269
+         this.headerButtons[1].loading = false;
270
+       }, 500);
271
+     }
272
+   }
244 273
   
245 274
   /**
246 275
    * 重置筛选和排序

Loading…
Cancel
Save