Browse Source

add bot stats process bar

master
filesite 1 month ago
parent
commit
2ef6e302b4
  1. 1
      themes/beauty/controller/CommandController.php
  2. 42
      themes/beauty/controller/SiteController.php
  3. 7
      themes/beauty/views/layout/main.php
  4. 2
      www/css/beauty.css
  5. 33
      www/js/beauty.js

1
themes/beauty/controller/CommandController.php

@ -269,6 +269,7 @@ eof;
if (empty($total)) {return false;} if (empty($total)) {return false;}
$stats = array( $stats = array(
'updatetime' => time(),
'currentDir' => $dirpath, 'currentDir' => $dirpath,
'total' => $total, 'total' => $total,
'current' => $index, 'current' => $index,

42
themes/beauty/controller/SiteController.php

@ -1044,4 +1044,46 @@ Class SiteController extends Controller {
return $this->render($viewName, $params, $pageTitle); 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'));
}
} }

7
themes/beauty/views/layout/main.php

@ -101,6 +101,13 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
你的浏览器不支持<code>audio</code>标签 你的浏览器不支持<code>audio</code>标签
</audio> </audio>
<?php } ?> <?php } ?>
</div><!--main_style-->
<div class="progress navbar-fixed-bottom botstats hide">
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;">
...
</div>
</div> </div>
<!--for theme beauty--> <!--for theme beauty-->

2
www/css/beauty.css

@ -173,6 +173,8 @@ a:link{text-decoration:none}
.simple-form{max-width:480px;margin:0 auto} .simple-form{max-width:480px;margin:0 auto}
.botstats{margin-bottom:2px;margin-left:10px;margin-right:10px}
/*自动播放图片时隐藏标题*/ /*自动播放图片时隐藏标题*/
.fancybox__container{ .fancybox__container{
--fancybox-bg:#1d1d1f; --fancybox-bg:#1d1d1f;

33
www/js/beauty.js

@ -922,4 +922,35 @@ $('.expand-icon').click(function(evt) {
Cookies.set(cookieKey, 'opened', { expires: 1 }); Cookies.set(cookieKey, 'opened', { expires: 1 });
} }
}); });
/* 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();
}

Loading…
Cancel
Save