From fe378eccd5911890b977eb188f6a3be661a32171 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Thu, 14 Aug 2025 11:23:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/helper/ViewHelper.php | 32 ++++++++++++++++++++++++++++++++ src/service/RecorderService.php | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/helper/ViewHelper.php b/src/helper/ViewHelper.php index 50b5928..bd1bbb4 100644 --- a/src/helper/ViewHelper.php +++ b/src/helper/ViewHelper.php @@ -461,6 +461,15 @@ class ViewHelper try { // 尝试使用ThinkPHP的视图渲染 if (class_exists('\\think\\facade\\View')) { + // 构建插件模板的完整路径 + $pluginViewPath = static::getPluginViewPath($template); + + // 如果插件模板文件存在,使用完整路径加载 + if (file_exists($pluginViewPath)) { + return View::fetch($pluginViewPath, $vars); + } + + // 否则尝试使用原始模板路径(用于自定义模板) return View::fetch($template, $vars); } } catch (\Exception $e) { @@ -472,6 +481,29 @@ class ViewHelper return static::renderBuiltinHtml($template, $vars); } + /** + * 获取插件视图文件的完整路径 + * @param string $template 模板路径 + * @return string + */ + protected static function getPluginViewPath(string $template): string + { + // 获取当前文件的目录 (/path/to/plugs/think-plugs-recorder/src/helper) + $currentDir = __DIR__; + + // 向上两级回到插件根目录 (/path/to/plugs/think-plugs-recorder) + $pluginDir = dirname(dirname($currentDir)); + + // 标准化模板路径中的分隔符 + $template = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $template); + + // 构建视图文件路径 + $viewPath = $pluginDir . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . $template . '.html'; + + // 返回标准化的绝对路径 + return realpath($viewPath) ?: $viewPath; + } + /** * 内置HTML渲染 * @param string $template diff --git a/src/service/RecorderService.php b/src/service/RecorderService.php index ed35f2e..f1d9d05 100644 --- a/src/service/RecorderService.php +++ b/src/service/RecorderService.php @@ -478,7 +478,7 @@ class RecorderService extends Service // 基础查询条件 $query->where('data_type', $dataType) ->where('data_id', $dataId) - ->where('operation_type', '<>', '读取'); // 排除读取操作 + ->whereNotIn('operation_type', ['读取', '查看']); // 排除读取操作 // 额外条件 if (!empty($conditions['start_time'])) {