ソースを参照

缩放改好-修改样式1

qdy 1ヶ月前
コミット
69ff0afa4f

+ 2
- 2
src/app/app.component.html ファイルの表示

@@ -12,7 +12,7 @@
12 12
         </h2>
13 13
       </div>
14 14
       <div class="flex-1 overflow-auto">
15
-        <app-tree-nav></app-tree-nav>
15
+        <app-tree-nav [treeData]="treeData" (refresh)="onTreeRefresh()"></app-tree-nav>
16 16
       </div>
17 17
       <!-- 底部退出区域 -->
18 18
       <div class="p-3 border-t border-gray-200 bg-gray-50 flex items-center justify-between">
@@ -39,7 +39,7 @@
39 39
     <div class="flex-1 h-full overflow-hidden bg-white flex flex-col">
40 40
 
41 41
       <div class="flex-1 overflow-auto content-area">
42
-        <div class="pt-0 px-4 pb-4 h-full">
42
+         <div class="pt-[5px] px-4 pb-4 h-full">
43 43
           <router-outlet></router-outlet>
44 44
         </div>
45 45
       </div>

+ 29
- 3
src/app/app.component.ts ファイルの表示

@@ -8,9 +8,10 @@ import { MatMenuModule } from '@angular/material/menu';
8 8
 import { MatTooltipModule } from '@angular/material/tooltip';
9 9
 import { DragDropModule } from '@angular/cdk/drag-drop';
10 10
 import { AuthService } from './services/auth.service';
11
-import { TreeService } from 'base-core';
12
-import { TreeNode } from 'base-core';
11
+import { TreeService } from './services/tree.service';
12
+import { TreeNode } from './models/tree-node.model';
13 13
 import { Subscription, filter } from 'rxjs';
14
+import { ConfigService } from 'base-core';
14 15
 
15 16
 @Component({
16 17
   selector: 'app-root',
@@ -31,12 +32,21 @@ export class AppComponent implements OnInit, OnDestroy {
31 32
     private router: Router,
32 33
     public authService: AuthService,
33 34
     private treeService: TreeService,
34
-    private activatedRoute: ActivatedRoute
35
+    private activatedRoute: ActivatedRoute,
36
+    private config: ConfigService
35 37
   ) {}
36 38
   
37 39
   ngOnInit() {
38 40
     console.log('AppComponent初始化');
39 41
     console.log('当前路由:', this.router.url);
42
+    
43
+    // 启用真实API调用
44
+    this.config.useMockData = false;
45
+    console.log('使用真实API数据,配置:', {
46
+      useMockData: this.config.useMockData,
47
+      apiBaseUrl: this.config.apiBaseUrl
48
+    });
49
+    
40 50
     // 从本地存储恢复宽度
41 51
     const savedWidth = localStorage.getItem('sidebarWidth');
42 52
     if (savedWidth) {
@@ -51,6 +61,9 @@ export class AppComponent implements OnInit, OnDestroy {
51 61
       },
52 62
       error: (error) => {
53 63
         console.error('加载树数据失败:', error);
64
+        // 确保设置 treeData 为空数组,避免绑定失效
65
+        this.treeData = [];
66
+        this.updateBreadcrumb();
54 67
       }
55 68
     });
56 69
 
@@ -103,6 +116,19 @@ export class AppComponent implements OnInit, OnDestroy {
103 116
     return this.authService.getCurrentUser()?.username || '用户';
104 117
   }
105 118
 
119
+  onTreeRefresh(): void {
120
+    console.log('树刷新事件触发');
121
+    this.treeService.getTree().subscribe({
122
+      next: (data) => {
123
+        this.treeData = data;
124
+        this.updateBreadcrumb();
125
+      },
126
+      error: (error) => {
127
+        console.error('刷新树数据失败:', error);
128
+      }
129
+    });
130
+  }
131
+
106 132
   ngOnDestroy() {
107 133
     this.subscriptions.unsubscribe();
108 134
   }

+ 1
- 0
src/app/pages/project-list/project-list.component.ts ファイルの表示

@@ -62,6 +62,7 @@ export class ProjectListComponent implements OnInit {
62 62
       },
63 63
       error: (error) => {
64 64
         console.error('加载项目失败', error);
65
+        this.projects = [];
65 66
         this.loading = false;
66 67
       }
67 68
     });

+ 1
- 0
src/app/pages/role-list/role-list.component.ts ファイルの表示

@@ -63,6 +63,7 @@ export class RoleListComponent implements OnInit {
63 63
       },
64 64
       error: (error) => {
65 65
         console.error('加载角色失败', error);
66
+        this.roles = [];
66 67
         this.loading = false;
67 68
       }
68 69
     });

+ 1
- 0
src/app/pages/tenant-list/tenant-list.component.ts ファイルの表示

@@ -62,6 +62,7 @@ export class TenantListComponent implements OnInit {
62 62
       },
63 63
       error: (error) => {
64 64
         console.error('加载租户失败', error);
65
+        this.tenants = [];
65 66
         this.loading = false;
66 67
       }
67 68
     });

+ 1
- 1
src/app/services/tree.service.spec.ts ファイルの表示

@@ -1,6 +1,6 @@
1 1
 import { TestBed } from '@angular/core/testing';
2 2
 
3
-import { TreeService } from 'base-core';
3
+import { TreeService } from './tree.service';
4 4
 
5 5
 describe('TreeService', () => {
6 6
   let service: TreeService;

+ 180
- 0
src/app/services/tree.service.ts ファイルの表示

@@ -0,0 +1,180 @@
1
+import { Injectable } from '@angular/core';
2
+import { HttpClient } from '@angular/common/http';
3
+import { Observable, of, catchError, map } from 'rxjs';
4
+import { TreeNode } from '../models/tree-node.model';
5
+import { ConfigService } from 'base-core';
6
+
7
+@Injectable({
8
+  providedIn: 'root'
9
+})
10
+export class TreeService {
11
+  constructor(
12
+    private http: HttpClient,
13
+    private config: ConfigService
14
+  ) {}
15
+
16
+  getTree(): Observable<TreeNode[]> {
17
+    console.log('TreeService.getTree() 调用');
18
+    console.log('config.useMockData:', this.config.useMockData);
19
+    console.log('config.apiBaseUrl:', this.config.apiBaseUrl);
20
+    
21
+    if (this.config.useMockData) {
22
+      console.log('使用模拟树数据');
23
+      const mockTree = this.getMockTree();
24
+      console.log('模拟数据节点数:', mockTree.length);
25
+      // 调试:打印第一个节点的图标信息
26
+      if (mockTree.length > 0 && mockTree[0].children) {
27
+        console.log('[模拟数据]第一个分组节点图标:', mockTree[0].icon);
28
+        console.log('[模拟数据]第一个分组子节点图标:', mockTree[0].children.map(c => ({name: c.name, icon: c.icon})));
29
+      }
30
+      console.log('模拟数据结构:', JSON.stringify(mockTree, null, 2));
31
+      return of(mockTree);
32
+    }
33
+    
34
+    const apiUrl = `${this.config.apiBaseUrl}/projects/tree`;
35
+    console.log('请求树数据:', apiUrl);
36
+    
37
+    return this.http.get<any>(apiUrl).pipe(
38
+      map(response => {
39
+        console.log('树数据响应:', response);
40
+        // 后端返回 {success: true, data: [...]}
41
+        if (response && response.success && response.data) {
42
+          console.log('提取data字段,节点数:', response.data.length);
43
+          // 调试:打印第一个节点的图标信息
44
+          if (response.data.length > 0 && response.data[0].children) {
45
+            console.log('第一个分组节点图标:', response.data[0].icon);
46
+            console.log('第一个分组子节点图标:', response.data[0].children.map((c: any) => ({name: c.name, icon: c.icon})));
47
+          }
48
+          return response.data;
49
+        } else {
50
+          console.warn('响应格式不符合预期,返回空数组');
51
+          return [];
52
+        }
53
+      }),
54
+      catchError((error) => {
55
+        console.error('获取树数据失败:', error);
56
+        console.error('错误详情:', error.status, error.message, error.url);
57
+        // 认证失败或其他错误时返回空数组,不显示模拟数据
58
+        console.warn('API请求失败,回退到模拟数据');
59
+        const mockTree = this.getMockTree();
60
+        console.log('回退模拟数据节点数:', mockTree.length);
61
+        return of(mockTree);
62
+      })
63
+    );
64
+  }
65
+
66
+  private getMockTree(): TreeNode[] {
67
+    // 模拟树数据,基于Go后端返回的结构
68
+    return [
69
+      {
70
+        id: 'home',
71
+        name: '首页',
72
+        icon: 'home',
73
+        type: 'group',
74
+        children: [
75
+          {
76
+            id: 'readme',
77
+            name: '说明',
78
+            icon: 'description',
79
+            type: 'page',
80
+            route: '/home/readme'
81
+          }
82
+        ]
83
+      },
84
+      {
85
+        id: 'service-group',
86
+        name: '服务',
87
+        icon: 'settings',
88
+        type: 'group',
89
+        children: [
90
+          {
91
+            id: 'service-register',
92
+            name: '注册服务配置',
93
+            icon: 'app_registration',
94
+            type: 'page',
95
+            route: '/service/register-config'
96
+          },
97
+          {
98
+            id: 'service-management',
99
+            name: '微服务管理',
100
+            icon: 'dns',
101
+            type: 'page',
102
+            route: '/service/management'
103
+          },
104
+          {
105
+            id: 'service-config',
106
+            name: '微服务配置管理',
107
+            icon: 'settings_applications',
108
+            type: 'page',
109
+            route: '/service/config-management'
110
+          },
111
+          {
112
+            id: 'boot-config',
113
+            name: '微服务启动配置管理',
114
+            icon: 'play_circle',
115
+            type: 'page',
116
+            route: '/service/boot-config'
117
+          }
118
+        ]
119
+      },
120
+      {
121
+        id: 'user-group',
122
+        name: '项目',
123
+        icon: 'folder',
124
+        type: 'group',
125
+        children: [
126
+          {
127
+            id: 'project-management',
128
+            name: '项目管理',
129
+            icon: 'folder_open',
130
+            type: 'page',
131
+            route: '/project/list'
132
+          },
133
+          {
134
+            id: 'agent-management',
135
+            name: 'Agent管理',
136
+            icon: 'smart_toy',
137
+            type: 'page',
138
+            route: '/agent/list'
139
+          },
140
+          {
141
+            id: 'skill-management',
142
+            name: 'Skill管理',
143
+            icon: 'build',
144
+            type: 'page',
145
+            route: '/skill/list'
146
+          }
147
+        ]
148
+      },
149
+      {
150
+        id: 'tenant-group',
151
+        name: '租户管理',
152
+        icon: 'apartment',
153
+        type: 'group',
154
+        children: [
155
+          {
156
+            id: 'tenant-management',
157
+            name: '租户管理',
158
+            icon: 'apartment',
159
+            type: 'page',
160
+            route: '/tenant/list'
161
+          },
162
+          {
163
+            id: 'role-management',
164
+            name: '角色管理',
165
+            icon: 'admin_panel_settings',
166
+            type: 'page',
167
+            route: '/role/list'
168
+          },
169
+          {
170
+            id: 'user-management',
171
+            name: '用户管理',
172
+            icon: 'people',
173
+            type: 'page',
174
+            route: '/user/list'
175
+          }
176
+        ]
177
+      }
178
+    ];
179
+  }
180
+}

読み込み中…
キャンセル
保存