426 lines
22 KiB
PHP
426 lines
22 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
|
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
|
use Slowlyo\OwlAdmin\Renderers\CRUDTable;
|
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
|
use App\Services\Admin\DeviceService;
|
|
use App\Models\Device;
|
|
|
|
class DeviceController extends AdminController
|
|
{
|
|
protected string $serviceName = DeviceService::class;
|
|
|
|
protected string $pageTitle = '设备管理';
|
|
|
|
public function list(): Page
|
|
{
|
|
$crud = $this->baseCRUD()
|
|
->filterTogglable(false)
|
|
->headerToolbar([
|
|
$this->createButton(true, 'lg'),
|
|
...$this->baseHeaderToolBar(),
|
|
])
|
|
->columns([
|
|
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
|
TableColumn::make()->name('name')->label('名称'),
|
|
TableColumn::make()->name('sn')->label('编号'),
|
|
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
|
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
|
$this->rowActions(true),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form(): Form
|
|
{
|
|
return $this->baseForm()->body([
|
|
TextControl::make()->name('name')->label('名称')->required(true),
|
|
TextControl::make()->name('sn')->label('编号'),
|
|
\amisMake()->SelectControl()->name('powered_by')->label('厂家')->options(),
|
|
TextControl::make()->name('model_sn')->label('型号'),
|
|
\amisMake()->RadiosControl()->name('type')->label('类型')->options(Device::typeMap())->required(true),
|
|
//监控设备-额外参数
|
|
\amisMake()->TextControl()->name('extends.ip')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('设备IP'),
|
|
\amisMake()->TextControl()->name('extends.username')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('设备用户名'),
|
|
\amisMake()->TextControl()->name('extends.password')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('设备密码'),
|
|
\amisMake()->GroupControl()->body([
|
|
\amisMake()->TextControl()->name('extends.live_port')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('实时端口'),
|
|
\amisMake()->TextControl()->name('extends.live_channel')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('实时通道'),
|
|
]),
|
|
\amisMake()->GroupControl()->body([
|
|
\amisMake()->TextControl()->name('extends.back_port')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('回放端口'),
|
|
\amisMake()->TextControl()->name('extends.back_channel')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label('回放通道'),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
return $this->baseDetail()->body([
|
|
TextControl::make()->static(true)->name('id')->label('ID'),
|
|
TextControl::make()->static(true)->name('name')->label('名称'),
|
|
TextControl::make()->static(true)->name('sn')->label('编号'),
|
|
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
|
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 监控设备列表
|
|
*/
|
|
public function monitorList(){
|
|
return CRUDTable::make()->mode('cards')->columnsCount(3)
|
|
->data([
|
|
'items' => [
|
|
[
|
|
'id'=>1,
|
|
'src'=>'ws://183.221.204.29:8100/rtsp?url=cnRzcDovL2FkbWluOjEyMzQ1Njc4OXhAMTE3LjE3NC4xODQuMTE4OjkwMDkvY2FtL3JlYWxtb25pdG9yP2NoYW5uZWw9MSZzdWJ0eXBlPTA='
|
|
],
|
|
]
|
|
])
|
|
->filter([
|
|
'title' => '搜索条件',
|
|
'body' => [
|
|
\amisMake()->TextControl()->name('name')->label('点位名称')->size('sm'),
|
|
amis('submit')->label(__('admin.search'))->level('primary'),
|
|
]
|
|
])
|
|
->actions([])
|
|
->itemClassName('col-sm-4')
|
|
->card([
|
|
'header' => [],
|
|
'body' => amisMake()->Video()
|
|
->isLive(true)->videoType('video/x-flv')->muted(true)->autoPlay(true)
|
|
->src('${src}')
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 气象图表
|
|
*/
|
|
public function meteorologicalChart(){
|
|
$randArr = function () {
|
|
$_arr = [];
|
|
for ($i = 0; $i < 7; $i++) {
|
|
$_arr[] = random_int(10, 200);
|
|
}
|
|
return '[' . implode(',', $_arr) . ']';
|
|
};
|
|
|
|
$random1 = $randArr();
|
|
$random2 = $randArr();
|
|
|
|
return $this->basePage()->title('')->body([
|
|
\amisMake()->grid()->columns([
|
|
\amisMake()->Form()->title('搜索条件')->mode('inline')->body([
|
|
\amisMake()->TextControl()->label('设备名称'),
|
|
\amisMake()->DateRangeControl()->label('时间范围'),
|
|
amis('submit')->label(__('admin.search'))->level('primary'),
|
|
]),
|
|
]),
|
|
\amisMake()->grid()->columns([
|
|
amisMake()->Flex()->items([
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '空气温度', subtext: '℃'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name:'空气温度', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '空气湿度', subtext: '%RH'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '空气湿度', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '光照强度LUX', },
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '光照强度LUX', },
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
]),
|
|
]),
|
|
\amisMake()->grid()->columns([
|
|
amisMake()->Flex()->items([
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '空气温度', subtext: '℃'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name:'空气温度', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '空气湿度', subtext: '%RH'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '空气湿度', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '光照强度LUX', },
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '光照强度LUX', },
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
]),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 水质图表
|
|
*/
|
|
public function waterChart(){
|
|
$randArr = function () {
|
|
$_arr = [];
|
|
for ($i = 0; $i < 7; $i++) {
|
|
$_arr[] = random_int(10, 200);
|
|
}
|
|
return '[' . implode(',', $_arr) . ']';
|
|
};
|
|
|
|
$random1 = $randArr();
|
|
$random2 = $randArr();
|
|
|
|
return $this->basePage()->title('')->body([
|
|
\amisMake()->grid()->columns([
|
|
\amisMake()->Form()->title('搜索条件')->mode('inline')->body([
|
|
\amisMake()->TextControl()->label('设备名称'),
|
|
\amisMake()->DateRangeControl()->label('时间范围'),
|
|
amis('submit')->label(__('admin.search'))->level('primary'),
|
|
]),
|
|
]),
|
|
\amisMake()->grid()->columns([
|
|
amisMake()->Flex()->items([
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '氯', subtext: 'mg/L'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name:'氯', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '电导率', subtext: 'us/cm'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '电导率', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '氧气', subtext: 'mg/L'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: 'PH'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
]),
|
|
]),
|
|
\amisMake()->grid()->columns([
|
|
amisMake()->Flex()->items([
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '温度', subtext: '℃'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name:'温度', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '浊度', subtext: 'NTU'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '空气湿度', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
)
|
|
]),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 土壤图表
|
|
*/
|
|
public function soilChart(){
|
|
$randArr = function () {
|
|
$_arr = [];
|
|
for ($i = 0; $i < 7; $i++) {
|
|
$_arr[] = random_int(10, 200);
|
|
}
|
|
return '[' . implode(',', $_arr) . ']';
|
|
};
|
|
|
|
$random1 = $randArr();
|
|
$random2 = $randArr();
|
|
|
|
return $this->basePage()->title('')->body([
|
|
\amisMake()->grid()->columns([
|
|
\amisMake()->Form()->title('搜索条件')->mode('inline')->body([
|
|
\amisMake()->TextControl()->label('设备名称'),
|
|
\amisMake()->DateRangeControl()->label('时间范围'),
|
|
amis('submit')->label(__('admin.search'))->level('primary'),
|
|
]),
|
|
]),
|
|
\amisMake()->grid()->columns([
|
|
amisMake()->Flex()->items([
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '氯', subtext: 'mg/L'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name:'氯', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '电导率', subtext: 'us/cm'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '电导率', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '氧气', subtext: 'mg/L'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: 'PH'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '光照强度LUX', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
]),
|
|
]),
|
|
\amisMake()->grid()->columns([
|
|
amisMake()->Flex()->items([
|
|
amisMake()->Card()->className('m-r')->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '温度', subtext: '℃'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name:'温度', data: {$random2}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
),
|
|
amisMake()->Card()->body(
|
|
amisMake()->Chart()->config("{
|
|
title:{ text: '浊度', subtext: 'NTU'},
|
|
tooltip: { trigger: 'axis' },
|
|
xAxis: { type: 'category', boundaryGap: false, data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] },
|
|
yAxis: { type: 'value' },
|
|
grid:{ left: '7%', right:'3%', top: 60, bottom: 30, },
|
|
series: [
|
|
{ name: '空气湿度', data: {$random1}, type: 'line', areaStyle: {}, smooth: true, symbol: 'none', },
|
|
]}")
|
|
)
|
|
]),
|
|
]),
|
|
]);
|
|
}
|
|
}
|