Ver código fonte

改用新表格加载数据

qdy 1 mês atrás
pai
commit
a355be1029

+ 6
- 3
angular.json Ver arquivo

@@ -36,10 +36,13 @@
36 36
               }
37 37
             ],
38 38
             "styles": [
39
-              "src/styles.scss"
39
+              "src/styles.scss",
40
+              "node_modules/tabulator-tables/dist/css/tabulator.min.css"
41
+            ],
42
+            "scripts": [
43
+              "node_modules/tabulator-tables/dist/js/tabulator.min.js"
40 44
             ],
41
-            "scripts": [],
42
-            "allowedCommonJsDependencies": ["ag-grid-angular", "ag-grid-community"]
45
+            "allowedCommonJsDependencies": ["ag-grid-angular", "ag-grid-community", "tabulator-tables"]
43 46
           },
44 47
           "configurations": {
45 48
             "production": {

+ 16
- 6
package-lock.json Ver arquivo

@@ -21,10 +21,11 @@
21 21
         "@types/marked": "^5.0.2",
22 22
         "ag-grid-angular": "^35.0.0",
23 23
         "ag-grid-community": "^35.0.0",
24
+        "base-core": "file:../../ng-base/dist/base-core",
24 25
         "marked": "^17.0.1",
25
-        "ng-base": "file:../../ng-base/dist/ng-base",
26 26
         "prismjs": "^1.30.0",
27 27
         "rxjs": "~7.8.0",
28
+        "tabulator-tables": "^5.6.0",
28 29
         "tslib": "^2.3.0",
29 30
         "zone.js": "~0.15.0"
30 31
       },
@@ -46,7 +47,10 @@
46 47
         "typescript": "~5.7.2"
47 48
       }
48 49
     },
49
-    "../../ng-base/dist/ng-base": {},
50
+    "../../ng-base/dist/base-core": {},
51
+    "../../ng-base/dist/ng-base": {
52
+      "extraneous": true
53
+    },
50 54
     "node_modules/@alloc/quick-lru": {
51 55
       "version": "5.2.0",
52 56
       "resolved": "https://registry.npmjs.org/@alloc/quick-lru/-/quick-lru-5.2.0.tgz",
@@ -6477,6 +6481,10 @@
6477 6481
       "dev": true,
6478 6482
       "license": "MIT"
6479 6483
     },
6484
+    "node_modules/base-core": {
6485
+      "resolved": "../../ng-base/dist/base-core",
6486
+      "link": true
6487
+    },
6480 6488
     "node_modules/base64-js": {
6481 6489
       "version": "1.5.1",
6482 6490
       "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
@@ -11222,10 +11230,6 @@
11222 11230
       "dev": true,
11223 11231
       "license": "MIT"
11224 11232
     },
11225
-    "node_modules/ng-base": {
11226
-      "resolved": "../../ng-base/dist/ng-base",
11227
-      "link": true
11228
-    },
11229 11233
     "node_modules/node-addon-api": {
11230 11234
       "version": "6.1.0",
11231 11235
       "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-6.1.0.tgz",
@@ -13964,6 +13968,12 @@
13964 13968
         "node": ">=0.10"
13965 13969
       }
13966 13970
     },
13971
+    "node_modules/tabulator-tables": {
13972
+      "version": "5.6.1",
13973
+      "resolved": "https://registry.npmjs.org/tabulator-tables/-/tabulator-tables-5.6.1.tgz",
13974
+      "integrity": "sha512-DsmaZqEmlQS/NL5ZJbVtoaeYjJgofEFp+2er7+uwKerGwd/E2rZbeQgux4+Ab1dxNJcbptiX7oUiTwogOnUdgQ==",
13975
+      "license": "MIT"
13976
+    },
13967 13977
     "node_modules/tailwindcss": {
13968 13978
       "version": "3.4.19",
13969 13979
       "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.19.tgz",

+ 1
- 0
package.json Ver arquivo

@@ -23,6 +23,7 @@
23 23
     "@types/marked": "^5.0.2",
24 24
     "ag-grid-angular": "^35.0.0",
25 25
     "ag-grid-community": "^35.0.0",
26
+    "tabulator-tables": "^5.6.0",
26 27
     "marked": "^17.0.1",
27 28
     "base-core": "file:../../ng-base/dist/base-core",
28 29
     "prismjs": "^1.30.0",

+ 23
- 16
src/app/pages/service-register-config/service-register-config.component.html Ver arquivo

@@ -1,4 +1,9 @@
1 1
 <div class="h-full flex flex-col pt-0 px-2 pb-2 min-w-0">
2
+  <!-- 错误消息显示 -->
3
+  <div *ngIf="errorMessage" class="mb-2 p-3 bg-red-100 border border-red-400 text-red-700 rounded">
4
+    {{ errorMessage }}
5
+  </div>
6
+  
2 7
   <!-- 顶部标题区域 -->
3 8
   <app-sticky-header
4 9
     [title]="title"
@@ -16,8 +21,8 @@
16 21
     [debugRegisterUrl]="debugInfo.registerUrl"
17 22
     [debugListUrl]="debugInfo.listUrl"
18 23
     [autoDetect]="true"
19
-      [scrollContainer]="'.content-area'"
20
-     [scrollThreshold]="20"
24
+    [scrollContainer]="'.content-area'"
25
+    [scrollThreshold]="20"
21 26
     [compactThreshold]="80"
22 27
     [widthTarget]="'#matCard'"
23 28
     (buttonClick)="onRegister()"
@@ -25,20 +30,22 @@
25 30
    
26 31
       <mat-card #matCard id="matCard" class="flex-1">
27 32
     <mat-card-content>
28
-        <!-- AG Grid组件 -->
29
-        <ag-grid-angular
30
-           class="ag-theme-alpine h-[800px]"
31
-          [columnDefs]="columnDefs"
32
-          [rowModelType]="'infinite'"
33
-          [datasource]="datasource"
34
-          [pagination]="true"
35
-          [paginationPageSize]="paginationPageSize"
36
-          [cacheBlockSize]="paginationPageSize"
37
-          [maxBlocksInCache]="10"
38
-            [domLayout]="'normal'"
39
-          [rowSelection]="'single'"
40
-          (gridReady)="onGridReady($event)">
41
-        </ag-grid-angular>
33
+        <!-- Tabulator表格组件 -->
34
+        <lib-tabulator-table
35
+          class="h-[800px]"
36
+          [columns]="tabulatorColumns"
37
+          [data]="tableData"
38
+          [pagination]="'local'"
39
+          [paginationSize]="paginationPageSize"
40
+          [paginationSizeSelector]="[10, 50, 100, 500]"
41
+          [selectable]="true"
42
+          [height]="'100%'"
43
+          [layout]="'fitColumns'"
44
+          [placeholder]="'暂无数据'"
45
+          (rowClick)="onRowClick($event)"
46
+          (rowSelected)="onRowSelected($event)"
47
+          #tabulator>
48
+        </lib-tabulator-table>
42 49
     </mat-card-content>
43 50
   </mat-card>
44 51
 </div>

+ 203
- 226
src/app/pages/service-register-config/service-register-config.component.ts Ver arquivo

@@ -1,56 +1,48 @@
1
-import { Component, OnInit, ChangeDetectorRef, AfterViewInit, OnDestroy, ViewChild, ElementRef, Renderer2 } from '@angular/core';
1
+import { Component, OnInit, ChangeDetectorRef, AfterViewInit, OnDestroy, ViewChild, ElementRef } from '@angular/core';
2 2
 import { CommonModule } from '@angular/common';
3 3
 import { MatCard, MatCardContent } from '@angular/material/card';
4 4
 
5 5
 import { HttpErrorResponse } from '@angular/common/http';
6
-import { StickyHeaderComponent } from 'base-core';
6
+import { StickyHeaderComponent, TabulatorTableComponent } from 'base-core';
7 7
 import { ConfigMeta } from '../../models/config-meta.model';
8 8
 import { ConfigMetaService } from '../../services/config-meta.service';
9
-import { AgGridAngular } from 'ag-grid-angular';
10
-import { ColDef, GridReadyEvent, PaginationChangedEvent, GridApi, IDatasource, IGetRowsParams, ModuleRegistry } from 'ag-grid-community';
11
-import { InfiniteRowModelModule, PaginationModule, RowSelectionModule } from 'ag-grid-community';
12 9
 import { ConfigMetaQueryRequest, PaginatedQueryResult } from '../../models/config-meta.model';
13 10
 
14
-// 注册 AG Grid 模块
15
-ModuleRegistry.registerModules([
16
-  InfiniteRowModelModule,
17
-  PaginationModule,
18
-  RowSelectionModule
19
-]);
20
-
21 11
 @Component({
22 12
   selector: 'app-service-register-config',
23
-  imports: [CommonModule, MatCard, MatCardContent, StickyHeaderComponent, AgGridAngular],
13
+  imports: [CommonModule, MatCard, MatCardContent, StickyHeaderComponent, TabulatorTableComponent],
24 14
   templateUrl: './service-register-config.component.html',
25 15
   styleUrl: './service-register-config.component.scss'
26 16
 })
27 17
 export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, OnDestroy {
28 18
   title = '注册服务配置';
29 19
   hintText = '点击"注册"按钮将同步所有配置元信息到数据库,并显示配置列表。';
30
-  
31
-   // AG Grid 配置
32
-  columnDefs: ColDef[] = [
33
-    { field: 'id', headerName: 'ID', width: 120 },
34
-    { field: 'configName', headerName: '配置名称', width: 150 },
35
-    { field: 'fieldName', headerName: '字段名', width: 150 },
36
-    { field: 'fieldType', headerName: '字段类型', width: 120 },
37
-    { field: 'yamlName', headerName: 'YAML名称', width: 150 },
38
-    { field: 'fieldDesc', headerName: '字段描述', width: 200 },
39
-    { field: 'creator', headerName: '创建者', width: 120 },
40
-    { field: 'createdAt', headerName: '创建时间', width: 180 }
20
+   
21
+  // Tabulator 配置
22
+  tabulatorColumns: any[] = [
23
+    { title: 'ID', field: 'id', width: 120, sorter: 'string' },
24
+    { title: '配置名称', field: 'configName', width: 150, sorter: 'string' },
25
+    { title: '字段名', field: 'fieldName', width: 150, sorter: 'string' },
26
+    { title: '字段类型', field: 'fieldType', width: 120, sorter: 'string' },
27
+    { title: 'YAML名称', field: 'yamlName', width: 150, sorter: 'string' },
28
+    { title: '字段描述', field: 'fieldDesc', width: 200, sorter: 'string' },
29
+    { title: '创建者', field: 'creator', width: 120, sorter: 'string' },
30
+    { title: '创建时间', field: 'createdAt', width: 180, sorter: 'datetime' }
41 31
   ];
42
-   rowData: any[] = [];
43
-   datasource: IDatasource | undefined = undefined;
44
-   configMetaList: ConfigMeta[] = [];
32
+  
33
+  configMetaList: ConfigMeta[] = [];
45 34
 
46
-   // 分页配置
47
-   paginationPageSize = 100;
35
+  // 分页配置
36
+  paginationPageSize = 100;
48 37
   currentPage = 1;
49 38
   totalRecords = 0;
50
-  gridApi: GridApi | null = null;
39
+
40
+  // Tabulator 数据
41
+  tableData: any[] = [];
51 42
 
52 43
   loading = false;
53 44
   registering = false;
45
+  errorMessage: string | null = null;
54 46
   
55 47
   // 注意:滚动状态现在由 sticky-header 组件自动检测管理
56 48
   // 使用 [autoDetect]="true" 启用自动滚动检测
@@ -67,23 +59,37 @@ export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, On
67 59
     pageSize: 10
68 60
   };
69 61
 
70
-  @ViewChild(AgGridAngular) agGrid!: AgGridAngular;
62
+  @ViewChild('tabulator') tabulator!: TabulatorTableComponent;
71 63
   @ViewChild('matCard', { read: ElementRef }) matCardRef!: ElementRef;
72 64
 
73 65
   constructor(
74 66
     private configMetaService: ConfigMetaService,
75 67
     private cdRef: ChangeDetectorRef,
76
-    private elementRef: ElementRef,
77
-    private renderer: Renderer2
68
+    private elementRef: ElementRef
78 69
   ) {}
79 70
 
80
-    ngOnInit() {
81
-      console.log('ServiceRegisterConfigComponent initialized');
82
-    }
71
+  ngOnInit() {
72
+    console.log('ServiceRegisterConfigComponent initialized');
73
+    
74
+    // 默认使用API数据,可通过调试信息切换为模拟数据
75
+    this.debugInfo.useMockData = false;
76
+    this.updateDataConfig();
77
+    
78
+    // 加载数据
79
+    this.loadData();
80
+    
81
+    console.log('初始化完成,配置状态:', {
82
+      useMockData: this.debugInfo.useMockData,
83
+      tableDataLength: this.tableData.length,
84
+      paginationMode: 'local'
85
+    });
86
+  }
83 87
 
84
-  loadData(page: number = 1) {
85
-    this.loading = true;
86
-    this.currentPage = page;
88
+  /**
89
+   * 加载数据(使用config-meta.service.ts)
90
+   */
91
+  loadData(page: number = 1): void {
92
+    console.log(`加载第${page}页数据,页大小: ${this.paginationPageSize}`);
87 93
     
88 94
     // 构建查询请求
89 95
     const request: ConfigMetaQueryRequest = {
@@ -91,26 +97,18 @@ export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, On
91 97
       pageSize: this.paginationPageSize
92 98
     };
93 99
     
94
-    console.log(`加载第${page}页数据,页大小: ${this.paginationPageSize}`);
100
+    this.loading = true;
95 101
     
96 102
     this.configMetaService.listConfigMetaPaginated(request).subscribe({
97
-      next: (result: PaginatedQueryResult<ConfigMeta[]>) => {
98
-        this.loading = false;
99
-        
100
-        if (result.success && result.data) {
101
-          this.rowData = result.data;
103
+       next: (result: PaginatedQueryResult<ConfigMeta[]>) => {
104
+         this.loading = false;
105
+         this.errorMessage = null;
106
+         
107
+         if (result.success && result.data) {
108
+          this.tableData = result.data;
102 109
           this.configMetaList = result.data;
103 110
           this.totalRecords = result.totalCount || result.data.length;
104 111
           
105
-          // 更新AG Grid分页总记录数
106
-          if (this.gridApi) {
107
-            // 设置总记录数,使分页控件显示正确的总页数
108
-            this.gridApi.setGridOption('pagination', {
109
-              total: this.totalRecords,
110
-              pageSize: this.paginationPageSize
111
-            } as any);
112
-          }
113
-          
114 112
           // 更新调试信息
115 113
           this.debugInfo.dataSource = 'API数据';
116 114
           this.debugInfo.recordCount = this.totalRecords;
@@ -123,178 +121,139 @@ export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, On
123 121
           this.debugInfo.pageSize = this.paginationPageSize;
124 122
           
125 123
           console.log(`数据加载成功: ${result.data.length}条记录,总计: ${this.totalRecords}`);
124
+          console.log('数据示例:', result.data.slice(0, 3)); // 打印前3条数据
126 125
         } else {
127 126
           console.error('数据加载失败:', result);
127
+          // 如果API失败,切换到模拟数据用于调试
128
+          this.debugInfo.useMockData = true;
129
+          this.updateDataConfig();
128 130
         }
129 131
         
130 132
         this.cdRef.detectChanges();
131 133
       },
132
-      error: (error: HttpErrorResponse) => {
133
-        this.loading = false;
134
-        console.error('加载数据时出错:', error);
135
-        this.cdRef.detectChanges();
136
-      }
134
+       error: (error: HttpErrorResponse) => {
135
+         this.loading = false;
136
+         console.error('加载数据时出错:', error);
137
+         console.error('错误详情:', error.error);
138
+         
139
+         // 设置错误消息
140
+         this.errorMessage = `加载数据失败: ${error.status} ${error.statusText}`;
141
+         
142
+         // API调用失败,切换到模拟数据
143
+         this.debugInfo.useMockData = true;
144
+         this.updateDataConfig();
145
+         
146
+         this.cdRef.detectChanges();
147
+       }
137 148
     });
138 149
   }
139 150
 
140
-    private generateMockData(page: number, pageSize: number): { data: any[], totalCount: number } {
141
-      const totalMockCount = 200;
142
-      const startIndex = page * pageSize;
143
-      const endIndex = Math.min(startIndex + pageSize, totalMockCount);
151
+  /**
152
+   * 生成模拟数据(用于调试)
153
+   */
154
+  private generateMockData(): ConfigMeta[] {
155
+    const mockData: ConfigMeta[] = [];
156
+    const configs = ['app', 'database', 'redis', 'logger', 'cache'];
157
+    const fieldTypes = ['string', 'int', 'bool', 'config', 'array'];
158
+    
159
+    for (let i = 1; i <= 200; i++) {
160
+      const configIndex = i % configs.length;
161
+      mockData.push({
162
+        id: `config-${i}`,
163
+        configName: configs[configIndex],
164
+        fieldName: `field_${i}`,
165
+        fieldType: fieldTypes[i % fieldTypes.length],
166
+        yamlName: `yaml.field.${i}`,
167
+        fieldDesc: `这是第 ${i} 个配置字段的描述`,
168
+        creator: `user_${(i % 5) + 1}`,
169
+        createdAt: new Date(Date.now() - i * 86400000).toISOString()
170
+      });
171
+    }
172
+    return mockData;
173
+  }
174
+
175
+  /**
176
+   * Tabulator事件处理器
177
+   */
178
+  
179
+  onDataLoading(event: any): void {
180
+    console.log('数据加载中:', event);
181
+    this.loading = true;
182
+    this.cdRef.detectChanges();
183
+  }
184
+
185
+  onDataLoaded(event: any): void {
186
+    console.log('数据加载完成:', event);
187
+    this.loading = false;
188
+    
189
+    // 提取实际数据
190
+    let data: any[] = [];
191
+    let totalCount = 0;
192
+    let lastPage = 0;
193
+    
194
+    if (this.debugInfo.useMockData) {
195
+      // 模拟数据模式下,event是数据数组
196
+      data = Array.isArray(event) ? event : [];
197
+      totalCount = data.length;
198
+      this.totalRecords = totalCount;
144 199
       
145
-      const mockData = [];
146
-      for (let i = startIndex; i < endIndex; i++) {
147
-        mockData.push({
148
-          id: i + 1,
149
-          configName: `配置${i + 1}`,
150
-          fieldName: `field_${i + 1}`,
151
-          fieldType: i % 3 === 0 ? 'string' : i % 3 === 1 ? 'number' : 'boolean',
152
-          yamlName: `yaml_${i + 1}`,
153
-          fieldDesc: `这是第${i + 1}个配置字段的描述`,
154
-          creator: `用户${(i % 5) + 1}`,
155
-          createdAt: new Date(Date.now() - i * 86400000).toISOString()
156
-        });
200
+      // 更新调试信息
201
+      this.debugInfo.dataSource = '模拟数据';
202
+      this.debugInfo.recordCount = totalCount;
203
+      this.debugInfo.lastUpdated = new Date().toISOString();
204
+      this.debugInfo.registerUrl = '模拟数据 - 无API调用';
205
+      this.debugInfo.listUrl = '模拟数据 - 无API调用';
206
+      this.debugInfo.totalPages = Math.ceil(totalCount / this.paginationPageSize);
207
+    } else {
208
+      // 远程数据模式下,event是Tabulator格式 { last_page, data }
209
+      if (event && typeof event === 'object') {
210
+        if ('data' in event) {
211
+          data = Array.isArray(event.data) ? event.data : [];
212
+        }
213
+        if ('last_page' in event) {
214
+          lastPage = event.last_page;
215
+          totalCount = lastPage * this.paginationPageSize;
216
+          this.totalRecords = totalCount;
217
+          this.debugInfo.totalPages = lastPage;
218
+        }
157 219
       }
158 220
       
159
-      return {
160
-        data: mockData,
161
-        totalCount: totalMockCount
162
-      };
221
+      // 更新调试信息
222
+      this.debugInfo.dataSource = 'API数据';
223
+      this.debugInfo.recordCount = totalCount;
224
+      this.debugInfo.lastUpdated = new Date().toISOString();
225
+      this.debugInfo.useMockData = false;
226
+      this.debugInfo.registerUrl = this.configMetaService.getInitUrl();
227
+      this.debugInfo.listUrl = this.configMetaService.getListUrl();
163 228
     }
229
+    
230
+    // 更新配置列表
231
+    this.configMetaList = data;
232
+    console.log(`数据加载完成: ${data.length}条记录,总计: ${totalCount}条`);
233
+    
234
+    this.cdRef.detectChanges();
235
+  }
164 236
 
165
-    createInfiniteDatasource(): IDatasource {
166
-      return {
167
-        getRows: (params: IGetRowsParams) => {
168
-          const pageSize = this.paginationPageSize;
169
-          const startRow = params.startRow;
170
-          const page = Math.floor(startRow / pageSize);
171
-          
172
-          console.log(`Infinite row model: startRow=${startRow}, endRow=${params.endRow}, page=${page}, pageSize=${pageSize}`);
173
-          
174
-          // 使用模拟数据或真实API
175
-          if (this.debugInfo.useMockData) {
176
-            this.loading = true;
177
-            setTimeout(() => {
178
-              const mockResult = this.generateMockData(page, pageSize);
179
-              const rowData = mockResult.data;
180
-              const totalCount = mockResult.totalCount;
181
-              
182
-              const lastRow = totalCount > 0 ? totalCount : -1;
183
-              params.successCallback(rowData, lastRow);
184
-              
185
-              // 更新调试信息
186
-              this.debugInfo.dataSource = '模拟数据';
187
-              this.debugInfo.recordCount = totalCount;
188
-              this.debugInfo.lastUpdated = new Date().toISOString();
189
-              this.debugInfo.registerUrl = '模拟数据 - 无API调用';
190
-              this.debugInfo.listUrl = '模拟数据 - 无API调用';
191
-              this.debugInfo.currentPage = page + 1;
192
-              this.debugInfo.totalPages = Math.ceil(totalCount / pageSize);
193
-              this.debugInfo.pageSize = pageSize;
194
-              
195
-              console.log(`模拟数据加载成功: ${rowData.length}条记录,总计: ${totalCount}`);
196
-              
197
-              // 更新组件状态
198
-              this.totalRecords = totalCount;
199
-              this.rowData = rowData;
200
-              this.configMetaList = rowData;
201
-              this.loading = false;
202
-              this.cdRef.detectChanges();
203
-            }, 100);
204
-          } else {
205
-            const request: ConfigMetaQueryRequest = {
206
-              page: page,
207
-              pageSize: pageSize
208
-            };
209
-            
210
-            this.loading = true;
211
-            this.configMetaService.listConfigMetaPaginated(request).subscribe({
212
-              next: (result: PaginatedQueryResult<ConfigMeta[]>) => {
213
-                this.loading = false;
214
-                if (result.success && result.data) {
215
-                  const rowData = result.data;
216
-                  const totalCount = result.totalCount || 0;
217
-                  
218
-                  // 成功回调,提供行数据及总行数
219
-                  // 对于无限行模型,需要传递 rowCount(总行数)以便网格知道何时停止加载
220
-                  const lastRow = totalCount > 0 ? totalCount : -1;
221
-                  params.successCallback(rowData, lastRow);
222
-                  
223
-                  // 更新调试信息
224
-                  this.debugInfo.dataSource = 'API数据';
225
-                  this.debugInfo.recordCount = totalCount;
226
-                  this.debugInfo.lastUpdated = new Date().toISOString();
227
-                  this.debugInfo.useMockData = false;
228
-                  this.debugInfo.registerUrl = this.configMetaService.getInitUrl();
229
-                  this.debugInfo.listUrl = this.configMetaService.getListUrl();
230
-                  this.debugInfo.currentPage = page + 1;
231
-                  this.debugInfo.totalPages = Math.ceil(totalCount / pageSize);
232
-                  this.debugInfo.pageSize = pageSize;
233
-                  
234
-                  console.log(`无限行模型数据加载成功: ${rowData.length}条记录,总计: ${totalCount}`);
235
-                  
236
-                  // 更新组件状态
237
-                  this.totalRecords = totalCount;
238
-                  this.rowData = rowData;
239
-                  this.configMetaList = rowData;
240
-                } else {
241
-                  console.error('无限行模型数据加载失败:', result);
242
-                  params.failCallback();
243
-                }
244
-                this.cdRef.detectChanges();
245
-              },
246
-              error: (error: HttpErrorResponse) => {
247
-                this.loading = false;
248
-                console.error('无限行模型加载数据时出错:', error);
249
-                params.failCallback();
250
-                this.cdRef.detectChanges();
251
-              }
252
-            });
253
-          }
254
-        },
255
-        rowCount: undefined // 初始时不知道总行数,将在第一次加载后由successCallback提供
256
-      };
257
-   }
237
+  onDataLoadError(error: any): void {
238
+    console.error('数据加载错误:', error);
239
+    this.loading = false;
240
+    this.cdRef.detectChanges();
241
+  }
258 242
 
259
-     onGridReady(params: GridReadyEvent) {
260
-       this.gridApi = params.api;
261
-       console.log('AG Grid ready, API initialized - setting infinite row model datasource');
262
-       
263
-       // 创建并设置无限行模型数据源
264
-       this.datasource = this.createInfiniteDatasource();
265
-       
266
-       // 通过API设置数据源(确保网格使用它)
267
-       params.api.setGridOption('datasource', this.datasource);
268
-       
269
-       // 添加分页事件监听器以更新调试信息
270
-       params.api.addEventListener('paginationChanged', this.onPaginationChanged.bind(this));
271
-       
272
-        // 网格滚动监听器暂时禁用,使用窗口滚动
273
-        // const gridElement = this.agGrid?.nativeElement;
274
-        // if (gridElement) {
275
-        //   this.gridScrollListener = this.renderer.listen(
276
-        //     gridElement,
277
-        //     'scroll',
278
-        //     this.handleScroll.bind(this)
279
-        //   );
280
-        //   console.log('网格滚动监听器已添加');
281
-        // }
282
-     }
283
-
284
-   onPaginationChanged(event: PaginationChangedEvent) {
285
-     if (!this.gridApi || event.newPage === undefined || typeof event.newPage !== 'number') {
286
-       return;
287
-     }
288
-     
289
-     const newPage = event.newPage + 1; // AG Grid页码从0开始,转换为从1开始
290
-     if (newPage !== this.currentPage) {
291
-       console.log(`分页改变: 从第${this.currentPage}页到第${newPage}页`);
292
-       this.currentPage = newPage;
293
-       
294
-       // 更新调试信息中的当前页码
295
-       this.debugInfo.currentPage = newPage;
296
-     }
297
-   }
243
+  onPageLoaded(page: number): void {
244
+    console.log('页面加载:', page);
245
+    this.currentPage = page;
246
+    this.debugInfo.currentPage = page;
247
+    this.cdRef.detectChanges();
248
+  }
249
+
250
+  onRowClick(event: any): void {
251
+    console.log('行点击:', event);
252
+  }
253
+
254
+  onRowSelected(event: any): void {
255
+    console.log('行选中:', event);
256
+  }
298 257
 
299 258
 
300 259
 
@@ -310,9 +269,29 @@ export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, On
310 269
     console.log('ServiceRegisterConfigComponent view initialized');
311 270
     // 注意:滚动检测现在由 sticky-header 组件自动处理
312 271
     // 通过 [autoDetect]="true" 启用
272
+  }
273
+
274
+  /**
275
+   * 根据模拟数据状态更新数据配置
276
+   */
277
+  private updateDataConfig(): void {
278
+    console.log('更新数据配置,当前useMockData:', this.debugInfo.useMockData);
313 279
     
314
-    // 启用模拟数据用于测试滚动效果
315
-    this.debugInfo.useMockData = true;
280
+    if (this.debugInfo.useMockData) {
281
+      // 使用模拟数据,设置静态数据
282
+      this.tableData = this.generateMockData();
283
+      console.log('使用模拟数据:', {
284
+        dataLength: this.tableData.length,
285
+        paginationMode: 'local'
286
+      });
287
+    } else {
288
+      // 使用真实API,清空静态数据,将通过loadData()加载
289
+      this.tableData = [];
290
+      console.log('使用API数据:', {
291
+        dataLength: this.tableData.length,
292
+        paginationMode: 'remote'
293
+      });
294
+    }
316 295
   }
317 296
 
318 297
 
@@ -331,21 +310,18 @@ export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, On
331 310
      this.configMetaService.initConfigMeta().subscribe({
332 311
        next: (result: any) => {
333 312
          this.registering = false;
313
+         this.errorMessage = null;
334 314
          if (result.success) {
335 315
            console.log('注册完成:', result.data);
336
-           // 重新加载数据 - 刷新无限行模型缓存
337
-           if (this.gridApi) {
338
-             // 回到第一页
339
-             this.gridApi.paginationGoToFirstPage();
340
-             // 刷新缓存,强制重新加载数据
341
-             this.gridApi.refreshInfiniteCache();
342
-             
343
-             // 重置当前页码
344
-             this.currentPage = 1;
345
-             this.debugInfo.currentPage = 1;
346
-             
347
-             console.log('无限行模型缓存已刷新,回到第一页');
348
-           }
316
+           
317
+           // 注册后切换到真实API数据
318
+           this.debugInfo.useMockData = false;
319
+           this.updateDataConfig();
320
+           
321
+           // 重新加载数据
322
+           this.loadData(1);
323
+           
324
+           console.log('注册成功,数据已重新加载');
349 325
          } else {
350 326
            console.error('注册失败:', result);
351 327
          }
@@ -353,6 +329,7 @@ export class ServiceRegisterConfigComponent implements OnInit, AfterViewInit, On
353 329
        error: (error: HttpErrorResponse) => {
354 330
          this.registering = false;
355 331
          console.error('注册时出错:', error);
332
+         this.errorMessage = `注册失败: ${error.status} ${error.statusText}`;
356 333
        }
357 334
      });
358 335
    }

Carregando…
Cancelar
Salvar