Bläddra i källkod

refactor(admin): 重构 Admin模块

- 移除 DashboardController 中的 AdminService 依赖- 删除 admin.php 配置文件
- 更新 AdminServiceProvider,移除服务注册代码
- 修改 README.md,更新模块概述
notfff 6 månader sedan
förälder
incheckning
658f8bb3cd

+ 21 - 24
app/Module/Admin/AdminControllers/DashboardController.php

@@ -18,15 +18,10 @@ class DashboardController extends AdminController
 {
     protected $title = '仪表板';
 
-    /**
-     * @var AdminService
-     */
-    protected AdminService $adminService;
 
-    public function __construct()
-    {
-        $this->adminService = app('admin.service');
-    }
+
+
+
 
     /**
      * 仪表板首页
@@ -50,30 +45,32 @@ class DashboardController extends AdminController
      */
     protected function buildDashboard(): Row
     {
-        $dashboardData = $this->adminService->getDashboardData();
-        
-        return new Row(function (Row $row) use ($dashboardData) {
+
+        return new Row(function (Row $row)  {
+            $adminService = new AdminService();
+            $dashboardData = $adminService->getDashboardData();
+
             // 第一行:统计卡片
             $row->column(12, function ($column) use ($dashboardData) {
                 $column->append(new StatisticsWidget($dashboardData['statistics']));
             });
-            
+
             // 第二行:系统状态和快捷操作
             $row->column(8, function ($column) use ($dashboardData) {
                 $column->append(new SystemStatusWidget($dashboardData['system']));
             });
-            
+
             $row->column(4, function ($column) use ($dashboardData) {
                 $column->append(new QuickActionsWidget());
             });
-            
+
             // 第三行:系统警报(如果有)
             if (!empty($dashboardData['alerts'])) {
                 $row->column(12, function ($column) use ($dashboardData) {
                     $column->append($this->buildAlertsWidget($dashboardData['alerts']));
                 });
             }
-            
+
             // 第四行:最近操作
             if (!empty($dashboardData['recent_actions'])) {
                 $row->column(12, function ($column) use ($dashboardData) {
@@ -94,22 +91,22 @@ class DashboardController extends AdminController
         $html = '<div class="card">';
         $html .= '<div class="card-header"><h4 class="card-title">系统警报</h4></div>';
         $html .= '<div class="card-body">';
-        
+
         foreach ($alerts as $alert) {
             $type = $alert['type'];
             $title = $alert['title'];
             $message = $alert['message'];
             $timestamp = $alert['timestamp']->format('Y-m-d H:i:s');
-            
+
             $html .= "<div class=\"alert alert-{$type}\">";
             $html .= "<strong>{$title}</strong><br>";
             $html .= "{$message}<br>";
             $html .= "<small class=\"text-muted\">{$timestamp}</small>";
             $html .= "</div>";
         }
-        
+
         $html .= '</div></div>';
-        
+
         return $html;
     }
 
@@ -135,7 +132,7 @@ class DashboardController extends AdminController
         $html .= '</tr>';
         $html .= '</thead>';
         $html .= '<tbody>';
-        
+
         foreach ($actions as $action) {
             $html .= '<tr>';
             $html .= "<td>{$action['description']}</td>";
@@ -144,12 +141,12 @@ class DashboardController extends AdminController
             $html .= "<td>{$action['ip_address']}</td>";
             $html .= '</tr>';
         }
-        
+
         $html .= '</tbody>';
         $html .= '</table>';
         $html .= '</div>';
         $html .= '</div></div>';
-        
+
         return $html;
     }
 
@@ -186,10 +183,10 @@ class DashboardController extends AdminController
         try {
             // 清理仪表板缓存
             cache()->forget('admin.dashboard.data');
-            
+
             // 获取新数据
             $data = $this->adminService->getDashboardData();
-            
+
             return response()->json([
                 'status' => 'success',
                 'message' => '仪表板数据已刷新',

+ 0 - 180
app/Module/Admin/Config/admin.php

@@ -1,180 +0,0 @@
-<?php
-
-return [
-    /*
-    |--------------------------------------------------------------------------
-    | Admin模块配置
-    |--------------------------------------------------------------------------
-    |
-    | Admin模块的基础配置选项
-    |
-    */
-
-    // 模块基础配置
-    'module' => [
-        'name' => 'Admin',
-        'version' => '1.0.0',
-        'description' => '后台基础功能扩展模块',
-        'author' => 'System',
-    ],
-
-    // 仪表板配置
-    'dashboard' => [
-        'enabled' => true,
-        'refresh_interval' => 30, // 秒
-        'widgets' => [
-            'system_status' => true,
-            'quick_actions' => true,
-            'statistics' => true,
-            'performance' => true,
-        ],
-    ],
-
-    // 缓存配置
-    'cache' => [
-        'enabled' => true,
-        'default_ttl' => 3600, // 秒
-        'types' => [
-            'config' => [
-                'ttl' => 7200,
-                'tags' => ['admin', 'config'],
-            ],
-            'system' => [
-                'ttl' => 1800,
-                'tags' => ['admin', 'system'],
-            ],
-            'stats' => [
-                'ttl' => 300,
-                'tags' => ['admin', 'stats'],
-            ],
-        ],
-    ],
-
-    // 日志配置
-    'log' => [
-        'enabled' => true,
-        'retention_days' => 30,
-        'max_file_size' => '10M',
-        'channels' => [
-            'admin' => [
-                'driver' => 'daily',
-                'path' => storage_path('logs/admin.log'),
-                'level' => 'info',
-                'days' => 30,
-            ],
-            'action' => [
-                'driver' => 'daily',
-                'path' => storage_path('logs/admin-action.log'),
-                'level' => 'info',
-                'days' => 90,
-            ],
-        ],
-    ],
-
-    // 系统监控配置
-    'monitoring' => [
-        'enabled' => true,
-        'metrics' => [
-            'system' => [
-                'cpu_usage' => true,
-                'memory_usage' => true,
-                'disk_usage' => true,
-                'load_average' => true,
-            ],
-            'application' => [
-                'response_time' => true,
-                'error_rate' => true,
-                'request_count' => true,
-                'database_queries' => true,
-            ],
-        ],
-        'alerts' => [
-            'cpu_threshold' => 80, // 百分比
-            'memory_threshold' => 85, // 百分比
-            'disk_threshold' => 90, // 百分比
-            'response_time_threshold' => 2000, // 毫秒
-        ],
-    ],
-
-    // 安全配置
-    'security' => [
-        'session_timeout' => 7200, // 秒
-        'max_login_attempts' => 5,
-        'lockout_duration' => 900, // 秒
-        'password_requirements' => [
-            'min_length' => 8,
-            'require_uppercase' => true,
-            'require_lowercase' => true,
-            'require_numbers' => true,
-            'require_symbols' => false,
-        ],
-    ],
-
-    // UI配置
-    'ui' => [
-        'theme' => 'default',
-        'sidebar_collapsed' => false,
-        'show_breadcrumbs' => true,
-        'items_per_page' => 20,
-        'date_format' => 'Y-m-d H:i:s',
-        'timezone' => 'Asia/Shanghai',
-    ],
-
-    // 权限配置
-    'permissions' => [
-        'super_admin' => [
-            'admin.dashboard',
-            'admin.cache.manage',
-            'admin.log.view',
-            'admin.log.export',
-            'admin.system.info',
-            'admin.system.backup',
-        ],
-        'admin' => [
-            'admin.dashboard',
-            'admin.cache.view',
-            'admin.log.view',
-            'admin.system.info',
-        ],
-    ],
-
-    // 备份配置
-    'backup' => [
-        'enabled' => true,
-        'storage_disk' => 'local',
-        'storage_path' => 'backups',
-        'retention_days' => 7,
-        'include' => [
-            'database' => true,
-            'files' => false,
-            'config' => true,
-        ],
-    ],
-
-    // 维护模式配置
-    'maintenance' => [
-        'enabled' => false,
-        'message' => '系统维护中,请稍后再试',
-        'allowed_ips' => [
-            '127.0.0.1',
-            '::1',
-        ],
-        'retry_after' => 3600, // 秒
-    ],
-
-    // 通知配置
-    'notifications' => [
-        'enabled' => true,
-        'channels' => [
-            'database' => true,
-            'mail' => false,
-            'sms' => false,
-        ],
-        'events' => [
-            'system_error' => true,
-            'high_cpu_usage' => true,
-            'disk_space_low' => true,
-            'failed_login' => true,
-        ],
-    ],
-];

+ 6 - 30
app/Module/Admin/Providers/AdminServiceProvider.php

@@ -9,7 +9,7 @@ use Illuminate\Support\ServiceProvider;
 
 /**
  * Admin模块服务提供者
- * 
+ *
  * 负责注册Admin模块的服务、事件监听器等
  */
 class AdminServiceProvider extends ServiceProvider
@@ -21,14 +21,10 @@ class AdminServiceProvider extends ServiceProvider
      */
     public function register()
     {
-        // 注册配置文件
-        $this->mergeConfigFrom(
-            __DIR__ . '/../Config/admin.php',
-            'admin_module'
-        );
 
-        // 注册服务
-        $this->registerServices();
+
+        // 注册服务,不需要注册服务
+//        $this->registerServices();
     }
 
     /**
@@ -48,28 +44,8 @@ class AdminServiceProvider extends ServiceProvider
         $this->publishResources();
     }
 
-    /**
-     * 注册服务
-     *
-     * @return void
-     */
-    protected function registerServices()
-    {
-        // 注册Admin服务
-        $this->app->singleton('admin.service', function ($app) {
-            return new \App\Module\Admin\Services\AdminService();
-        });
-
-        // 注册缓存服务
-        $this->app->singleton('admin.cache', function ($app) {
-            return new \App\Module\Admin\Services\CacheService();
-        });
-
-        // 注册日志服务
-        $this->app->singleton('admin.log', function ($app) {
-            return new \App\Module\Admin\Services\LogService();
-        });
-    }
+
+
 
     /**
      * 注册事件监听器

+ 1 - 1
app/Module/Admin/README.md

@@ -4,7 +4,7 @@
 
 ## 模块概述
 
-Admin模块是专门用于扩展后台基础功能的模块,提供通用的后台管理组件、工具类、辅助功能等。该模块不处理具体的业务逻辑,而是为其他模块的后台管理功能提供基础支持和通用组件
+Admin模块是专门用于扩展后台基础功能的模块,提供通用的后台管理组件、工具类、辅助功能等。该模块不处理具体的业务逻辑,而是为其他模块的后台管理功能提供基础支持/通用组件/实践演示
 
 ## 功能特点