| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- namespace App\Module\Admin\AdminWidgets;
- use Dcat\Admin\Widgets\Card;
- /**
- * 快捷操作小部件
- */
- class QuickActionsWidget extends Card
- {
- public function __construct()
- {
- parent::__construct('快捷操作', $this->buildContent());
- }
- /**
- * 构建内容
- *
- * @return string
- */
- protected function buildContent(): string
- {
- $actions = [
- [
- 'title' => '清理缓存',
- 'icon' => 'fa-broom',
- 'color' => 'warning',
- 'url' => '/admin/admin-cache',
- 'description' => '清理系统缓存',
- ],
- [
- 'title' => '系统信息',
- 'icon' => 'fa-info-circle',
- 'color' => 'info',
- 'url' => '/admin/system-info',
- 'description' => '查看系统详细信息',
- ],
- [
- 'title' => '日志管理',
- 'icon' => 'fa-file-alt',
- 'color' => 'primary',
- 'url' => '/admin/logs',
- 'description' => '查看和管理系统日志',
- ],
- [
- 'title' => '系统维护',
- 'icon' => 'fa-tools',
- 'color' => 'danger',
- 'url' => '#',
- 'description' => '执行系统维护操作',
- 'onclick' => 'performMaintenance()',
- ],
- [
- 'title' => '备份系统',
- 'icon' => 'fa-archive',
- 'color' => 'success',
- 'url' => '#',
- 'description' => '创建系统备份',
- 'onclick' => 'createBackup()',
- ],
- [
- 'title' => '性能监控',
- 'icon' => 'fa-chart-line',
- 'color' => 'secondary',
- 'url' => '/admin/performance',
- 'description' => '查看性能监控数据',
- ],
- ];
- $html = '<div class="list-group list-group-flush">';
-
- foreach ($actions as $action) {
- $onclick = isset($action['onclick']) ? "onclick=\"{$action['onclick']}\"" : '';
- $href = isset($action['onclick']) ? 'javascript:void(0)' : $action['url'];
-
- $html .= '<a href="' . $href . '" class="list-group-item list-group-item-action" ' . $onclick . '>';
- $html .= '<div class="d-flex w-100 justify-content-between align-items-center">';
- $html .= '<div>';
- $html .= "<i class=\"fa {$action['icon']} text-{$action['color']} mr-2\"></i>";
- $html .= "<strong>{$action['title']}</strong>";
- $html .= "<br><small class=\"text-muted\">{$action['description']}</small>";
- $html .= '</div>';
- $html .= '<i class="fa fa-chevron-right text-muted"></i>';
- $html .= '</div>';
- $html .= '</a>';
- }
-
- $html .= '</div>';
-
- // 添加JavaScript函数
- $html .= $this->getQuickActionsScript();
-
- return $html;
- }
- /**
- * 获取快捷操作JavaScript
- *
- * @return string
- */
- protected function getQuickActionsScript(): string
- {
- return '
- <script>
- function performMaintenance() {
- if (confirm("确定要执行系统维护吗?这可能需要几分钟时间。")) {
- Dcat.loading();
-
- $.post("/admin/api/maintenance", {
- _token: $("meta[name=csrf-token]").attr("content"),
- clear_cache: true,
- clean_logs: false,
- optimize_database: false
- }).done(function(data) {
- Dcat.loading(false);
- if (data.status === "success") {
- Dcat.success("系统维护完成");
- setTimeout(function() {
- location.reload();
- }, 2000);
- } else {
- Dcat.error(data.message || "维护失败");
- }
- }).fail(function() {
- Dcat.loading(false);
- Dcat.error("维护操作失败");
- });
- }
- }
-
- function createBackup() {
- if (confirm("确定要创建系统备份吗?")) {
- Dcat.loading();
-
- $.post("/admin/api/backup", {
- _token: $("meta[name=csrf-token]").attr("content"),
- include_database: true,
- include_files: false,
- include_config: true
- }).done(function(data) {
- Dcat.loading(false);
- if (data.status === "success") {
- Dcat.success("备份创建成功");
- if (data.download_url) {
- window.open(data.download_url, "_blank");
- }
- } else {
- Dcat.error(data.message || "备份失败");
- }
- }).fail(function() {
- Dcat.loading(false);
- Dcat.error("备份操作失败");
- });
- }
- }
- </script>';
- }
- }
|