Переглянути джерело

feat(dev): 新增开发工具模块

- 添加开发工具模块的基础结构和功能
- 实现了开发工具、开发日志和开发配置的管理功能
- 添加了相关模型、枚举、事件和监听器
- 实现了开发工具逻辑层的核心功能
- 添加了模块文档和数据库设计文档
Your Name 8 місяців тому
батько
коміт
8b6e177e14

+ 15 - 0
app/Module/Dev/AdminControllers/Helper/FilterHelper.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use UCore\DcatAdmin\FilterHelper as BaseFilterHelper;
+
+/**
+ * 筛选器辅助类
+ *
+ * 提供开发工具模块后台控制器的筛选器构建功能
+ */
+class FilterHelper extends BaseFilterHelper
+{
+    use FilterHelperTrait;
+}

+ 136 - 0
app/Module/Dev/AdminControllers/Helper/FilterHelperTrait.php

@@ -0,0 +1,136 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use App\Module\Dev\Enums\DEV_LOG_TYPE;
+use App\Module\Dev\Enums\DEV_STATUS;
+use Dcat\Admin\Grid\Filter;
+use Dcat\Admin\Grid\Filter\Presenter\Presenter;
+
+/**
+ * 筛选器辅助特性
+ *
+ * 提供开发工具模块后台控制器的筛选器构建功能的具体实现
+ */
+trait FilterHelperTrait
+{
+    /**
+     * 添加开发工具ID筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function equalDevId(string $field = 'id', string $label = 'ID'): Filter\AbstractFilter
+    {
+        return $this->filter->equal($field, $label);
+    }
+
+    /**
+     * 添加开发工具名称筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function likeDevName(string $field = 'name', string $label = '名称'): Filter\AbstractFilter
+    {
+        return $this->filter->like($field, $label);
+    }
+
+    /**
+     * 添加开发工具状态筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Presenter
+     */
+    public function equalDevStatus(string $field = 'status', string $label = '状态'): Presenter
+    {
+        return $this->filter->equal($field, $label)->select(DEV_STATUS::getAll());
+    }
+
+    /**
+     * 添加开发日志类型筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Presenter
+     */
+    public function equalDevLogType(string $field = 'type', string $label = '日志类型'): Presenter
+    {
+        return $this->filter->equal($field, $label)->select(DEV_LOG_TYPE::getAll());
+    }
+
+    /**
+     * 添加开发日志内容筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function likeDevLogContent(string $field = 'content', string $label = '日志内容'): Filter\AbstractFilter
+    {
+        return $this->filter->like($field, $label);
+    }
+
+    /**
+     * 添加开发日志用户ID筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function equalDevLogUserId(string $field = 'user_id', string $label = '用户ID'): Filter\AbstractFilter
+    {
+        return $this->filter->equal($field, $label);
+    }
+
+    /**
+     * 添加开发日志创建时间筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function betweenDevLogCreatedAt(string $field = 'created_at', string $label = '创建时间'): Filter\AbstractFilter
+    {
+        return $this->filter->between($field, $label)->datetime();
+    }
+
+    /**
+     * 添加开发配置键筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function likeDevConfigKey(string $field = 'key', string $label = '配置键'): Filter\AbstractFilter
+    {
+        return $this->filter->like($field, $label);
+    }
+
+    /**
+     * 添加开发配置值筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Filter\AbstractFilter
+     */
+    public function likeDevConfigValue(string $field = 'value', string $label = '配置值'): Filter\AbstractFilter
+    {
+        return $this->filter->like($field, $label);
+    }
+
+    /**
+     * 添加开发配置状态筛选
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Presenter
+     */
+    public function equalDevConfigStatus(string $field = 'status', string $label = '状态'): Presenter
+    {
+        return $this->filter->equal($field, $label)->select(DEV_STATUS::getAll());
+    }
+}

+ 15 - 0
app/Module/Dev/AdminControllers/Helper/FormHelper.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use UCore\DcatAdmin\FormHelper as BaseFormHelper;
+
+/**
+ * 表单辅助类
+ *
+ * 提供开发工具模块后台控制器的表单构建功能
+ */
+class FormHelper extends BaseFormHelper
+{
+    use FormHelperTrait;
+}

+ 151 - 0
app/Module/Dev/AdminControllers/Helper/FormHelperTrait.php

@@ -0,0 +1,151 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use App\Module\Dev\Enums\DEV_LOG_TYPE;
+use App\Module\Dev\Enums\DEV_STATUS;
+use Dcat\Admin\Form;
+use Dcat\Admin\Form\Field;
+
+/**
+ * 表单辅助特性
+ *
+ * 提供开发工具模块后台控制器的表单构建功能的具体实现
+ */
+trait FormHelperTrait
+{
+    /**
+     * 添加开发工具名称输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Text
+     */
+    public function textDevName(string $field = 'name', string $label = '名称'): Field\Text
+    {
+        return $this->form->text($field, $label)
+            ->required()
+            ->rules('required|max:100');
+    }
+
+    /**
+     * 添加开发工具描述输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Textarea
+     */
+    public function textareaDevDescription(string $field = 'description', string $label = '描述'): Field\Textarea
+    {
+        return $this->form->textarea($field, $label)
+            ->rows(3)
+            ->rules('max:200');
+    }
+
+    /**
+     * 添加开发工具状态选择
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Select|Field\Radio
+     */
+    public function selectDevStatus(string $field = 'status', string $label = '状态', bool $useRadio = true)
+    {
+        $options = DEV_STATUS::getAll();
+
+        if ($useRadio) {
+            return $this->form->radio($field, $label)
+                ->options($options)
+                ->default(DEV_STATUS::ENABLED->value);
+        }
+
+        return $this->form->select($field, $label)
+            ->options($options)
+            ->default(DEV_STATUS::ENABLED->value);
+    }
+
+    /**
+     * 添加开发日志类型选择
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Select
+     */
+    public function selectDevLogType(string $field = 'type', string $label = '日志类型'): Field\Select
+    {
+        return $this->form->select($field, $label)
+            ->options(DEV_LOG_TYPE::getAll())
+            ->default(DEV_LOG_TYPE::INFO->value)
+            ->required();
+    }
+
+    /**
+     * 添加开发日志内容输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Textarea
+     */
+    public function textareaDevLogContent(string $field = 'content', string $label = '日志内容'): Field\Textarea
+    {
+        return $this->form->textarea($field, $label)
+            ->rows(5)
+            ->required();
+    }
+
+    /**
+     * 添加开发日志额外数据输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Textarea
+     */
+    public function textareaDevLogExtraData(string $field = 'extra_data', string $label = '额外数据'): Field\Textarea
+    {
+        return $this->form->textarea($field, $label)
+            ->rows(5)
+            ->help('请输入JSON格式的数据');
+    }
+
+    /**
+     * 添加开发配置键输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Text
+     */
+    public function textDevConfigKey(string $field = 'key', string $label = '配置键'): Field\Text
+    {
+        return $this->form->text($field, $label)
+            ->required()
+            ->rules('required|max:100');
+    }
+
+    /**
+     * 添加开发配置值输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Textarea
+     */
+    public function textareaDevConfigValue(string $field = 'value', string $label = '配置值'): Field\Textarea
+    {
+        return $this->form->textarea($field, $label)
+            ->rows(5)
+            ->required();
+    }
+
+    /**
+     * 添加开发配置描述输入
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Field\Textarea
+     */
+    public function textareaDevConfigDescription(string $field = 'description', string $label = '配置描述'): Field\Textarea
+    {
+        return $this->form->textarea($field, $label)
+            ->rows(3)
+            ->rules('max:200');
+    }
+}

+ 15 - 0
app/Module/Dev/AdminControllers/Helper/GridHelper.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use UCore\DcatAdmin\GridHelper as BaseGridHelper;
+
+/**
+ * 列表页辅助类
+ *
+ * 提供开发工具模块后台控制器的列表页构建功能
+ */
+class GridHelper extends BaseGridHelper
+{
+    use GridHelperTrait;
+}

+ 156 - 0
app/Module/Dev/AdminControllers/Helper/GridHelperTrait.php

@@ -0,0 +1,156 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use App\Module\Dev\Enums\DEV_LOG_TYPE;
+use App\Module\Dev\Enums\DEV_STATUS;
+use Dcat\Admin\Grid;
+use Dcat\Admin\Grid\Column;
+
+/**
+ * 列表页辅助特性
+ *
+ * 提供开发工具模块后台控制器的列表页构建功能的具体实现
+ */
+trait GridHelperTrait
+{
+    /**
+     * 添加开发工具状态列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnDevStatus(string $field = 'status', string $label = '状态'): Column
+    {
+        return $this->grid->column($field, $label)
+            ->using(DEV_STATUS::getAll())
+            ->label([
+                DEV_STATUS::DISABLED->value => 'danger',
+                DEV_STATUS::ENABLED->value => 'success',
+            ]);
+    }
+
+    /**
+     * 添加开发日志类型列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnDevLogType(string $field = 'type', string $label = '日志类型'): Column
+    {
+        return $this->grid->column($field, $label)
+            ->using(DEV_LOG_TYPE::getAll())
+            ->label([
+                DEV_LOG_TYPE::INFO->value => 'info',
+                DEV_LOG_TYPE::WARNING->value => 'warning',
+                DEV_LOG_TYPE::ERROR->value => 'danger',
+                DEV_LOG_TYPE::DEBUG->value => 'primary',
+            ]);
+    }
+
+    /**
+     * 添加开发日志内容列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @param int $limit 限制长度
+     * @return Column
+     */
+    public function columnDevLogContent(string $field = 'content', string $label = '日志内容', int $limit = 50): Column
+    {
+        return $this->grid->column($field, $label)->limit($limit);
+    }
+
+    /**
+     * 添加开发日志额外数据列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnDevLogExtraData(string $field = 'extra_data', string $label = '额外数据'): Column
+    {
+        return $this->grid->column($field, $label)->display(function ($value) {
+            if (empty($value)) {
+                return '';
+            }
+
+            if (is_string($value)) {
+                $value = json_decode($value, true);
+            }
+
+            return '<span class="badge badge-primary">查看详情</span>';
+        })->modal('额外数据', function ($modal) {
+            $value = $this->extra_data;
+
+            if (is_string($value)) {
+                $value = json_decode($value, true);
+            }
+
+            return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
+        });
+    }
+
+    /**
+     * 添加开发配置键列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnDevConfigKey(string $field = 'key', string $label = '配置键'): Column
+    {
+        return $this->grid->column($field, $label);
+    }
+
+    /**
+     * 添加开发配置值列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @param int $limit 限制长度
+     * @return Column
+     */
+    public function columnDevConfigValue(string $field = 'value', string $label = '配置值', int $limit = 50): Column
+    {
+        return $this->grid->column($field, $label)->limit($limit);
+    }
+
+    /**
+     * 添加日志文件名列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnLogFileName(string $field = 'name', string $label = '文件名'): Column
+    {
+        return $this->grid->column($field, $label);
+    }
+
+    /**
+     * 添加日志文件大小列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnLogFileSize(string $field = 'size', string $label = '文件大小'): Column
+    {
+        return $this->grid->column($field, $label);
+    }
+
+    /**
+     * 添加日志文件修改时间列
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Column
+     */
+    public function columnLogFileModified(string $field = 'modified', string $label = '修改时间'): Column
+    {
+        return $this->grid->column($field, $label);
+    }
+}

+ 15 - 0
app/Module/Dev/AdminControllers/Helper/ShowHelper.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use UCore\DcatAdmin\ShowHelper as BaseShowHelper;
+
+/**
+ * 详情页辅助类
+ *
+ * 提供开发工具模块后台控制器的详情页构建功能
+ */
+class ShowHelper extends BaseShowHelper
+{
+    use ShowHelperTrait;
+}

+ 97 - 0
app/Module/Dev/AdminControllers/Helper/ShowHelperTrait.php

@@ -0,0 +1,97 @@
+<?php
+
+namespace App\Module\Dev\AdminControllers\Helper;
+
+use App\Module\Dev\Enums\DEV_LOG_TYPE;
+use App\Module\Dev\Enums\DEV_STATUS;
+use Dcat\Admin\Show;
+
+/**
+ * 详情页辅助特性
+ *
+ * 提供开发工具模块后台控制器的详情页构建功能的具体实现
+ */
+trait ShowHelperTrait
+{
+    /**
+     * 显示开发工具状态
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Show\Field
+     */
+    public function fieldDevStatus(string $field = 'status', string $label = '状态'): Show\Field
+    {
+        return $this->show->field($field, $label)->as(function ($value) {
+            return DEV_STATUS::getAll()[$value] ?? '未知';
+        });
+    }
+
+    /**
+     * 显示开发日志类型
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Show\Field
+     */
+    public function fieldDevLogType(string $field = 'type', string $label = '日志类型'): Show\Field
+    {
+        return $this->show->field($field, $label)->as(function ($value) {
+            return DEV_LOG_TYPE::getAll()[$value] ?? '未知';
+        });
+    }
+
+    /**
+     * 显示开发日志内容
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Show\Field
+     */
+    public function fieldDevLogContent(string $field = 'content', string $label = '日志内容'): Show\Field
+    {
+        return $this->show->field($field, $label);
+    }
+
+    /**
+     * 显示开发日志额外数据
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Show\Field
+     */
+    public function fieldDevLogExtraData(string $field = 'extra_data', string $label = '额外数据'): Show\Field
+    {
+        return $this->show->field($field, $label)->json();
+    }
+
+    /**
+     * 显示开发配置值
+     *
+     * @param string $field 字段名
+     * @param string $label 标签名
+     * @return Show\Field
+     */
+    public function fieldDevConfigValue(string $field = 'value', string $label = '配置值'): Show\Field
+    {
+        return $this->show->field($field, $label);
+    }
+
+    /**
+     * 显示系统信息
+     *
+     * @param array $systemInfo 系统信息
+     * @return Show\Field
+     */
+    public function fieldSystemInfo(array $systemInfo): void
+    {
+        $this->show->divider('系统信息');
+
+        foreach ($systemInfo as $key => $value) {
+            $label = ucwords(str_replace('_', ' ', $key));
+            $this->show->field($key, $label)->as(function () use ($value) {
+                return $value;
+            });
+        }
+    }
+}

+ 90 - 0
app/Module/Dev/Docs/DEV.md

@@ -0,0 +1,90 @@
+# 开发工具模块开发计划
+
+## 1. 概述
+
+本文档描述了开发工具模块的开发计划和任务分解,包括各个组件的实现顺序和依赖关系。
+
+## 2. 开发环境准备
+
+- [x] 创建模块目录结构
+- [x] 配置开发环境
+- [x] 设置数据库连接
+
+## 3. 数据库设计与实现
+
+- [x] 设计开发工具表结构
+- [x] 设计开发日志表结构
+- [x] 设计开发配置表结构
+- [ ] 创建数据库迁移文件
+- [ ] 执行数据库迁移
+
+## 4. 实现模型层
+
+- [x] Dev模型
+- [x] DevLog模型
+- [x] DevConfig模型
+
+## 5. 实现枚举类
+
+- [x] DEV_STATUS枚举
+- [x] DEV_LOG_TYPE枚举
+
+## 6. 实现逻辑层
+
+- [x] DevLogic
+
+## 7. 实现服务层
+
+- [x] DevService
+- [x] LogViewerService
+
+## 8. 实现事件和监听器
+
+- [x] DevLogCreatedEvent
+- [x] DevLogEventListener
+
+## 9. 实现后台控制器
+
+- [ ] DevController
+- [ ] DevLogController
+- [ ] DevConfigController
+- [ ] LogViewerController
+
+## 10. 实现服务提供者
+
+- [x] DevServiceProvider
+
+## 11. 文档编写
+
+- [x] README.md
+- [x] 设计概述.md
+- [x] 数据库设计.md
+- [ ] 日志查看器.md
+- [ ] 开发配置.md
+- [ ] 系统信息.md
+
+## 12. 测试
+
+- [ ] 单元测试
+  - [ ] 模型测试
+  - [ ] 服务测试
+  - [ ] 逻辑测试
+- [ ] 功能测试
+  - [ ] 控制器测试
+  - [ ] API测试
+- [ ] 集成测试
+  - [ ] 与其他模块的集成测试
+
+## 13. 部署与上线
+
+- [ ] 准备部署脚本
+- [ ] 执行数据库迁移
+- [ ] 配置生产环境
+- [ ] 上线测试
+
+## 14. 后续优化
+
+- [ ] 性能优化
+- [ ] 缓存策略优化
+- [ ] 代码重构
+- [ ] 功能扩展

+ 30 - 0
app/Module/Dev/Docs/README.md

@@ -0,0 +1,30 @@
+# 开发工具模块文档索引
+
+## 概述
+
+开发工具模块提供了一系列开发和调试工具,帮助开发人员更高效地进行开发和调试工作。本目录包含了开发工具模块的详细设计文档。
+
+## 文档目录
+
+### 1. 基础设计文档
+
+- [设计概述](设计概述.md) - 模块的整体设计思路和架构
+- [数据库设计](数据库设计.md) - 详细的数据库表结构和关系设计
+- [DEV](DEV.md) - 模块的开发计划和进度
+
+### 2. 功能领域文档
+
+- [日志查看器](日志查看器.md) - 查看和管理系统日志
+- [开发配置](开发配置.md) - 管理开发环境配置
+- [系统信息](系统信息.md) - 查看系统运行信息
+
+### 3. 开发与实现文档
+
+- [开发指南](开发指南.md) - 模块开发的快速入门指南
+- [事件系统](事件系统.md) - 模块的事件系统设计与实现
+
+## 文档更新记录
+
+| 日期 | 版本 | 更新内容 | 更新人 |
+| ---- | ---- | -------- | ------ |
+| 2023-06-01 | v1.0 | 初始版本 | 系统管理员 |

+ 165 - 0
app/Module/Dev/Docs/数据库设计.md

@@ -0,0 +1,165 @@
+# 开发工具模块数据库设计
+
+## 1. 数据库表概览
+
+开发工具模块包含以下数据库表:
+
+| 表名 | 描述 |
+| ---- | ---- |
+| `dev_tools` | 存储开发工具基本信息 |
+| `dev_logs` | 存储开发日志记录 |
+| `dev_configs` | 存储开发配置项 |
+
+## 2. 表结构详细设计
+
+### 2.1 dev_tools 表
+
+存储开发工具的基本信息。
+
+#### 字段定义
+
+| 字段名 | 类型 | 允许空 | 默认值 | 描述 |
+| ------ | ---- | ------ | ------ | ---- |
+| `id` | bigint unsigned | 否 | 自增 | 主键ID |
+| `name` | varchar(100) | 否 | 无 | 工具名称 |
+| `description` | varchar(200) | 是 | NULL | 工具描述 |
+| `status` | tinyint | 否 | 1 | 状态:0-禁用,1-启用 |
+| `created_at` | timestamp | 是 | NULL | 创建时间 |
+| `updated_at` | timestamp | 是 | NULL | 更新时间 |
+| `deleted_at` | timestamp | 是 | NULL | 删除时间 |
+
+#### 索引
+
+| 索引名 | 类型 | 字段 |
+| ------ | ---- | ---- |
+| `PRIMARY` | 主键 | `id` |
+| `idx_name` | 普通索引 | `name` |
+| `idx_status` | 普通索引 | `status` |
+
+### 2.2 dev_logs 表
+
+存储开发日志记录。
+
+#### 字段定义
+
+| 字段名 | 类型 | 允许空 | 默认值 | 描述 |
+| ------ | ---- | ------ | ------ | ---- |
+| `id` | bigint unsigned | 否 | 自增 | 主键ID |
+| `type` | varchar(20) | 否 | 无 | 日志类型:info, warning, error, debug |
+| `content` | text | 否 | 无 | 日志内容 |
+| `ip` | varchar(45) | 是 | NULL | IP地址 |
+| `user_id` | int | 否 | 0 | 用户ID |
+| `user_agent` | varchar(255) | 是 | NULL | 用户代理 |
+| `extra_data` | json | 是 | NULL | 额外数据 |
+| `created_at` | timestamp | 是 | NULL | 创建时间 |
+| `updated_at` | timestamp | 是 | NULL | 更新时间 |
+
+#### 索引
+
+| 索引名 | 类型 | 字段 |
+| ------ | ---- | ---- |
+| `PRIMARY` | 主键 | `id` |
+| `idx_type` | 普通索引 | `type` |
+| `idx_user_id` | 普通索引 | `user_id` |
+| `idx_created_at` | 普通索引 | `created_at` |
+
+### 2.3 dev_configs 表
+
+存储开发配置项。
+
+#### 字段定义
+
+| 字段名 | 类型 | 允许空 | 默认值 | 描述 |
+| ------ | ---- | ------ | ------ | ---- |
+| `id` | bigint unsigned | 否 | 自增 | 主键ID |
+| `key` | varchar(100) | 否 | 无 | 配置键 |
+| `value` | text | 否 | 无 | 配置值 |
+| `description` | varchar(200) | 是 | NULL | 配置描述 |
+| `status` | tinyint | 否 | 1 | 状态:0-禁用,1-启用 |
+| `created_at` | timestamp | 是 | NULL | 创建时间 |
+| `updated_at` | timestamp | 是 | NULL | 更新时间 |
+
+#### 索引
+
+| 索引名 | 类型 | 字段 |
+| ------ | ---- | ---- |
+| `PRIMARY` | 主键 | `id` |
+| `idx_key` | 唯一索引 | `key` |
+| `idx_status` | 普通索引 | `status` |
+
+## 3. 数据库脚本
+
+### 3.1 创建 dev_tools 表
+
+```sql
+DROP TABLE IF EXISTS `kku_dev_tools`;
+CREATE TABLE `kku_dev_tools` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
+  `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '工具名称',
+  `description` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '工具描述',
+  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态:0-禁用,1-启用',
+  `created_at` timestamp NULL DEFAULT NULL,
+  `updated_at` timestamp NULL DEFAULT NULL,
+  `deleted_at` timestamp NULL DEFAULT NULL COMMENT '删除时间',
+  PRIMARY KEY (`id`),
+  KEY `idx_name` (`name`),
+  KEY `idx_status` (`status`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+```
+
+### 3.2 创建 dev_logs 表
+
+```sql
+DROP TABLE IF EXISTS `kku_dev_logs`;
+CREATE TABLE `kku_dev_logs` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
+  `type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '日志类型:info, warning, error, debug',
+  `content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '日志内容',
+  `ip` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'IP地址',
+  `user_id` int NOT NULL DEFAULT '0' COMMENT '用户ID',
+  `user_agent` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '用户代理',
+  `extra_data` json DEFAULT NULL COMMENT '额外数据',
+  `created_at` timestamp NULL DEFAULT NULL,
+  `updated_at` timestamp NULL DEFAULT NULL,
+  PRIMARY KEY (`id`),
+  KEY `idx_type` (`type`),
+  KEY `idx_user_id` (`user_id`),
+  KEY `idx_created_at` (`created_at`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+```
+
+### 3.3 创建 dev_configs 表
+
+```sql
+DROP TABLE IF EXISTS `kku_dev_configs`;
+CREATE TABLE `kku_dev_configs` (
+  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
+  `key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '配置键',
+  `value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '配置值',
+  `description` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '配置描述',
+  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态:0-禁用,1-启用',
+  `created_at` timestamp NULL DEFAULT NULL,
+  `updated_at` timestamp NULL DEFAULT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `idx_key` (`key`),
+  KEY `idx_status` (`status`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+```
+
+## 4. 数据字典
+
+### 4.1 日志类型枚举
+
+| 值 | 描述 |
+| -- | ---- |
+| `info` | 信息 |
+| `warning` | 警告 |
+| `error` | 错误 |
+| `debug` | 调试 |
+
+### 4.2 状态枚举
+
+| 值 | 描述 |
+| -- | ---- |
+| `0` | 禁用 |
+| `1` | 启用 |

+ 95 - 0
app/Module/Dev/Docs/设计概述.md

@@ -0,0 +1,95 @@
+# 开发工具模块设计概述
+
+## 1. 模块简介
+
+开发工具模块提供了一系列开发和调试工具,帮助开发人员更高效地进行开发和调试工作。该模块包含日志查看器、开发配置管理、系统信息查看等功能。
+
+## 2. 核心功能
+
+- **日志查看器**:查看和管理系统日志文件
+- **开发配置管理**:管理开发环境的配置项
+- **系统信息查看**:查看系统运行环境和状态信息
+- **开发日志记录**:记录开发过程中的关键操作和事件
+
+## 3. 模块架构
+
+### 3.1 目录结构
+
+开发工具模块采用标准的模块化目录结构,便于代码组织和维护:
+
+```
+app/Module/Dev/
+├── AdminControllers/        # 后台管理控制器
+├── Databases/               # 数据库相关文件
+│   └── GenerateSql/         # 数据库创建脚本
+├── Docs/                    # 模块文档
+├── Enums/                   # 枚举类型定义
+├── Events/                  # 事件类
+├── Listeners/               # 事件监听器
+├── Logics/                  # 业务逻辑类
+├── Models/                  # 数据模型
+├── Providers/               # 服务提供者
+└── Services/                # 服务类
+```
+
+### 3.2 核心组件
+
+#### 3.2.1 模型层 (Models)
+
+开发工具模块的核心数据模型包括:
+
+- **Dev**:开发工具模型,存储开发工具的基本信息
+- **DevLog**:开发日志模型,记录开发过程中的操作和事件
+- **DevConfig**:开发配置模型,存储开发环境的配置项
+
+#### 3.2.2 逻辑层 (Logics)
+
+逻辑层包含核心业务逻辑,仅供模块内部使用:
+
+- **DevLogic**:开发工具核心逻辑,处理开发工具的创建、更新、删除等
+
+#### 3.2.3 服务层 (Services)
+
+服务层对外提供功能接口,是模块与外部交互的主要方式:
+
+- **DevService**:开发工具服务,提供开发工具的查询、创建、更新等功能
+- **LogViewerService**:日志查看服务,提供日志文件的查看和管理功能
+
+#### 3.2.4 事件系统 (Events & Listeners)
+
+开发工具模块定义了以下核心事件:
+
+- **DevLogCreatedEvent**:开发日志创建事件
+
+## 4. 设计原则
+
+开发工具模块的设计遵循以下原则:
+
+### 4.1 单一职责原则
+每个类只负责一个功能领域,如日志查看、配置管理等。
+
+### 4.2 开闭原则
+模块设计为可扩展的,新功能可以通过扩展而非修改现有代码来实现。
+
+### 4.3 依赖倒置原则
+高层模块不应该依赖低层模块,两者都应该依赖抽象。
+
+### 4.4 接口隔离原则
+不强制客户端依赖于它们不使用的接口。
+
+### 4.5 最小知识原则
+一个对象应该对其他对象有最少的了解。
+
+## 5. 与其他模块的交互
+
+开发工具模块主要与以下模块交互:
+
+- **用户模块**:获取用户信息,用于记录操作日志
+- **系统模块**:获取系统运行信息
+
+## 6. 扩展点
+
+开发工具模块提供以下扩展点:
+
+- **事件系统**:其他模块可以监听开发工具模块的事件
+- **服务接口**:其他模块可以调用开发工具模块的服务接口

+ 49 - 0
app/Module/Dev/Enums/DEV_LOG_TYPE.php

@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Module\Dev\Enums;
+
+use UCore\Enum\EnumCore;
+use UCore\Enum\EnumToString;
+
+/**
+ * 开发日志类型枚举
+ */
+enum DEV_LOG_TYPE: string
+{
+    use EnumCore, EnumToString;
+
+    /**
+     * 信息
+     */
+    case INFO = 'info';
+
+    /**
+     * 警告
+     */
+    case WARNING = 'warning';
+
+    /**
+     * 错误
+     */
+    case ERROR = 'error';
+
+    /**
+     * 调试
+     */
+    case DEBUG = 'debug';
+
+    /**
+     * 获取所有日志类型
+     *
+     * @return array
+     */
+    public static function getAll(): array
+    {
+        return [
+            self::INFO->value => '信息',
+            self::WARNING->value => '警告',
+            self::ERROR->value => '错误',
+            self::DEBUG->value => '调试',
+        ];
+    }
+}

+ 37 - 0
app/Module/Dev/Enums/DEV_STATUS.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Module\Dev\Enums;
+
+use UCore\Enum\EnumCore;
+use UCore\Enum\EnumToInt;
+
+/**
+ * 开发工具状态枚举
+ */
+enum DEV_STATUS: int
+{
+    use EnumCore, EnumToInt;
+
+    /**
+     * 禁用
+     */
+    case DISABLED = 0;
+
+    /**
+     * 启用
+     */
+    case ENABLED = 1;
+
+    /**
+     * 获取所有状态
+     *
+     * @return array
+     */
+    public static function getAll(): array
+    {
+        return [
+            self::DISABLED->value => '禁用',
+            self::ENABLED->value => '启用',
+        ];
+    }
+}

+ 34 - 0
app/Module/Dev/Events/DevLogCreatedEvent.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Module\Dev\Events;
+
+use App\Module\Dev\Models\DevLog;
+use Illuminate\Broadcasting\InteractsWithSockets;
+use Illuminate\Foundation\Events\Dispatchable;
+use Illuminate\Queue\SerializesModels;
+
+/**
+ * 开发日志创建事件
+ */
+class DevLogCreatedEvent
+{
+    use Dispatchable, InteractsWithSockets, SerializesModels;
+
+    /**
+     * 开发日志模型
+     *
+     * @var DevLog
+     */
+    public DevLog $log;
+
+    /**
+     * 创建一个新的事件实例
+     *
+     * @param DevLog $log
+     * @return void
+     */
+    public function __construct(DevLog $log)
+    {
+        $this->log = $log;
+    }
+}

+ 52 - 0
app/Module/Dev/Listeners/DevLogEventListener.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Module\Dev\Listeners;
+
+use App\Module\Dev\Events\DevLogCreatedEvent;
+use Illuminate\Support\Facades\Log;
+
+/**
+ * 开发日志事件监听器
+ */
+class DevLogEventListener
+{
+    /**
+     * 处理开发日志创建事件
+     *
+     * @param DevLogCreatedEvent $event
+     * @return void
+     */
+    public function handleDevLogCreated(DevLogCreatedEvent $event): void
+    {
+        try {
+            // 记录日志
+            Log::info('开发日志创建', [
+                'log_id' => $event->log->id,
+                'type' => $event->log->type,
+                'content' => $event->log->content,
+                'user_id' => $event->log->user_id,
+            ]);
+
+            // 这里可以添加其他处理逻辑,如发送通知等
+        } catch (\Exception $e) {
+            Log::error('处理开发日志创建事件失败', [
+                'error' => $e->getMessage(),
+                'log_id' => $event->log->id,
+            ]);
+        }
+    }
+
+    /**
+     * 注册监听器
+     *
+     * @param \Illuminate\Events\Dispatcher $events
+     * @return void
+     */
+    public function subscribe($events): void
+    {
+        $events->listen(
+            DevLogCreatedEvent::class,
+            [DevLogEventListener::class, 'handleDevLogCreated']
+        );
+    }
+}

+ 155 - 0
app/Module/Dev/Logics/DevLogic.php

@@ -0,0 +1,155 @@
+<?php
+
+namespace App\Module\Dev\Logics;
+
+use App\Module\Dev\Events\DevLogCreatedEvent;
+use App\Module\Dev\Models\Dev;
+use App\Module\Dev\Models\DevLog;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Request;
+
+/**
+ * 开发工具逻辑类
+ *
+ * 处理开发工具相关的业务逻辑
+ */
+class DevLogic
+{
+    /**
+     * 获取开发工具列表
+     *
+     * @param array $params 查询参数
+     * @return \Illuminate\Pagination\LengthAwarePaginator
+     */
+    public static function getDevTools(array $params = [])
+    {
+        $query = Dev::query();
+
+        if (!empty($params['name'])) {
+            $query->where('name', 'like', '%' . $params['name'] . '%');
+        }
+
+        if (isset($params['status'])) {
+            $query->where('status', $params['status']);
+        }
+
+        return $query->paginate($params['per_page'] ?? 15);
+    }
+
+    /**
+     * 创建开发工具
+     *
+     * @param array $data 开发工具数据
+     * @return Dev
+     */
+    public static function createDevTool(array $data): Dev
+    {
+        try {
+            return DB::transaction(function () use ($data) {
+                return Dev::create($data);
+            });
+        } catch (\Exception $e) {
+            Log::error('创建开发工具失败', [
+                'error' => $e->getMessage(),
+                'data' => $data
+            ]);
+            throw $e;
+        }
+    }
+
+    /**
+     * 更新开发工具
+     *
+     * @param int $id 开发工具ID
+     * @param array $data 开发工具数据
+     * @return bool
+     */
+    public static function updateDevTool(int $id, array $data): bool
+    {
+        try {
+            return DB::transaction(function () use ($id, $data) {
+                $devTool = Dev::find($id);
+
+                if (!$devTool) {
+                    return false;
+                }
+
+                return $devTool->update($data);
+            });
+        } catch (\Exception $e) {
+            Log::error('更新开发工具失败', [
+                'error' => $e->getMessage(),
+                'id' => $id,
+                'data' => $data
+            ]);
+            return false;
+        }
+    }
+
+    /**
+     * 删除开发工具
+     *
+     * @param int $id 开发工具ID
+     * @return bool
+     */
+    public static function deleteDevTool(int $id): bool
+    {
+        try {
+            return DB::transaction(function () use ($id) {
+                $devTool = Dev::find($id);
+
+                if (!$devTool) {
+                    return false;
+                }
+
+                return $devTool->delete();
+            });
+        } catch (\Exception $e) {
+            Log::error('删除开发工具失败', [
+                'error' => $e->getMessage(),
+                'id' => $id
+            ]);
+            return false;
+        }
+    }
+
+    /**
+     * 记录开发日志
+     *
+     * @param string $type 日志类型
+     * @param string $content 日志内容
+     * @param array $extraData 额外数据
+     * @return DevLog
+     */
+    public static function log(string $type, string $content, array $extraData = []): DevLog
+    {
+        try {
+            $data = [
+                'type' => $type,
+                'content' => $content,
+                'ip' => Request::ip(),
+                'user_id' => auth()->id() ?? 0,
+                'user_agent' => Request::userAgent(),
+                'extra_data' => $extraData,
+            ];
+
+            $log = DevLog::create($data);
+
+            // 触发日志创建事件
+            event(new DevLogCreatedEvent($log));
+
+            return $log;
+        } catch (\Exception $e) {
+            Log::error('记录开发日志失败', [
+                'error' => $e->getMessage(),
+                'type' => $type,
+                'content' => $content,
+                'extra_data' => $extraData
+            ]);
+
+            // 创建失败时,返回一个空的日志对象
+            return new DevLog();
+        }
+    }
+}

+ 69 - 0
app/Module/Dev/Models/Dev.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Module\Dev\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * 开发工具模型
+ *
+ * @property int $id ID
+ * @property string $name 名称
+ * @property string $description 描述
+ * @property int $status 状态
+ * @property \Carbon\Carbon $created_at 创建时间
+ * @property \Carbon\Carbon $updated_at 更新时间
+ * @property \Carbon\Carbon $deleted_at 删除时间
+ */
+class Dev extends Model
+{
+    use SoftDeletes;
+
+    /**
+     * 表名
+     *
+     * @var string
+     */
+    protected $table = 'dev_tools';
+
+    /**
+     * 可批量赋值的属性
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'name',
+        'description',
+        'status',
+    ];
+
+    /**
+     * 隐藏的属性
+     *
+     * @var array
+     */
+    protected $hidden = [
+        'deleted_at',
+    ];
+
+    /**
+     * 日期字段
+     *
+     * @var array
+     */
+    protected $dates = [
+        'created_at',
+        'updated_at',
+        'deleted_at',
+    ];
+
+    /**
+     * 属性类型转换
+     *
+     * @var array
+     */
+    protected $casts = [
+        'status' => 'integer',
+    ];
+}

+ 57 - 0
app/Module/Dev/Models/DevConfig.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Module\Dev\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 开发配置模型
+ *
+ * @property int $id ID
+ * @property string $key 配置键
+ * @property string $value 配置值
+ * @property string $description 描述
+ * @property int $status 状态
+ * @property \Carbon\Carbon $created_at 创建时间
+ * @property \Carbon\Carbon $updated_at 更新时间
+ */
+class DevConfig extends Model
+{
+    /**
+     * 表名
+     *
+     * @var string
+     */
+    protected $table = 'dev_configs';
+
+    /**
+     * 可批量赋值的属性
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'key',
+        'value',
+        'description',
+        'status',
+    ];
+
+    /**
+     * 日期字段
+     *
+     * @var array
+     */
+    protected $dates = [
+        'created_at',
+        'updated_at',
+    ];
+
+    /**
+     * 属性类型转换
+     *
+     * @var array
+     */
+    protected $casts = [
+        'status' => 'integer',
+    ];
+}

+ 62 - 0
app/Module/Dev/Models/DevLog.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace App\Module\Dev\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * 开发日志模型
+ *
+ * @property int $id ID
+ * @property string $type 日志类型
+ * @property string $content 日志内容
+ * @property string $ip IP地址
+ * @property int $user_id 用户ID
+ * @property string $user_agent 用户代理
+ * @property array $extra_data 额外数据
+ * @property \Carbon\Carbon $created_at 创建时间
+ * @property \Carbon\Carbon $updated_at 更新时间
+ */
+class DevLog extends Model
+{
+    /**
+     * 表名
+     *
+     * @var string
+     */
+    protected $table = 'dev_logs';
+
+    /**
+     * 可批量赋值的属性
+     *
+     * @var array
+     */
+    protected $fillable = [
+        'type',
+        'content',
+        'ip',
+        'user_id',
+        'user_agent',
+        'extra_data',
+    ];
+
+    /**
+     * 日期字段
+     *
+     * @var array
+     */
+    protected $dates = [
+        'created_at',
+        'updated_at',
+    ];
+
+    /**
+     * 属性类型转换
+     *
+     * @var array
+     */
+    protected $casts = [
+        'user_id' => 'integer',
+        'extra_data' => 'array',
+    ];
+}

+ 74 - 0
app/Module/Dev/Providers/DevServiceProvider.php

@@ -0,0 +1,74 @@
+<?php
+
+namespace App\Module\Dev\Providers;
+
+use App\Module\Dev\Events\DevLogCreatedEvent;
+use App\Module\Dev\Listeners\DevLogEventListener;
+use Illuminate\Support\ServiceProvider;
+
+/**
+ * 开发模块服务提供者
+ */
+class DevServiceProvider extends ServiceProvider
+{
+    /**
+     * 事件到监听器的映射
+     *
+     * @var array
+     */
+    protected $listen = [
+        DevLogCreatedEvent::class => [
+            DevLogEventListener::class . '@handleDevLogCreated',
+        ],
+    ];
+
+    /**
+     * 需要注册的订阅者
+     *
+     * @var array
+     */
+    protected $subscribe = [
+        DevLogEventListener::class,
+    ];
+
+    /**
+     * 注册服务
+     *
+     * @return void
+     */
+    public function register(): void
+    {
+        // 注册服务...
+    }
+
+    /**
+     * 启动服务
+     *
+     * @return void
+     */
+    public function boot(): void
+    {
+        // 注册事件监听器
+        $this->registerEvents();
+    }
+
+    /**
+     * 注册事件和监听器
+     *
+     * @return void
+     */
+    protected function registerEvents(): void
+    {
+        $events = $this->app['events'];
+
+        foreach ($this->listen as $event => $listeners) {
+            foreach ($listeners as $listener) {
+                $events->listen($event, $listener);
+            }
+        }
+
+        foreach ($this->subscribe as $subscriber) {
+            $events->subscribe($subscriber);
+        }
+    }
+}

+ 215 - 0
app/Module/Dev/Services/DevService.php

@@ -0,0 +1,215 @@
+<?php
+
+namespace App\Module\Dev\Services;
+
+use App\Module\Dev\Enums\DEV_LOG_TYPE;
+use App\Module\Dev\Logics\DevLogic;
+use App\Module\Dev\Models\Dev;
+use App\Module\Dev\Models\DevConfig;
+use App\Module\Dev\Models\DevLog;
+use Illuminate\Support\Facades\Cache;
+
+/**
+ * 开发工具服务类
+ *
+ * 提供开发工具相关的服务方法,供其他模块调用
+ */
+class DevService
+{
+    /**
+     * 获取开发工具列表
+     *
+     * @param array $params 查询参数
+     * @return \Illuminate\Pagination\LengthAwarePaginator
+     */
+    public static function getDevTools(array $params = [])
+    {
+        return DevLogic::getDevTools($params);
+    }
+
+    /**
+     * 获取开发工具详情
+     *
+     * @param int $id 开发工具ID
+     * @return Dev|null
+     */
+    public static function getDevToolDetail(int $id): ?Dev
+    {
+        return Dev::find($id);
+    }
+
+    /**
+     * 创建开发工具
+     *
+     * @param array $data 开发工具数据
+     * @return Dev
+     */
+    public static function createDevTool(array $data): Dev
+    {
+        return DevLogic::createDevTool($data);
+    }
+
+    /**
+     * 更新开发工具
+     *
+     * @param int $id 开发工具ID
+     * @param array $data 开发工具数据
+     * @return bool
+     */
+    public static function updateDevTool(int $id, array $data): bool
+    {
+        return DevLogic::updateDevTool($id, $data);
+    }
+
+    /**
+     * 删除开发工具
+     *
+     * @param int $id 开发工具ID
+     * @return bool
+     */
+    public static function deleteDevTool(int $id): bool
+    {
+        return DevLogic::deleteDevTool($id);
+    }
+
+    /**
+     * 记录开发日志
+     *
+     * @param string $type 日志类型
+     * @param string $content 日志内容
+     * @param array $extraData 额外数据
+     * @return DevLog
+     */
+    public static function log(string $type, string $content, array $extraData = []): DevLog
+    {
+        return DevLogic::log($type, $content, $extraData);
+    }
+
+    /**
+     * 记录信息日志
+     *
+     * @param string $content 日志内容
+     * @param array $extraData 额外数据
+     * @return DevLog
+     */
+    public static function logInfo(string $content, array $extraData = []): DevLog
+    {
+        return self::log(DEV_LOG_TYPE::INFO->value, $content, $extraData);
+    }
+
+    /**
+     * 记录警告日志
+     *
+     * @param string $content 日志内容
+     * @param array $extraData 额外数据
+     * @return DevLog
+     */
+    public static function logWarning(string $content, array $extraData = []): DevLog
+    {
+        return self::log(DEV_LOG_TYPE::WARNING->value, $content, $extraData);
+    }
+
+    /**
+     * 记录错误日志
+     *
+     * @param string $content 日志内容
+     * @param array $extraData 额外数据
+     * @return DevLog
+     */
+    public static function logError(string $content, array $extraData = []): DevLog
+    {
+        return self::log(DEV_LOG_TYPE::ERROR->value, $content, $extraData);
+    }
+
+    /**
+     * 记录调试日志
+     *
+     * @param string $content 日志内容
+     * @param array $extraData 额外数据
+     * @return DevLog
+     */
+    public static function logDebug(string $content, array $extraData = []): DevLog
+    {
+        return self::log(DEV_LOG_TYPE::DEBUG->value, $content, $extraData);
+    }
+
+    /**
+     * 获取开发配置
+     *
+     * @param string $key 配置键
+     * @param mixed $default 默认值
+     * @return mixed
+     */
+    public static function getConfig(string $key, $default = null)
+    {
+        $cacheKey = 'dev_config_' . $key;
+
+        return Cache::remember($cacheKey, 3600, function () use ($key, $default) {
+            $config = DevConfig::where('key', $key)->first();
+            return $config ? $config->value : $default;
+        });
+    }
+
+    /**
+     * 设置开发配置
+     *
+     * @param string $key 配置键
+     * @param mixed $value 配置值
+     * @param string $description 描述
+     * @return DevConfig
+     */
+    public static function setConfig(string $key, $value, string $description = ''): DevConfig
+    {
+        $config = DevConfig::updateOrCreate(
+            ['key' => $key],
+            [
+                'value' => $value,
+                'description' => $description,
+                'status' => 1,
+            ]
+        );
+
+        // 清除缓存
+        Cache::forget('dev_config_' . $key);
+
+        return $config;
+    }
+
+    /**
+     * 获取所有开发配置
+     *
+     * @return \Illuminate\Database\Eloquent\Collection
+     */
+    public static function getAllConfigs()
+    {
+        return DevConfig::all();
+    }
+
+    /**
+     * 获取系统信息
+     *
+     * @return array
+     */
+    public static function getSystemInfo(): array
+    {
+        return [
+            'php_version' => PHP_VERSION,
+            'laravel_version' => app()->version(),
+            'server_software' => $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown',
+            'server_os' => PHP_OS,
+            'database_connection' => config('database.default'),
+            'cache_driver' => config('cache.default'),
+            'session_driver' => config('session.driver'),
+            'queue_connection' => config('queue.default'),
+            'timezone' => config('app.timezone'),
+            'locale' => config('app.locale'),
+            'env' => config('app.env'),
+            'debug' => config('app.debug'),
+            'url' => config('app.url'),
+            'memory_limit' => ini_get('memory_limit'),
+            'max_execution_time' => ini_get('max_execution_time'),
+            'upload_max_filesize' => ini_get('upload_max_filesize'),
+            'post_max_size' => ini_get('post_max_size'),
+        ];
+    }
+}

+ 194 - 0
app/Module/Dev/Services/LogViewerService.php

@@ -0,0 +1,194 @@
+<?php
+
+namespace App\Module\Dev\Services;
+
+use Illuminate\Support\Facades\File;
+use Illuminate\Support\Facades\Storage;
+
+/**
+ * 日志查看服务类
+ *
+ * 提供日志查看相关的服务方法,供其他模块调用
+ */
+class LogViewerService
+{
+    /**
+     * 获取日志文件列表
+     *
+     * @return array
+     */
+    public static function getLogFiles(): array
+    {
+        $path = storage_path('logs');
+        $files = File::files($path);
+
+        $logFiles = [];
+        foreach ($files as $file) {
+            if ($file->getExtension() === 'log') {
+                $logFiles[] = [
+                    'name' => $file->getFilename(),
+                    'path' => $file->getPathname(),
+                    'size' => self::formatFileSize($file->getSize()),
+                    'modified' => date('Y-m-d H:i:s', $file->getMTime()),
+                ];
+            }
+        }
+
+        // 按修改时间排序
+        usort($logFiles, function ($a, $b) {
+            return strtotime($b['modified']) - strtotime($a['modified']);
+        });
+
+        return $logFiles;
+    }
+
+    /**
+     * 获取日志文件内容
+     *
+     * @param string $filename 文件名
+     * @param int $lines 行数
+     * @return array
+     */
+    public static function getLogContent(string $filename, int $lines = 1000): array
+    {
+        $path = storage_path('logs/' . $filename);
+
+        if (!File::exists($path)) {
+            return [
+                'error' => '文件不存在',
+                'content' => [],
+            ];
+        }
+
+        // 读取最后N行
+        $content = self::tailFile($path, $lines);
+
+        // 解析日志内容
+        $parsedContent = self::parseLogContent($content);
+
+        return [
+            'filename' => $filename,
+            'path' => $path,
+            'size' => self::formatFileSize(File::size($path)),
+            'modified' => date('Y-m-d H:i:s', File::lastModified($path)),
+            'content' => $parsedContent,
+        ];
+    }
+
+    /**
+     * 清空日志文件
+     *
+     * @param string $filename 文件名
+     * @return bool
+     */
+    public static function clearLogFile(string $filename): bool
+    {
+        $path = storage_path('logs/' . $filename);
+
+        if (!File::exists($path)) {
+            return false;
+        }
+
+        // 清空文件内容
+        file_put_contents($path, '');
+
+        return true;
+    }
+
+    /**
+     * 删除日志文件
+     *
+     * @param string $filename 文件名
+     * @return bool
+     */
+    public static function deleteLogFile(string $filename): bool
+    {
+        $path = storage_path('logs/' . $filename);
+
+        if (!File::exists($path)) {
+            return false;
+        }
+
+        // 删除文件
+        return File::delete($path);
+    }
+
+    /**
+     * 格式化文件大小
+     *
+     * @param int $size 文件大小(字节)
+     * @return string
+     */
+    protected static function formatFileSize(int $size): string
+    {
+        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
+
+        $i = 0;
+        while ($size >= 1024 && $i < count($units) - 1) {
+            $size /= 1024;
+            $i++;
+        }
+
+        return round($size, 2) . ' ' . $units[$i];
+    }
+
+    /**
+     * 读取文件最后N行
+     *
+     * @param string $path 文件路径
+     * @param int $lines 行数
+     * @return string
+     */
+    protected static function tailFile(string $path, int $lines): string
+    {
+        $file = fopen($path, 'r');
+        $total_lines = count(file($path));
+
+        if ($total_lines <= $lines) {
+            $result = file_get_contents($path);
+            fclose($file);
+            return $result;
+        }
+
+        $line_counter = 0;
+        $position = -1;
+        $buffer = '';
+
+        while ($line_counter < $lines && fseek($file, $position, SEEK_END) !== -1) {
+            $char = fgetc($file);
+            if ($char === "\n") {
+                $line_counter++;
+            }
+            $buffer = $char . $buffer;
+            $position--;
+        }
+
+        fclose($file);
+        return $buffer;
+    }
+
+    /**
+     * 解析日志内容
+     *
+     * @param string $content 日志内容
+     * @return array
+     */
+    protected static function parseLogContent(string $content): array
+    {
+        $pattern = '/\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\] (\w+)\.(\w+): (.*?)(?=\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\]|$)/s';
+
+        preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
+
+        $parsedContent = [];
+        foreach ($matches as $match) {
+            $parsedContent[] = [
+                'datetime' => $match[1],
+                'environment' => $match[2],
+                'level' => $match[3],
+                'message' => trim($match[4]),
+            ];
+        }
+
+        return $parsedContent;
+    }
+}