视频监控
parent
d1a14556f2
commit
180f2e070d
|
|
@ -2,17 +2,12 @@
|
|||
|
||||
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\Renderers\{Button, Form, Page, TableColumn, TextControl, Component, CRUDTable, Card, Video, DateRangeControl};
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\DeviceService;
|
||||
use App\Models\Device;
|
||||
use App\Models\Keyword;
|
||||
use App\Admin\Components;
|
||||
use Slowlyo\OwlAdmin\Renderers\Button;
|
||||
|
||||
class DeviceController extends AdminController
|
||||
{
|
||||
|
|
@ -68,18 +63,12 @@ class DeviceController extends AdminController
|
|||
\amisMake()->SelectControl()->name('powered_by')->label('厂家')->options(Keyword::getByParentKey('device-factory')->pluck('name', 'id')->toArray())->required(true),
|
||||
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('回放通道'),
|
||||
]),
|
||||
// 监控设备-额外参数
|
||||
// rtsp://admin:lcdx12345@172.16.40.2:554/Streaming/Channels/5201
|
||||
TextControl::make()->name('extends.rtsp_url')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label(__('device.rtsp_url')),
|
||||
// rtsp://admin:lcdx12345@172.16.40.2:554/Streaming/tracks/5201
|
||||
TextControl::make()->name('extends.rtsp_history')->hiddenOn('data.type != '.Device::TYPE_MONITOR)->label(__('device.rtsp_history')),
|
||||
|
||||
Components::make()->keywordsTagControl('group_tags', '分组', 'device-group'),
|
||||
Components::make()->sortControl('sort', __('admin.order')),
|
||||
TextControl::make()->name('is_enable')->type('switch')->default(1)->label('显示'),
|
||||
|
|
@ -101,64 +90,60 @@ class DeviceController extends AdminController
|
|||
/**
|
||||
* 监控设备列表
|
||||
*/
|
||||
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'),
|
||||
]
|
||||
])
|
||||
public function monitorList()
|
||||
{
|
||||
if ($this->actionOfGetData()) {
|
||||
return $this->response()->success($this->service->list());
|
||||
}
|
||||
return CRUDTable::make()
|
||||
->mode('cards')
|
||||
->hideCheckToggler()
|
||||
->columnsCount(3)
|
||||
->perPage(6)
|
||||
->affixHeader(false)
|
||||
->filterTogglable(true)
|
||||
->set('primaryField', $this->service->primaryKey())
|
||||
->api(admin_url($this->queryPath . '?_action=getData&_type=' . Device::TYPE_MONITOR))
|
||||
->footerToolbar(['statistics', 'pagination'])
|
||||
->headerToolbar([])
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
TextControl::make()->name('name')->label('点位名称')->size('md'),
|
||||
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
Component::make()->setType('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}')
|
||||
]);
|
||||
->card(Card::make()->header(['title' => '$name'])->body(Video::make()->videoType('video/x-flv')->muted(true)->autoPlay(true)->src('${src}')));
|
||||
}
|
||||
|
||||
/**
|
||||
* 监控历史视频
|
||||
*/
|
||||
public function monitorVideoList(){
|
||||
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'),
|
||||
\amisMake()->DateRangeControl()->label('时间范围'),
|
||||
amis('submit')->label(__('admin.search'))->level('primary'),
|
||||
]
|
||||
])
|
||||
public function monitorVideoList()
|
||||
{
|
||||
if ($this->actionOfGetData()) {
|
||||
return $this->response()->success($this->service->list());
|
||||
}
|
||||
return CRUDTable::make()
|
||||
->mode('cards')
|
||||
->hideCheckToggler()
|
||||
->columnsCount(3)
|
||||
->perPage(6)
|
||||
->affixHeader(false)
|
||||
->filterTogglable(true)
|
||||
->set('primaryField', $this->service->primaryKey())
|
||||
->api(admin_url($this->queryPath . '?_action=getData&_type=' . Device::TYPE_MONITOR . '&_mode=history'))
|
||||
->footerToolbar(['statistics', 'pagination'])
|
||||
->headerToolbar([])
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
TextControl::make()->name('name')->label('点位名称')->size('md'),
|
||||
DateRangeControl::make()->name('date')->label('日期')->maxDate('now')->size('md'),
|
||||
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
Component::make()->setType('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}')
|
||||
]);
|
||||
->card(Card::make()->header(['title' => '$name'])->body(Video::make()->videoType('video/x-flv')->muted(true)->autoPlay(true)->src('${src}')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,14 +2,12 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use EloquentFilter\Filterable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Device extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Filterable;
|
||||
|
||||
public const TYPE_MONITOR = 1; //监控设备
|
||||
|
|
@ -30,6 +28,10 @@ class Device extends Model
|
|||
'group_tags'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'extends' => 'json'
|
||||
];
|
||||
|
||||
protected function serializeDate(\DateTimeInterface $date){
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,33 @@ class DeviceService extends BaseService
|
|||
protected array $withRelationships = ['factory'];
|
||||
|
||||
protected string $modelFilterName = DeviceFilter::class;
|
||||
|
||||
public function list()
|
||||
{
|
||||
$query = $this->listQuery();
|
||||
|
||||
$items = (clone $query)->paginate(request()->input('perPage', 20))->items();
|
||||
$base = settings()->get('rtsp_url');
|
||||
if (request('_type') == Device::TYPE_MONITOR) {
|
||||
$history = request('_mode') === 'history';
|
||||
$date = explode(',', request('date'));
|
||||
$start = data_get($date, 0);
|
||||
$end = data_get($date, 1);
|
||||
foreach ($items as &$item) {
|
||||
$url = data_get($item->extends, $history ? 'rtsp_history' : 'rtsp_url');
|
||||
$src = null;
|
||||
if ($base && $url) {
|
||||
// 查看历史监控
|
||||
if ($history && $start && $end) {
|
||||
$url .= '?start=' . date('Y-m-d', $start) . '&end=' . data('Y-m-d', $end);
|
||||
}
|
||||
$src = $base . base64_encode($url);
|
||||
}
|
||||
$item->src = $src;
|
||||
}
|
||||
}
|
||||
$total = (clone $query)->count();
|
||||
|
||||
return compact('items', 'total');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\Device;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Device>
|
||||
*/
|
||||
class DeviceFactory extends Factory
|
||||
{
|
||||
protected $model = Device::class;
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'sn' => $this->faker->isbn10(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Device;
|
||||
use Database\Factories\DeviceFactory;
|
||||
|
||||
class DeviceSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
Device::truncate();
|
||||
(new DeviceFactory)->count(100)->create([
|
||||
'type' => Device::TYPE_MONITOR,
|
||||
// 'extends' => [
|
||||
// 'rtsp_url' => 'rtsp://admin:lcdx12345@172.16.40.2:554/Streaming/Channels/5201',
|
||||
// 'rtsp_history' => 'rtsp://admin:lcdx12345@172.16.40.2:554/Streaming/tracks/5201',
|
||||
// ]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'rtsp_url' => 'RTSP 直播流',
|
||||
'rtsp_history' => 'RTSP 回放流',
|
||||
];
|
||||
Loading…
Reference in New Issue