补充实验田点击打开
parent
51dd0f4e1f
commit
3968270cf3
|
|
@ -3,14 +3,11 @@
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
||||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use App\Admin\Components;
|
use App\Admin\Components;
|
||||||
use App\Models\Region;
|
use App\Models\Region;
|
||||||
use App\Models\Device;
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
use Slowlyo\OwlAdmin\Renderers\DialogAction;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Dialog;
|
use Slowlyo\OwlAdmin\Renderers\Dialog;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Service;
|
|
||||||
|
|
||||||
class CustomRegionController extends AdminController
|
class CustomRegionController extends AdminController
|
||||||
{
|
{
|
||||||
|
|
@ -43,84 +40,13 @@ class CustomRegionController extends AdminController
|
||||||
$regionList = Region::with('devices')->where('category_id', $categoryId)->get();
|
$regionList = Region::with('devices')->where('category_id', $categoryId)->get();
|
||||||
$resList = [];
|
$resList = [];
|
||||||
foreach($regionList as $region){
|
foreach($regionList as $region){
|
||||||
$tabs = [
|
$tabs = Region::regionTabConfig($region);
|
||||||
[
|
|
||||||
'title' => '基地详情',
|
|
||||||
'value' => 'detail',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 0,
|
|
||||||
],
|
|
||||||
];
|
|
||||||
if($region->devices){
|
|
||||||
foreach($region->devices as $device){
|
|
||||||
switch($device->type)
|
|
||||||
{
|
|
||||||
case Device::TYPE_MONITOR:
|
|
||||||
$tabs[] = [//有监控设备才有
|
|
||||||
'title' => '监控视频',
|
|
||||||
'value' => 'monitor',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-monitor?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 1,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case Device::TYPE_SOIL:
|
|
||||||
$tabs[] = [//有土壤设备才有
|
|
||||||
'title' => '土壤数据',
|
|
||||||
'value' => 'turang',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-soil?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 2,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case Device::TYPE_WATER_QUALITY:
|
|
||||||
$tabs[] = [//有水质设备才有
|
|
||||||
'title' => '水质数据',
|
|
||||||
'value' => 'shuizi',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-water?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 3,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case Device::TYPE_METEOROLOGICAL:
|
|
||||||
$tabs[] = [//有气象设备才有
|
|
||||||
'title' => '气象数据',
|
|
||||||
'value' => 'qixiang',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-meteorological?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 4,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case Device::TYPE_AIR:
|
|
||||||
$tabs[] = [//有通风设备才有
|
|
||||||
'title' => '通风设备',
|
|
||||||
'value' => 'air',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-air?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 5,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
case Device::TYPE_ATOMIZING:
|
|
||||||
$tabs[] = [//有喷雾设备才有
|
|
||||||
'title' => '喷雾设备',
|
|
||||||
'value' => 'wasserstrahl',
|
|
||||||
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-wasserstrahl?id='.$region->id)),
|
|
||||||
'unmountOnExit' => true,//每次切换tab都要销毁
|
|
||||||
'sort' => 6,
|
|
||||||
];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$tabs = array_merge(collect($tabs)->sortBy('sort')->toArray(), []);
|
|
||||||
$resList[] = [
|
$resList[] = [
|
||||||
"icon"=> $region->cover ?? '',
|
"icon"=> $region->cover ?? '',
|
||||||
"text"=> $region->name,
|
"text"=> $region->name,
|
||||||
'clickAction' => DialogAction::make()->dialog(
|
'clickAction' => DialogAction::make()->dialog(
|
||||||
Dialog::make()->title($region['name'])->body([
|
Dialog::make()->title($region['name'])->body([
|
||||||
\amisMake()->Tabs()->tabsMode('simple')->name('detailTab')->tabs($tabs),
|
\amisMake()->Tabs()->tabsMode('simple')->tabs($tabs),
|
||||||
])->size('full')
|
])->size('full')
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
@ -128,6 +54,14 @@ class CustomRegionController extends AdminController
|
||||||
return $resList;
|
return $resList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRegionTabs(Request $request){
|
||||||
|
$region = Region::find($request->id);
|
||||||
|
$tabs = Region::regionTabConfig($region);
|
||||||
|
$page = \amisMake()->Tabs()->tabsMode('simple')->tabs($tabs);
|
||||||
|
|
||||||
|
return $this->response()->success($page);
|
||||||
|
}
|
||||||
|
|
||||||
public function regionDetail(Request $request)
|
public function regionDetail(Request $request)
|
||||||
{
|
{
|
||||||
$id = $request->id;
|
$id = $request->id;
|
||||||
|
|
@ -141,7 +75,7 @@ class CustomRegionController extends AdminController
|
||||||
->body([
|
->body([
|
||||||
\amisMake()->TextControl()->static(true)->name('name')->label('名称')->value($region->name),
|
\amisMake()->TextControl()->static(true)->name('name')->label('名称')->value($region->name),
|
||||||
\amisMake()->TextControl()->static(true)->name('director')->label('负责人')->value($region->director),
|
\amisMake()->TextControl()->static(true)->name('director')->label('负责人')->value($region->director),
|
||||||
\amisMake()->TextControl()->static(true)->name('category')->label('分类')->value($region->category?->name ?? ''),
|
\amisMake()->TextControl()->static(true)->name('category_name')->label('分类')->value($region->category?->name ?? ''),
|
||||||
\amisMake()->TextControl()->static(true)->name('area')->label('面积m²')->value($region?->area ?? ''),
|
\amisMake()->TextControl()->static(true)->name('area')->label('面积m²')->value($region?->area ?? ''),
|
||||||
\amisMake()->TextControl()->static(true)->name('sort')->label('排序')->value($region?->sort ?? '0'),
|
\amisMake()->TextControl()->static(true)->name('sort')->label('排序')->value($region?->sort ?? '0'),
|
||||||
\amisMake()->SwitchControl()->static(true)->name('is_enable')->name('is_enable')->label('显示')->value($region?->is_enable ?? 0),
|
\amisMake()->SwitchControl()->static(true)->name('is_enable')->name('is_enable')->label('显示')->value($region?->is_enable ?? 0),
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ use Slowlyo\OwlAdmin\Renderers\Button;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Image;
|
use Slowlyo\OwlAdmin\Renderers\Image;
|
||||||
use App\Admin\Components;
|
use App\Admin\Components;
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
|
use App\Models\Region;
|
||||||
use Slowlyo\OwlAdmin\Renderers\Html;
|
use Slowlyo\OwlAdmin\Renderers\Html;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class RegionController extends AdminController
|
class RegionController extends AdminController
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +50,12 @@ class RegionController extends AdminController
|
||||||
TableColumn::make()->name('is_enable')->type('switch')->label('显示')->quickEdit(Components::make()->enableControl('is_enable', '', 'inline')->saveImmediately(true)),
|
TableColumn::make()->name('is_enable')->type('switch')->label('显示')->quickEdit(Components::make()->enableControl('is_enable', '', 'inline')->saveImmediately(true)),
|
||||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||||
// TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
// TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||||
$this->rowActions(true, 'lg'),
|
amisMake()->Operation()->label(__('admin.actions'))->buttons([
|
||||||
|
$this->showRegion(),
|
||||||
|
$this->rowEditButton(true, 'lg'),
|
||||||
|
$this->rowDeleteButton()
|
||||||
|
]),
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->baseList($crud);
|
return $this->baseList($crud);
|
||||||
|
|
@ -94,4 +101,12 @@ class RegionController extends AdminController
|
||||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function showRegion(){
|
||||||
|
return amisMake()->DialogAction()->icon('fa-regular fa-eye')->label('查看')->level('link')->dialog(
|
||||||
|
amisMake()->Dialog()->title('查看详情')->body([
|
||||||
|
\amisMake()->Service()->schemaApi(admin_url('custom-region-tabs?id=${id}'))
|
||||||
|
])->size('full')->actions([])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ Route::group([
|
||||||
|
|
||||||
//特殊菜单
|
//特殊菜单
|
||||||
$router->get('custom-region/{type}', '\App\Admin\Controllers\CustomRegionController@regionIndex');
|
$router->get('custom-region/{type}', '\App\Admin\Controllers\CustomRegionController@regionIndex');
|
||||||
|
$router->post('custom-region-tabs', '\App\Admin\Controllers\CustomRegionController@getRegionTabs');
|
||||||
$router->post('custom-region-detail', '\App\Admin\Controllers\CustomRegionController@regionDetail');
|
$router->post('custom-region-detail', '\App\Admin\Controllers\CustomRegionController@regionDetail');
|
||||||
|
|
||||||
$router->get('custom-region-monitor', '\App\Admin\Controllers\DeviceController@monitorList');
|
$router->get('custom-region-monitor', '\App\Admin\Controllers\DeviceController@monitorList');
|
||||||
|
|
|
||||||
|
|
@ -27,4 +27,80 @@ class Region extends Model
|
||||||
public function devices(){
|
public function devices(){
|
||||||
return $this->belongsToMany(Device::class, RegionDevice::class, 'region_id', 'device_id')->withTimestamps();
|
return $this->belongsToMany(Device::class, RegionDevice::class, 'region_id', 'device_id')->withTimestamps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function regionTabConfig($region = null){
|
||||||
|
$tabs = [
|
||||||
|
[
|
||||||
|
'title' => '基地详情',
|
||||||
|
'value' => 'detail',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-detail?id='.($region?->id ?? '${id}'))),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 0,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
if($region?->devices){
|
||||||
|
foreach($region->devices as $device){
|
||||||
|
switch($device->type)
|
||||||
|
{
|
||||||
|
case Device::TYPE_MONITOR:
|
||||||
|
$tabs[] = [//有监控设备才有
|
||||||
|
'title' => '监控视频',
|
||||||
|
'value' => 'monitor',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-monitor?id='.$region->id)),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 1,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Device::TYPE_SOIL:
|
||||||
|
$tabs[] = [//有土壤设备才有
|
||||||
|
'title' => '土壤数据',
|
||||||
|
'value' => 'turang',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-soil?id='.$region->id)),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 2,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Device::TYPE_WATER_QUALITY:
|
||||||
|
$tabs[] = [//有水质设备才有
|
||||||
|
'title' => '水质数据',
|
||||||
|
'value' => 'shuizi',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-water?id='.$region->id)),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 3,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Device::TYPE_METEOROLOGICAL:
|
||||||
|
$tabs[] = [//有气象设备才有
|
||||||
|
'title' => '气象数据',
|
||||||
|
'value' => 'qixiang',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-meteorological?id='.$region->id)),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 4,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Device::TYPE_AIR:
|
||||||
|
$tabs[] = [//有通风设备才有
|
||||||
|
'title' => '通风设备',
|
||||||
|
'value' => 'air',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-air?id='.$region->id)),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 5,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case Device::TYPE_ATOMIZING:
|
||||||
|
$tabs[] = [//有喷雾设备才有
|
||||||
|
'title' => '喷雾设备',
|
||||||
|
'value' => 'wasserstrahl',
|
||||||
|
'tab'=>\amisMake()->Service()->schemaApi(admin_url('custom-region-wasserstrahl?id='.$region->id)),
|
||||||
|
'unmountOnExit' => true,//每次切换tab都要销毁
|
||||||
|
'sort' => 6,
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$tabs = array_merge(collect($tabs)->sortBy('sort')->toArray(), []);
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue