diff --git a/themes/beauty/controller/CommandController.php b/themes/beauty/controller/CommandController.php index ffccdb9..2a37be1 100644 --- a/themes/beauty/controller/CommandController.php +++ b/themes/beauty/controller/CommandController.php @@ -269,6 +269,7 @@ eof; if (empty($total)) {return false;} $stats = array( + 'updatetime' => time(), 'currentDir' => $dirpath, 'total' => $total, 'current' => $index, diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index 32661cd..c732aec 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -1044,4 +1044,46 @@ Class SiteController extends Controller { return $this->render($viewName, $params, $pageTitle); } + //获取MainBot扫描状态 + public function actionBotstats() { + $code = 0; + $msg = 'OK'; + $percent = 0; + + $statsFile = __DIR__ . '/../../../runtime/cache/stats_scan.json'; + if (!file_exists($statsFile)) { + $code = 0; + $msg = '还没执行过文件扫描任务'; + }else { + try { + $code = 1; + $msg = "状态:未知"; + + $json = file_get_contents($statsFile); + $stats = json_decode($json, true); + if (!empty($stats['percent'])) { + $percent = $stats['percent']; + } + + if (!empty($stats['status'])) { + $statusNames = [ + 'running' => '执行中', + 'finished' => '已完成', + ]; + + $status = !empty($statusNames[$stats['status']]) ? $statusNames[$stats['status']] : '未知'; + $msg = "状态:{$status}"; + } + + if (!empty($stats['updatetime'])) { + $msg .= ",更新时间:" . date('Y-m-d H:i:s', $stats['updatetime']); + } + }catch(Exception $e) { + $msg = '获取文件扫描状态失败:' . $e->getMessage(); + } + } + + return $this->renderJson(compact('code', 'percent', 'msg')); + } + } diff --git a/themes/beauty/views/layout/main.php b/themes/beauty/views/layout/main.php index 36c5a67..71dc077 100644 --- a/themes/beauty/views/layout/main.php +++ b/themes/beauty/views/layout/main.php @@ -101,6 +101,13 @@ require_once __DIR__ . '/../../../../plugins/Html.php'; 你的浏览器不支持audio标签 + + + + diff --git a/www/css/beauty.css b/www/css/beauty.css index 8a09c6c..6df2221 100644 --- a/www/css/beauty.css +++ b/www/css/beauty.css @@ -173,6 +173,8 @@ a:link{text-decoration:none} .simple-form{max-width:480px;margin:0 auto} +.botstats{margin-bottom:2px;margin-left:10px;margin-right:10px} + /*自动播放图片时隐藏标题*/ .fancybox__container{ --fancybox-bg:#1d1d1f; diff --git a/www/js/beauty.js b/www/js/beauty.js index 2b46623..1b55200 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -922,4 +922,35 @@ $('.expand-icon').click(function(evt) { Cookies.set(cookieKey, 'opened', { expires: 1 }); } -}); \ No newline at end of file +}); + +/* MainBot扫描进度展示 */ +if ($('.botstats').length > 0) { + var refreshBotStats = function() { + $.ajax({ + url: '/site/botstats', + method: 'GET', + dataType: 'json' + }).done(function(data) { + if (data.code != 1) { + console.warn('Bot stats获取失败', data.msg); + }else { + $('.botstats .progress-bar').css('width', data.percent + '%').text('扫描已完成 ' + data.percent + '%'); + if (data.percent < 100) { + $('.botstats').removeClass('hide'); + $('.botstats .progress-bar').removeClass('progress-bar-success'); + setTimeout(refreshBotStats, 10000); + }else { + $('.botstats .progress-bar').addClass('progress-bar-success'); + setTimeout(function() { + $('.botstats').addClass('hide'); + }, 3000); + } + } + }).fail(function(jqXHR, textStatus, errorThrown) { + console.error('Bot stats获取失败,错误信息:' + errorThrown); + }); + }; + + refreshBotStats(); +}