diff --git a/app/admin/controller/system/McpLog.php b/app/admin/controller/system/McpLog.php new file mode 100644 index 0000000..e790255 --- /dev/null +++ b/app/admin/controller/system/McpLog.php @@ -0,0 +1,14 @@ + 'desc', + ]; + + public function __construct(App $app) + { + parent::__construct($app); + + $this->model = new SystemMcpLog(); + + // 密钥下拉(搜索用);SystemMcpKey 软删自动排除 + $this->assign('select_list_mcp_key', SystemMcpKey::select(), true); + } + + /** + * @NodeAnotation(title="列表") + */ + public function index() + { + if ($this->request->isAjax()) { + if (input('selectFields')) { + return $this->selectList(); + } + list($page, $limit, $where) = $this->buildTableParames(); + $count = $this->model + ->withJoin('mcpKey', 'LEFT') + ->where($where) + ->count(); + $list = $this->model + ->withJoin('mcpKey', 'LEFT') + ->where($where) + ->page($page, $limit) + ->order($this->sort) + ->select(); + $data = [ + 'code' => 0, + 'msg' => '', + 'count' => $count, + 'data' => $list, + ]; + + return json($data); + } + + return $this->fetch(); + } + + /** + * @NodeAnotation(title="删除") + */ + public function delete($id) + { + $this->checkPostRequest(); + $row = $this->model->whereIn('id', $id)->select(); + $row->isEmpty() && $this->error('数据不存在'); + try { + // 仅删除日志记录,不级联影响密钥表 + $save = $row->delete(); + } catch (\Exception $e) { + $this->error('删除失败:' . $e->getMessage()); + } + $save ? $this->success('删除成功') : $this->error('删除失败'); + } +} diff --git a/extend/base/admin/model/SystemMcpLogBase.php b/extend/base/admin/model/SystemMcpLogBase.php index b31c13e..9b887c0 100644 --- a/extend/base/admin/model/SystemMcpLogBase.php +++ b/extend/base/admin/model/SystemMcpLogBase.php @@ -4,9 +4,30 @@ namespace base\admin\model; use app\common\model\TimeModel; +/** + * @property int $id + * @property int $key_id 密钥ID + * @property string $node 节点 + * @property string $arguments 参数摘要JSON + * @property int $is_success 是否成功 0:失败,1:成功 + * @property int $cost_ms 耗时毫秒 + * @property int $create_time 创建时间 + * @property \app\admin\model\SystemMcpKey|null $mcpKey 密钥 + */ class SystemMcpLogBase extends TimeModel { protected $updateTime = false; protected $deleteTime = false; + + /** + * 所属密钥. + * withJoin 为 LEFT JOIN 且不附加软删条件: + * 密钥不存在时关联字段为 null、软删密钥仍可 join 出(delete_time > 0), + * 前端据 mcp_key.title / mcp_key.delete_time 兜底显示"(已删除)#id"。 + */ + public function mcpKey() + { + return $this->belongsTo('app\admin\model\SystemMcpKey', 'key_id', 'id'); + } } diff --git a/extend/base/admin/view/system/mcp_log/_common.js b/extend/base/admin/view/system/mcp_log/_common.js new file mode 100644 index 0000000..9ca0b6b --- /dev/null +++ b/extend/base/admin/view/system/mcp_log/_common.js @@ -0,0 +1,11 @@ +var init = { + tableElem: '#currentTable', + tableRenderId: 'currentTableRenderId', + indexUrl: 'system.mcp_log/index', + addUrl: '', + editUrl: '', + readUrl: '', + deleteUrl: 'system.mcp_log/delete', + exportUrl: '', + modifyUrl: '', +}; diff --git a/extend/base/admin/view/system/mcp_log/index.html b/extend/base/admin/view/system/mcp_log/index.html new file mode 100644 index 0000000..911b1b8 --- /dev/null +++ b/extend/base/admin/view/system/mcp_log/index.html @@ -0,0 +1,9 @@ +
+
+ +
+
+
diff --git a/extend/base/admin/view/system/mcp_log/index.js b/extend/base/admin/view/system/mcp_log/index.js new file mode 100644 index 0000000..1902f53 --- /dev/null +++ b/extend/base/admin/view/system/mcp_log/index.js @@ -0,0 +1,46 @@ +$(function(){ + // 密钥名称:LEFT JOIN 关联,密钥不存在或已软删时兜底显示 + var keyNameTemplet = function(d) { + if (d.mcp_key && d.mcp_key.title && (!d.mcp_key.delete_time || d.mcp_key.delete_time === 0)) { + return d.mcp_key.title; + } + return '(已删除)#' + d.key_id + ''; + }; + + // 成功/失败徽章 + var successTemplet = function(d) { + if (d.is_success == 1) { + return '成功'; + } + return '失败'; + }; + + // 参数摘要:截断 200 字符,title 悬浮全文 + var argumentsTemplet = function(d) { + if (!d.arguments) return '-'; + var text = String(d.arguments); + var safe = text.replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"').replace(/'/g,'''); + if (text.length > 200) { + return '' + safe.substring(0, 200) + '...'; + } + return safe; + }; + + ua.table.render({ + init: init, + toolbar: ['refresh', 'delete'], + defaultToolbar: ['filter'], + cols: [[ + {type: 'checkbox'}, + {field: 'id', title: 'ID', width: 80, sort: true}, + {field: 'key_id', title: '密钥', minWidth: 140, templet: keyNameTemplet, search: 'select', selectList: ua.getDataBrage('select_list_mcp_key'), selectValue: 'id', selectLabel: 'title'}, + {field: 'node', title: '节点', minWidth: 180}, + {field: 'is_success', title: '状态', width: 90, templet: successTemplet, search: 'select', selectList: {1: '成功', 0: '失败'}}, + {field: 'cost_ms', title: '耗时(ms)', width: 100, search: false}, + {field: 'arguments', title: '参数摘要', minWidth: 220, templet: argumentsTemplet, search: false}, + {field: 'create_time', title: '调用时间', width: 170, templet: ua.table.date, search: 'range'}, + ]], + }); + + ua.listen(); +})