|
|
@@ -0,0 +1,39 @@
|
|
|
+import { CommonModule } from '@angular/common';
|
|
|
+import { ChangeDetectionStrategy, Component, OnInit, computed, inject, signal } from '@angular/core';
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
+import { RouterLink } from '@angular/router';
|
|
|
+import { ArrowRight, Database, LoaderCircle, LucideAngularModule, Search } from 'lucide-angular';
|
|
|
+import { AdminResourceCatalog } from '../admin.models';
|
|
|
+import { CloudFunctionsService } from '../cloud-functions.service';
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-admin-resource-catalog',
|
|
|
+ standalone: true,
|
|
|
+ imports: [CommonModule, FormsModule, RouterLink, LucideAngularModule],
|
|
|
+ templateUrl: './admin-resource-catalog.component.html',
|
|
|
+ styleUrl: './admin-resource-catalog.component.scss',
|
|
|
+ changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
+})
|
|
|
+export class AdminResourceCatalogComponent implements OnInit {
|
|
|
+ readonly catalog = signal<AdminResourceCatalog | null>(null);
|
|
|
+ readonly query = signal('');
|
|
|
+ readonly loading = signal(true);
|
|
|
+ readonly error = signal('');
|
|
|
+ readonly resources = computed(() => {
|
|
|
+ const keyword = this.query().trim().toLowerCase();
|
|
|
+ const resources = this.catalog()?.resources ?? [];
|
|
|
+ return keyword ? resources.filter((item) => `${item.label} ${item.className}`.toLowerCase().includes(keyword)) : resources;
|
|
|
+ });
|
|
|
+ readonly icons = { ArrowRight, Database, LoaderCircle, Search };
|
|
|
+ private readonly functions = inject(CloudFunctionsService);
|
|
|
+
|
|
|
+ ngOnInit(): void { void this.load(); }
|
|
|
+
|
|
|
+ async load(): Promise<void> {
|
|
|
+ this.loading.set(true);
|
|
|
+ this.error.set('');
|
|
|
+ try { this.catalog.set(await this.functions.admin<AdminResourceCatalog>('catalog')); }
|
|
|
+ catch (error) { this.error.set(error instanceof Error ? error.message : '数据类目录加载失败'); }
|
|
|
+ finally { this.loading.set(false); }
|
|
|
+ }
|
|
|
+}
|