更新首页样式及跨域

This commit is contained in:
扫地僧 2026-01-28 23:01:54 +08:00
parent 89d7761887
commit aa2612bcb9
8 changed files with 303 additions and 197 deletions

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace app\index\controller\Article;
@ -16,17 +17,19 @@ use think\db\exception\DbException;
class ArticleController extends BaseController
{
/**
* 获取新闻中心顶部4篇文章
* 获取技术中心顶部4篇文章
* @return Json
*/
public function getNewsCenterTop4(): Json
{
try {
// 1. 查询新闻中心主分类
$newsCenterCategory = ArticlesCategory::where('name', '新闻中心')
// 1. 查询技术中心主分类
$newsCenterCategory = ArticlesCategory::where('name', '技术中心')
->where('delete_time', null)
->find();
var_dump($newsCenterCategory);
if (!$newsCenterCategory) {
return json([
'code' => 200,
@ -35,7 +38,7 @@ class ArticleController extends BaseController
]);
}
// 2. 获取新闻中心及其子分类的ID列表
// 2. 获取技术中心及其子分类的ID列表
$mainCategoryId = $newsCenterCategory['id'];
// 查询子分类
@ -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' => []
]);
}

View File

@ -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
]);
}
/**

View File

@ -25,3 +25,7 @@ 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' => '.*']);
// --- 日志相关路由 ---
Route::get('index/getLogs', 'app\index\controller\Index@getLogs');
Route::get('getLogs', 'app\index\controller\Index@getLogs');

View File

@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>后端运行状态</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
h1 {
color: #333;
text-align: center;
}
p {
color: #666;
text-align: center;
}
#log-content {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
margin: 20px auto;
max-width: 1200px;
max-height: 600px;
overflow-y: auto;
}
#log-content div {
padding: 5px 0;
border-bottom: 1px solid #eee;
font-size: 14px;
line-height: 1.4;
}
#log-content div:hover {
background-color: #f9f9f9;
}
#log-content p {
text-align: left;
}
.refresh-info {
text-align: center;
font-size: 12px;
color: #999;
margin-top: 10px;
}
</style>
</head>
<body>
<h1>后端服务运行状态</h1>
<p>实时监控系统运行情况</p>
<div id="log-content">
<p>正在加载日志...</p>
</div>
<div class="refresh-info">
<span id="last-refresh">最后刷新: 从未</span>
<span> | </span>
<span>每5秒自动刷新</span>
</div>
<script>
// 加载日志
function loadLogs() {
fetch('/getLogs')
.then(response => response.json())
.then(data => {
const logContent = document.getElementById('log-content');
if (data.code === 200) {
logContent.innerHTML = '';
if (data.data && data.data.length > 0) {
data.data.forEach(log => {
const logItem = document.createElement('div');
logItem.textContent = log;
logContent.appendChild(logItem);
});
} else {
logContent.innerHTML = '<p>暂无日志记录</p>';
}
} else {
logContent.innerHTML = '<p>加载日志失败: ' + (data.msg || '未知错误') + '</p>';
}
// 更新最后刷新时间
const now = new Date();
const timeStr = now.toLocaleString('zh-CN');
document.getElementById('last-refresh').textContent = '最后刷新: ' + timeStr;
})
.catch(error => {
console.error('加载日志失败:', error);
const logContent = document.getElementById('log-content');
logContent.innerHTML = '<p>加载日志失败: 网络错误</p>';
});
}
// 初始加载日志
loadLogs();
// 定时刷新日志每5秒一次
setInterval(loadLogs, 5000);
</script>
</body>
</html>

283
composer.lock generated
View File

@ -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"
}

View File

@ -9,7 +9,7 @@ return [
// 是否启用路由
'with_route' => true,
// 默认应用
'default_app' => 'admin',
'default_app' => 'index',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 自动多应用模式

View File

@ -4,8 +4,8 @@
// +----------------------------------------------------------------------
return [
// 模板引擎类型使用Think
'type' => 'Think',
// 模板引擎类型使用php
'type' => 'php',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板目录名