From 7743c059ec278383a062d8f3585a7c5344229d7d Mon Sep 17 00:00:00 2001 From: hantao Date: Wed, 6 Aug 2025 17:11:56 +0800 Subject: [PATCH] api --- application/admin/controller/Dashboard.php | 55 +-- application/admin/view/dashboard/index.html | 473 +++----------------- public/assets/js/backend/dashboard.js | 129 +++--- 3 files changed, 140 insertions(+), 517 deletions(-) diff --git a/application/admin/controller/Dashboard.php b/application/admin/controller/Dashboard.php index 2dd2e06..f68c923 100644 --- a/application/admin/controller/Dashboard.php +++ b/application/admin/controller/Dashboard.php @@ -23,60 +23,17 @@ class Dashboard extends Backend */ public function index() { - try { - \think\Db::execute("SET @@sql_mode='';"); - } catch (\Exception $e) { - } - $column = []; - $starttime = Date::unixtime('day', -6); - $endtime = Date::unixtime('day', 0, 'end'); - $joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime]) - ->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date') - ->group('join_date') - ->select(); - for ($time = $starttime; $time <= $endtime;) { - $column[] = date("Y-m-d", $time); - $time += 86400; - } - $userlist = array_fill_keys($column, 0); - foreach ($joinlist as $k => $v) { - $userlist[$v['join_date']] = $v['nums']; - } + $car_num = Db::query('SELECT +COUNT(IF(car_type = 1,1,null)) new_car, +COUNT(IF(car_type = 3,1,null)) rent_car, +COUNT(IF(car_type = 2,1,null)) old_car + FROM cars;')[0]; - $dbTableList = Db::query("SHOW TABLE STATUS"); - $addonList = get_addon_list(); - $totalworkingaddon = 0; - $totaladdon = count($addonList); - foreach ($addonList as $index => $item) { - if ($item['state']) { - $totalworkingaddon += 1; - } - } $this->view->assign([ - 'totaluser' => User::count(), - 'totaladdon' => $totaladdon, - 'totaladmin' => Admin::count(), - 'totalcategory' => \app\common\model\Category::count(), - 'todayusersignup' => User::whereTime('jointime', 'today')->count(), - 'todayuserlogin' => User::whereTime('logintime', 'today')->count(), - 'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(), - 'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(), - 'threednu' => User::whereTime('jointime', '-3 days')->count(), - 'sevendnu' => User::whereTime('jointime', '-7 days')->count(), - 'dbtablenums' => count($dbTableList), - 'dbsize' => array_sum(array_map(function ($item) { - return $item['Data_length'] + $item['Index_length']; - }, $dbTableList)), - 'totalworkingaddon' => $totalworkingaddon, - 'attachmentnums' => Attachment::count(), - 'attachmentsize' => Attachment::sum('filesize'), - 'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(), - 'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'), + ...$car_num ]); - $this->assignconfig('column', array_keys($userlist)); - $this->assignconfig('userdata', array_values($userlist)); return $this->view->fetch(); } diff --git a/application/admin/view/dashboard/index.html b/application/admin/view/dashboard/index.html index 1b0bc3a..537c0fb 100644 --- a/application/admin/view/dashboard/index.html +++ b/application/admin/view/dashboard/index.html @@ -1,403 +1,78 @@ -
-
- {:build_heading(null, false)} - -
-
-
-
- -
-
-
- -
- {$totaluser|htmlentities} - {:__('Total user')} -
-
-
-
-
- -
- {$totaladdon|htmlentities} - {:__('Total addon')} -
-
-
-
-
- -
- {$attachmentnums|htmlentities} - {:__('Total attachment')} -
-
-
-
-
- -
- {$totaladmin|htmlentities} - {:__('Total admin')} -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
{$todayusersignup|htmlentities}
-
{:__('Today user signup')}
-
-
-
-
-
-
-
-
-
{$todayuserlogin|htmlentities}
-
{:__('Today user login')}
-
-
-
-
-
-
-
-
-
{$threednu|htmlentities}
-
{:__('Three dnu')}
-
-
-
-
-
-
-
-
-
{$sevendnu|htmlentities}
-
{:__('Seven dnu')}
-
-
-
-
-
-
-
-
-
{$sevendau|htmlentities}
-
{:__('Seven dau')}
-
-
-
-
-
-
-
-
-
{$thirtydau|htmlentities}
-
{:__('Thirty dau')}
-
-
-
-
-
-
-
-
-
-
- -
- -
-
-
-
-
-
- {:__('Real time')} -
{:__('Working addon count')}
-
-
-
-
-

{$totalworkingaddon|htmlentities}

-
- {:__('Working addon count tips')} -
-
-
-
-
-
-
-
-
-
-
- {:__('Real time')} -
{:__('Database count')}
-
-
-
-
-

{$dbtablenums|htmlentities}

-
- {:__('Database table nums')} -
-
-
-

{$dbsize|format_bytes=###,'',0}

-
- {:__('Database size')} -
-
-
-
-
-
-
- -
-
-
-
- {:__('Real time')} -
{:__('Attachment count')}
-
-
- -
-
-

{$attachmentnums|htmlentities}

-
- {:__('Attachment nums')} -
-
-
-

{$attachmentsize|format_bytes=###,'',0}

-
- {:__('Attachment size')} -
-
-
-
-
-
-
-
-
-
-
- {:__('Real time')} -
{:__('Picture count')}
-
-
- -
-
-

{$picturenums|htmlentities}

-
- {:__('Picture nums')} -
-
-
-

{$picturesize|format_bytes=###,'',0}

-
- {:__('Picture size')} -
-
-
-
-
-
-
-
-
-
-
-
- {:__('Custom zone')} -
-
-
+ {:build_heading()} + +
+
+ 🚙 +
{$new_car}
+
新车库存
+
+
+ 🚗 +
{$old_car}
+
二手车库存
+
+
+ 🚐 +
{$rent_car}
+
租车车辆
+
+
+ 💰 +
¥xxxx
+
本月销售额
+ + + + + diff --git a/public/assets/js/backend/dashboard.js b/public/assets/js/backend/dashboard.js index ab8409c..a275d29 100755 --- a/public/assets/js/backend/dashboard.js +++ b/public/assets/js/backend/dashboard.js @@ -2,77 +2,68 @@ define(['jquery', 'bootstrap', 'backend', 'addtabs', 'table', 'echarts', 'echart var Controller = { index: function () { - // 基于准备好的dom,初始化echarts实例 - var myChart = Echarts.init(document.getElementById('echart'), 'walden'); + function showTab(tabName) { + // Hide all tab contents + const tabContents = document.querySelectorAll('.tab-content'); + tabContents.forEach(content => { + content.classList.remove('active'); + }); - // 指定图表的配置项和数据 - var option = { - title: { - text: '', - subtext: '' - }, - color: [ - "#18d1b1", - "#3fb1e3", - "#626c91", - "#a0a7e6", - "#c4ebad", - "#96dee8" - ], - tooltip: { - trigger: 'axis' - }, - legend: { - data: [__('Register user')] - }, - toolbox: { - show: false, - feature: { - magicType: {show: true, type: ['stack', 'tiled']}, - saveAsImage: {show: true} + // Remove active class from all tabs + const navTabs = document.querySelectorAll('.nav-tab'); + navTabs.forEach(tab => { + tab.classList.remove('active'); + }); + + // Show selected tab content + document.getElementById(tabName).classList.add('active'); + + // Add active class to corresponding nav tab + const activeTab = document.querySelector(`.nav-tab[onclick="showTab('${tabName}')"]`); + if (activeTab) { + activeTab.classList.add('active'); + } + } + + // Add click animations to cards + document.querySelectorAll('.car-card').forEach(card => { + card.addEventListener('click', function() { + this.style.transform = 'scale(0.95)'; + setTimeout(() => { + this.style.transform = ''; + }, 150); + }); + }); + + // Add hover effect to action buttons + document.querySelectorAll('.action-btn').forEach(btn => { + btn.addEventListener('click', function() { + const originalText = this.textContent; + this.textContent = '✓ 已点击'; + this.style.background = 'linear-gradient(135deg, #48bb78 0%, #38a169 100%)'; + + setTimeout(() => { + this.textContent = originalText; + this.style.background = 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'; + }, 1000); + }); + }); + + // Simulate real-time updates + setInterval(() => { + const statNumbers = document.querySelectorAll('.stat-number'); + statNumbers.forEach(num => { + if (num.textContent.includes('¥')) return; + const currentValue = parseInt(num.textContent); + if (Math.random() > 0.7) { + num.textContent = currentValue + Math.floor(Math.random() * 3); + num.style.color = '#48bb78'; + setTimeout(() => { + num.style.color = '#2d3748'; + }, 1000); } - }, - xAxis: { - type: 'category', - boundaryGap: false, - data: Config.column - }, - yAxis: {}, - grid: [{ - left: 'left', - top: 'top', - right: '10', - bottom: 30 - }], - series: [{ - name: __('Register user'), - type: 'line', - smooth: true, - areaStyle: { - normal: {} - }, - lineStyle: { - normal: { - width: 1.5 - } - }, - data: Config.userdata - }] - }; - - // 使用刚指定的配置项和数据显示图表。 - myChart.setOption(option); - - $(window).resize(function () { - myChart.resize(); - }); - - $(document).on("click", ".btn-refresh", function () { - setTimeout(function () { - myChart.resize(); - }, 0); - }); - + }); + }, 5000); } };