更新细节
This commit is contained in:
parent
0b85a8062f
commit
0c780d19c6
|
@ -2,8 +2,8 @@ const config = {
|
|||
terminal: 1, //终端
|
||||
title: '后台管理系统', //网站默认标题
|
||||
version: '1.6.0', //版本号
|
||||
baseUrl: `${import.meta.env.VITE_APP_BASE_URL || ''}/`, //请求接口域名
|
||||
// baseUrl: 'http://127.0.0.1:30005/',
|
||||
// baseUrl: `${import.meta.env.VITE_APP_BASE_URL || ''}/`, //请求接口域名
|
||||
baseUrl: 'http://127.0.0.1:30005/',
|
||||
urlPrefix: 'adminapi', //请求默认前缀
|
||||
timeout: 10 * 1000 //请求超时时长
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
<div>
|
||||
<v-charts
|
||||
style="height: 350px"
|
||||
:option="workbenchData.visitorOption"
|
||||
:option="workbenchData.dataOption"
|
||||
:autoresize="true"
|
||||
/>
|
||||
</div>
|
||||
|
@ -83,9 +83,9 @@ import vCharts from 'vue-echarts'
|
|||
const workbenchData: any = reactive({
|
||||
today: {}, // 今日数据
|
||||
menu: [], // 常用功能
|
||||
visitor: [], // 图表数据
|
||||
chart_data: [], // 图表数据
|
||||
|
||||
visitorOption: {
|
||||
dataOption: {
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
data: [0],
|
||||
|
@ -138,29 +138,29 @@ const getData = () => {
|
|||
.then((res: any) => {
|
||||
workbenchData.today = res.today
|
||||
workbenchData.menu = res.menu
|
||||
workbenchData.visitor = res.visitor
|
||||
workbenchData.chart_data = res.chart_data
|
||||
// 清空echarts 数据
|
||||
workbenchData.visitorOption.xAxis.data = []
|
||||
workbenchData.visitorOption.series[0].data = []
|
||||
workbenchData.visitorOption.series[1].data = []
|
||||
workbenchData.visitorOption.series[2].data = []
|
||||
workbenchData.visitorOption.series[3].data = []
|
||||
workbenchData.dataOption.xAxis.data = []
|
||||
workbenchData.dataOption.series[0].data = []
|
||||
workbenchData.dataOption.series[1].data = []
|
||||
workbenchData.dataOption.series[2].data = []
|
||||
workbenchData.dataOption.series[3].data = []
|
||||
|
||||
// 写入从后台拿来的数据
|
||||
res.visitor.date.reverse().forEach((item: any) => {
|
||||
workbenchData.visitorOption.xAxis.data.push(item)
|
||||
res.chart_data.date.reverse().forEach((item: any) => {
|
||||
workbenchData.dataOption.xAxis.data.push(item)
|
||||
})
|
||||
res.visitor.list[0].data.forEach((item: any) => {
|
||||
workbenchData.visitorOption.series[0].data.push(item)
|
||||
res.chart_data.list[0].data.forEach((item: any) => {
|
||||
workbenchData.dataOption.series[0].data.push(item)
|
||||
})
|
||||
res.visitor.list[1].data.forEach((item: any) => {
|
||||
workbenchData.visitorOption.series[1].data.push(item)
|
||||
res.chart_data.list[1].data.forEach((item: any) => {
|
||||
workbenchData.dataOption.series[1].data.push(item)
|
||||
})
|
||||
res.visitor.list[2].data.forEach((item: any) => {
|
||||
workbenchData.visitorOption.series[2].data.push(item)
|
||||
res.chart_data.list[2].data.forEach((item: any) => {
|
||||
workbenchData.dataOption.series[2].data.push(item)
|
||||
})
|
||||
res.visitor.list[3].data.forEach((item: any) => {
|
||||
workbenchData.visitorOption.series[3].data.push(item)
|
||||
res.chart_data.list[3].data.forEach((item: any) => {
|
||||
workbenchData.dataOption.series[3].data.push(item)
|
||||
})
|
||||
})
|
||||
.catch((err: any) => {
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace app\adminapi\logic;
|
|||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 工作台
|
||||
|
@ -42,7 +42,7 @@ class WorkbenchLogic extends BaseLogic
|
|||
// 快捷入口
|
||||
'menu' => self::menu(),
|
||||
// 图表数据
|
||||
'visitor' => self::visitor(),
|
||||
'chart_data' => self::chartData(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -87,59 +87,77 @@ class WorkbenchLogic extends BaseLogic
|
|||
*/
|
||||
public static function today(): array
|
||||
{
|
||||
$todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
$todayEnd = strtotime(date('Y-m-d 23:59:59'));
|
||||
$userWhere['user_id'] = 0;
|
||||
// 超级管理员数据
|
||||
if ((request()->adminInfo)['root'] && !(request()->adminInfo)['user_id']) {
|
||||
unset($userWhere['user_id']);
|
||||
}
|
||||
// 普通用户数据
|
||||
if (!(request()->adminInfo)['root'] && (request()->adminInfo)['user_id']) {
|
||||
$userWhere['user_id'] = (request()->adminInfo)['user_id'];
|
||||
}
|
||||
$totalLand = Db::name('land')->where($userWhere)->count();
|
||||
$todayLand = Db::name('land')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$totalProduct = Db::name('product')->where($userWhere)->count();
|
||||
$todayProduct = Db::name('product')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$totalDevice = Db::name('device')->where($userWhere)->count();
|
||||
$todayDevice = Db::name('device')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$totalAlarm = Db::name('monitor_alarm')->where($userWhere)->count();
|
||||
$todayAlarm = Db::name('monitor_alarm')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
return [
|
||||
'time' => date('Y-m-d H:i:s'),
|
||||
// 土地数
|
||||
'today_land' => 3,
|
||||
// 今日新增
|
||||
'total_land' => 10,
|
||||
|
||||
// 产品数
|
||||
'today_product' => 2,
|
||||
// 今日新增
|
||||
'total_product' => 100,
|
||||
|
||||
// 设备数
|
||||
'today_device' => 2,
|
||||
// 今日新增
|
||||
'total_device' => 12,
|
||||
|
||||
// 报警数
|
||||
'today_alarm' => 5,
|
||||
// 今日新增
|
||||
'total_alarm' => 35,
|
||||
|
||||
|
||||
'today_land' => $todayLand,
|
||||
'total_land' => $totalLand,
|
||||
'today_product' => $todayProduct,
|
||||
'total_product' => $totalProduct,
|
||||
'today_device' => $todayDevice,
|
||||
'total_device' => $totalDevice,
|
||||
'today_alarm' => $todayAlarm,
|
||||
'total_alarm' => $totalAlarm
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 访问数
|
||||
* @notes 图表数据
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2021/12/29 16:57
|
||||
*/
|
||||
public static function visitor(): array
|
||||
public static function chartData(): array
|
||||
{
|
||||
$land = $device = $product = $alarm = [];
|
||||
$date = [];
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
$where_start = strtotime("- " . $i . "day");
|
||||
$date[] = date('Y/m/d', $where_start);
|
||||
$land[$i] = rand(0, 100);
|
||||
$product[$i] = rand(0, 100);
|
||||
$device[$i] = rand(0, 100);
|
||||
$alarm[$i] = rand(0, 100);
|
||||
$userWhere['user_id'] = 0;
|
||||
if ((request()->adminInfo)['root'] && !(request()->adminInfo)['user_id']) {
|
||||
unset($userWhere['user_id']);
|
||||
}
|
||||
if (!(request()->adminInfo)['root'] && (request()->adminInfo)['user_id']) {
|
||||
$userWhere['user_id'] = (request()->adminInfo)['user_id'];
|
||||
}
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$where_start = strtotime(date('Y-m-d 00:00:00', strtotime('-' . $i . ' day')));
|
||||
$date[] = date('Y-m-d', $where_start);
|
||||
$todayStart = $where_start;
|
||||
$todayEnd = $where_start + 86400 -1;
|
||||
$todayLand = Db::name('land')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$land[$i] = $todayLand;
|
||||
$todayProduct = Db::name('product')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$product[$i] = $todayProduct;
|
||||
$todayDevice = Db::name('device')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$device[$i] = $todayDevice;
|
||||
$todayAlarm = Db::name('monitor_alarm')->where($userWhere)->where('create_time', 'between', [$todayStart, $todayEnd])->count();
|
||||
$alarm[$i] = $todayAlarm;
|
||||
}
|
||||
|
||||
return [
|
||||
'date' => $date,
|
||||
'list' => [
|
||||
['name' => '土地数', 'data' => $land],
|
||||
['name' => '产品数', 'data' => $product],
|
||||
['name' => '设备数', 'data' => $device],
|
||||
['name' => '报警数', 'data' => $alarm],
|
||||
['name' => '报警数', 'data' => $alarm]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue