From aa2612bcb9bb75f37689e2fad20d6c7f83fdfc5c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=89=AB=E5=9C=B0=E5=83=A7?= <357099073@qq.com>
Date: Wed, 28 Jan 2026 23:01:54 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=A6=96=E9=A1=B5=E6=A0=B7?=
=?UTF-8?q?=E5=BC=8F=E5=8F=8A=E8=B7=A8=E5=9F=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/admin/controller/FrontMenuController.php | 6 +-
.../controller/Article/ArticleController.php | 49 +--
app/index/controller/Index.php | 46 ++-
app/index/route/app.php | 6 +-
app/index/view/index/index.html | 104 +++++++
composer.lock | 283 ++++++++----------
config/app.php | 2 +-
config/view.php | 4 +-
8 files changed, 303 insertions(+), 197 deletions(-)
create mode 100644 app/index/view/index/index.html
diff --git a/app/admin/controller/FrontMenuController.php b/app/admin/controller/FrontMenuController.php
index 5a2f17a..f42cf50 100644
--- a/app/admin/controller/FrontMenuController.php
+++ b/app/admin/controller/FrontMenuController.php
@@ -14,7 +14,7 @@ use app\model\FrontMenu;
class FrontMenuController extends BaseController
{
- /**
+ /**
* 获取前端导航接口
* @return \think\response\Json
*/
@@ -163,7 +163,7 @@ class FrontMenuController extends BaseController
} catch (DbException $e) {
// 记录失败日志
$this->logFail('前端导航管理', '更新前端导航', $e->getMessage());
- return json([
+ return json([
'code' => 500,
'msg' => 'fail:' . $e->getMessage(),
'data' => $e->getTraceAsString()
@@ -176,7 +176,7 @@ class FrontMenuController extends BaseController
{
try {
// 检查是否有子前端导航
-$hasChildren = FrontMenu::where('pid', $id)
+ $hasChildren = FrontMenu::where('pid', $id)
->where('pid', $id)
->where('delete_time', null)
->count() > 0;
diff --git a/app/index/controller/Article/ArticleController.php b/app/index/controller/Article/ArticleController.php
index f984bea..58b9446 100644
--- a/app/index/controller/Article/ArticleController.php
+++ b/app/index/controller/Article/ArticleController.php
@@ -1,5 +1,6 @@
where('delete_time', null)
->find();
-
+
+ var_dump($newsCenterCategory);
+
if (!$newsCenterCategory) {
return json([
'code' => 200,
@@ -34,18 +37,18 @@ class ArticleController extends BaseController
'list' => [],
]);
}
-
- // 2. 获取新闻中心及其子分类的ID列表
+
+ // 2. 获取技术中心及其子分类的ID列表
$mainCategoryId = $newsCenterCategory['id'];
-
+
// 查询子分类
$subCategories = ArticlesCategory::where('cid', $mainCategoryId)
->where('delete_time', null)
->column('id');
-
+
// 合并主分类和子分类ID
$categoryIds = array_merge([$mainCategoryId], $subCategories);
-
+
if (empty($categoryIds)) {
return json([
'code' => 200,
@@ -53,7 +56,7 @@ class ArticleController extends BaseController
'list' => [],
]);
}
-
+
// 3. 查询符合条件的文章,按指定优先级排序,取最新4篇
$articles = Articles::published()
->whereIn('cate', $categoryIds)
@@ -75,7 +78,7 @@ class ArticleController extends BaseController
])
->limit(4)
->select();
-
+
// 4. 处理文章数据,去除HTML标签并生成desc字段
foreach ($articles as &$article) {
// 使用PHP的strip_tags函数去除HTML标签,然后截取前100个字符
@@ -83,7 +86,7 @@ class ArticleController extends BaseController
// 移除原始content字段,减少返回数据大小
unset($article['content']);
}
-
+
return json([
'code' => 200,
'msg' => 'success',
@@ -92,10 +95,10 @@ class ArticleController extends BaseController
} catch (\Exception $e) {
// 打印完整错误信息到日志
$errorMsg = '错误信息:' . $e->getMessage() . ' | 错误行号:' . $e->getLine() . ' | 执行SQL:' . Articles::getLastSql();
- trace('新闻中心文章查询失败: ' . $errorMsg, 'error');
+ trace('技术中心文章查询失败: ' . $errorMsg, 'error');
return json([
'code' => 500,
- 'msg' => '新闻中心文章查询失败,请稍后重试',
+ 'msg' => '技术中心文章查询失败,请稍后重试',
'list' => []
]);
}
@@ -118,7 +121,7 @@ class ArticleController extends BaseController
try {
$article = Articles::where('id', $id)->where('delete_time', null)->find();
-
+
if (!$article) {
return json([
'code' => 404,
@@ -164,7 +167,7 @@ class ArticleController extends BaseController
try {
$article = Articles::where('id', $id)->where('delete_time', null)->find();
-
+
if (!$article) {
return json([
'code' => 404,
@@ -210,15 +213,15 @@ class ArticleController extends BaseController
try {
$article = Articles::where('id', $id)->where('delete_time', null)->find();
-
+
if (!$article) {
return json([
'code' => 404,
'msg' => '文章不存在',
'list' => []
]);
- }
-
+ }
+
if ($article->likes <= 0) {
return json([
'code' => 400,
@@ -226,10 +229,10 @@ class ArticleController extends BaseController
'list' => []
]);
}
-
+
$article->dec('likes');
$article->save();
-
+
return json([
'code' => 200,
'msg' => '取消点赞成功',
@@ -246,4 +249,4 @@ class ArticleController extends BaseController
]);
}
}
-}
\ No newline at end of file
+}
diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php
index 77436ef..ef7a76a 100644
--- a/app/index/controller/Index.php
+++ b/app/index/controller/Index.php
@@ -9,12 +9,56 @@ use app\index\BaseController;
use app\model\FrontMenu;
use app\model\OnePage;
use think\db\exception\DbException;
+use think\facade\Env;
class Index extends BaseController
{
public function index()
{
- return '您好!这是一个[index]示例应用';
+ return view('index/index');
+ }
+
+ /**
+ * 获取日志列表
+ */
+ public function getLogs()
+ {
+ $logPath = Env::get('runtime_path') . 'log/';
+ $logs = [];
+
+ // 读取最近的日志文件
+ $files = glob($logPath . '*.log');
+ if ($files) {
+ // 按修改时间排序,最新的在前
+ usort($files, function($a, $b) {
+ return filemtime($b) - filemtime($a);
+ });
+
+ // 读取最新的日志文件
+ $latestFile = reset($files);
+ if (file_exists($latestFile)) {
+ $content = file_get_contents($latestFile);
+ $lines = explode("\n", $content);
+
+ // 倒序遍历,只取最近的100条
+ $count = 0;
+ for ($i = count($lines) - 1; $i >= 0 && $count < 100; $i--) {
+ if (!empty(trim($lines[$i]))) {
+ $logs[] = $lines[$i];
+ $count++;
+ }
+ }
+
+ // 再倒序回来,使最新的日志在最后
+ $logs = array_reverse($logs);
+ }
+ }
+
+ return json([
+ 'code' => 200,
+ 'msg' => 'success',
+ 'data' => $logs
+ ]);
}
/**
diff --git a/app/index/route/app.php b/app/index/route/app.php
index 1236b5f..e41f6dd 100644
--- a/app/index/route/app.php
+++ b/app/index/route/app.php
@@ -24,4 +24,8 @@ Route::post('articleUnlikes/:id', 'app\index\controller\Article\ArticleControlle
// --- 前端导航与单页路由 ---
Route::get('headmenu', 'app\index\controller\Index@getHeadMenu');
-Route::rule('onepage/:path', 'app\index\controller\Index@getOnePageByPath', 'GET')->pattern(['path' => '.*']);
\ No newline at end of file
+Route::rule('onepage/:path', 'app\index\controller\Index@getOnePageByPath', 'GET')->pattern(['path' => '.*']);
+
+// --- 日志相关路由 ---
+Route::get('index/getLogs', 'app\index\controller\Index@getLogs');
+Route::get('getLogs', 'app\index\controller\Index@getLogs');
\ No newline at end of file
diff --git a/app/index/view/index/index.html b/app/index/view/index/index.html
new file mode 100644
index 0000000..1eb924e
--- /dev/null
+++ b/app/index/view/index/index.html
@@ -0,0 +1,104 @@
+
+
+
+
+
+ 后端运行状态
+
+
+
+ 后端服务运行状态
+ 实时监控系统运行情况
+
+
+ 最后刷新: 从未
+ |
+ 每5秒自动刷新
+
+
+
+
+
\ No newline at end of file
diff --git a/composer.lock b/composer.lock
index 55390f6..fcab430 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "f2fe151df908712821797af0035e9769",
+ "content-hash": "ca7c2e934d0d1625582732e674763e2b",
"packages": [
{
"name": "firebase/php-jwt",
@@ -374,16 +374,16 @@
},
{
"name": "psr/http-message",
- "version": "1.1",
+ "version": "2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
- "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba"
+ "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba",
- "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba",
+ "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71",
+ "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71",
"shasum": ""
},
"require": {
@@ -392,7 +392,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.1.x-dev"
+ "dev-master": "2.0.x-dev"
}
},
"autoload": {
@@ -407,7 +407,7 @@
"authors": [
{
"name": "PHP-FIG",
- "homepage": "http://www.php-fig.org/"
+ "homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
@@ -421,9 +421,9 @@
"response"
],
"support": {
- "source": "https://github.com/php-fig/http-message/tree/1.1"
+ "source": "https://github.com/php-fig/http-message/tree/2.0"
},
- "time": "2023-04-04T09:50:52+00:00"
+ "time": "2023-04-04T09:54:51+00:00"
},
{
"name": "psr/log",
@@ -526,103 +526,18 @@
},
"time": "2021-10-29T13:26:27+00:00"
},
- {
- "name": "symfony/polyfill-mbstring",
- "version": "v1.33.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/polyfill-mbstring.git",
- "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493",
- "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493",
- "shasum": ""
- },
- "require": {
- "ext-iconv": "*",
- "php": ">=7.2"
- },
- "provide": {
- "ext-mbstring": "*"
- },
- "suggest": {
- "ext-mbstring": "For best performance"
- },
- "type": "library",
- "extra": {
- "thanks": {
- "url": "https://github.com/symfony/polyfill",
- "name": "symfony/polyfill"
- }
- },
- "autoload": {
- "files": [
- "bootstrap.php"
- ],
- "psr-4": {
- "Symfony\\Polyfill\\Mbstring\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Nicolas Grekas",
- "email": "p@tchwork.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony polyfill for the Mbstring extension",
- "homepage": "https://symfony.com",
- "keywords": [
- "compatibility",
- "mbstring",
- "polyfill",
- "portable",
- "shim"
- ],
- "support": {
- "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.33.0"
- },
- "funding": [
- {
- "url": "https://symfony.com/sponsor",
- "type": "custom"
- },
- {
- "url": "https://github.com/fabpot",
- "type": "github"
- },
- {
- "url": "https://github.com/nicolas-grekas",
- "type": "github"
- },
- {
- "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
- "type": "tidelift"
- }
- ],
- "time": "2024-12-23T08:48:59+00:00"
- },
{
"name": "topthink/framework",
- "version": "v8.1.3",
+ "version": "v8.1.4",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
- "reference": "e4207e98b66f92d26097ed6efd535930cba90e8f"
+ "reference": "8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/top-think/framework/zipball/e4207e98b66f92d26097ed6efd535930cba90e8f",
- "reference": "e4207e98b66f92d26097ed6efd535930cba90e8f",
+ "url": "https://api.github.com/repos/top-think/framework/zipball/8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01",
+ "reference": "8e7b2b2364047cbf71a38c4e397a9ca0d4ef2b01",
"shasum": ""
},
"require": {
@@ -630,7 +545,7 @@
"ext-json": "*",
"ext-mbstring": "*",
"php": ">=8.0.0",
- "psr/http-message": "^1.0",
+ "psr/http-message": "^1.0|^2.0",
"psr/log": "^1.0|^2.0|^3.0",
"psr/simple-cache": "^1.0|^2.0|^3.0",
"topthink/think-container": "^3.0",
@@ -639,6 +554,7 @@
"topthink/think-validate": "^3.0"
},
"require-dev": {
+ "friendsofphp/php-cs-fixer": "^3.92",
"guzzlehttp/psr7": "^2.1.0",
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.2",
@@ -674,9 +590,9 @@
],
"support": {
"issues": "https://github.com/top-think/framework/issues",
- "source": "https://github.com/top-think/framework/tree/v8.1.3"
+ "source": "https://github.com/top-think/framework/tree/v8.1.4"
},
- "time": "2025-07-14T03:48:44+00:00"
+ "time": "2026-01-15T02:45:10+00:00"
},
{
"name": "topthink/think-container",
@@ -724,56 +640,6 @@
},
"time": "2025-04-07T03:21:51+00:00"
},
- {
- "name": "topthink/think-cors",
- "version": "v1.0.2",
- "source": {
- "type": "git",
- "url": "https://github.com/top-think/think-cors.git",
- "reference": "822d90b357daa5aa5e1d01668615599f428ad132"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/top-think/think-cors/zipball/822d90b357daa5aa5e1d01668615599f428ad132",
- "reference": "822d90b357daa5aa5e1d01668615599f428ad132",
- "shasum": ""
- },
- "require": {
- "topthink/framework": "^6.0|^8.0"
- },
- "type": "library",
- "extra": {
- "think": {
- "config": {
- "cors": "src/config.php"
- },
- "services": [
- "think\\cors\\Service"
- ]
- }
- },
- "autoload": {
- "psr-4": {
- "think\\cors\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "Apache-2.0"
- ],
- "authors": [
- {
- "name": "yunwuxin",
- "email": "448901948@qq.com"
- }
- ],
- "description": "The Cors Library For ThinkPHP",
- "support": {
- "issues": "https://github.com/top-think/think-cors/issues",
- "source": "https://github.com/top-think/think-cors/tree/v1.0.2"
- },
- "time": "2024-04-26T06:32:17+00:00"
- },
{
"name": "topthink/think-filesystem",
"version": "v2.0.3",
@@ -1090,17 +956,102 @@
"time": "2024-09-25T14:21:43+00:00"
},
{
- "name": "symfony/var-dumper",
- "version": "v6.4.26",
+ "name": "symfony/polyfill-mbstring",
+ "version": "v1.33.0",
"source": {
"type": "git",
- "url": "https://github.com/symfony/var-dumper.git",
- "reference": "cfae1497a2f1eaad78dbc0590311c599c7178d4a"
+ "url": "https://github.com/symfony/polyfill-mbstring.git",
+ "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/var-dumper/zipball/cfae1497a2f1eaad78dbc0590311c599c7178d4a",
- "reference": "cfae1497a2f1eaad78dbc0590311c599c7178d4a",
+ "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493",
+ "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493",
+ "shasum": ""
+ },
+ "require": {
+ "ext-iconv": "*",
+ "php": ">=7.2"
+ },
+ "provide": {
+ "ext-mbstring": "*"
+ },
+ "suggest": {
+ "ext-mbstring": "For best performance"
+ },
+ "type": "library",
+ "extra": {
+ "thanks": {
+ "url": "https://github.com/symfony/polyfill",
+ "name": "symfony/polyfill"
+ }
+ },
+ "autoload": {
+ "files": [
+ "bootstrap.php"
+ ],
+ "psr-4": {
+ "Symfony\\Polyfill\\Mbstring\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony polyfill for the Mbstring extension",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "compatibility",
+ "mbstring",
+ "polyfill",
+ "portable",
+ "shim"
+ ],
+ "support": {
+ "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.33.0"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://github.com/nicolas-grekas",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2024-12-23T08:48:59+00:00"
+ },
+ {
+ "name": "symfony/var-dumper",
+ "version": "v6.4.32",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/var-dumper.git",
+ "reference": "131fc9915e0343052af5ed5040401b481ca192aa"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/var-dumper/zipball/131fc9915e0343052af5ed5040401b481ca192aa",
+ "reference": "131fc9915e0343052af5ed5040401b481ca192aa",
"shasum": ""
},
"require": {
@@ -1155,7 +1106,7 @@
"dump"
],
"support": {
- "source": "https://github.com/symfony/var-dumper/tree/v6.4.26"
+ "source": "https://github.com/symfony/var-dumper/tree/v6.4.32"
},
"funding": [
{
@@ -1175,20 +1126,20 @@
"type": "tidelift"
}
],
- "time": "2025-09-25T15:37:27+00:00"
+ "time": "2026-01-01T13:34:06+00:00"
},
{
"name": "topthink/think-dumper",
- "version": "v1.0.5",
+ "version": "v1.0.6",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-dumper.git",
- "reference": "eba662a1843d5db68059050c530f7d43287289fc"
+ "reference": "2140ea8293d1a27637ada9b830078b8a1e0f44b3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/top-think/think-dumper/zipball/eba662a1843d5db68059050c530f7d43287289fc",
- "reference": "eba662a1843d5db68059050c530f7d43287289fc",
+ "url": "https://api.github.com/repos/top-think/think-dumper/zipball/2140ea8293d1a27637ada9b830078b8a1e0f44b3",
+ "reference": "2140ea8293d1a27637ada9b830078b8a1e0f44b3",
"shasum": ""
},
"require": {
@@ -1221,9 +1172,9 @@
"description": "Dumper extend for thinkphp",
"support": {
"issues": "https://github.com/top-think/think-dumper/issues",
- "source": "https://github.com/top-think/think-dumper/tree/v1.0.5"
+ "source": "https://github.com/top-think/think-dumper/tree/v1.0.6"
},
- "time": "2025-03-21T07:15:45+00:00"
+ "time": "2026-01-14T08:50:35+00:00"
},
{
"name": "topthink/think-trace",
@@ -1286,5 +1237,5 @@
"php": ">=8.0.0"
},
"platform-dev": {},
- "plugin-api-version": "2.6.0"
+ "plugin-api-version": "2.9.0"
}
diff --git a/config/app.php b/config/app.php
index 7d89170..4ac42b4 100644
--- a/config/app.php
+++ b/config/app.php
@@ -9,7 +9,7 @@ return [
// 是否启用路由
'with_route' => true,
// 默认应用
- 'default_app' => 'admin',
+ 'default_app' => 'index',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 自动多应用模式
diff --git a/config/view.php b/config/view.php
index 01259a0..84151a2 100644
--- a/config/view.php
+++ b/config/view.php
@@ -4,8 +4,8 @@
// +----------------------------------------------------------------------
return [
- // 模板引擎类型使用Think
- 'type' => 'Think',
+ // 模板引擎类型使用php
+ 'type' => 'php',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板目录名