merge app/Models/Region.php
commit
d1b8d88a5e
|
|
@ -85,4 +85,95 @@ class Components extends BaseRenderer {
|
||||||
->name($name)->label($label)
|
->name($name)->label($label)
|
||||||
->options(Keyword::getByParentKey($typeKey)->pluck('name', 'id')->toArray());
|
->options(Keyword::getByParentKey($typeKey)->pluck('name', 'id')->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成统计图config
|
||||||
|
* 折线图或者柱状图
|
||||||
|
*/
|
||||||
|
public function chartLineBarConfig($title = '', array $x , array $y){
|
||||||
|
$yAxisData = [];
|
||||||
|
$seriesData = [];
|
||||||
|
if(!isset($y[0])){
|
||||||
|
$_y = $y;
|
||||||
|
$y = [0=>$_y];
|
||||||
|
}
|
||||||
|
$i = 0;
|
||||||
|
$tips = '{b0}';
|
||||||
|
foreach($y as $item) {
|
||||||
|
//tips
|
||||||
|
$tips.= '<br/> {a'.$i.'}: {c'.$i.'}'.($item['unit'] ?? '');
|
||||||
|
//纵坐标
|
||||||
|
$yAxisData[] = [
|
||||||
|
'name'=>$item['name'].($item['unit'] ?? ''),
|
||||||
|
'type' =>'value',
|
||||||
|
'axisTick' => true,
|
||||||
|
'alignTicks' => true,
|
||||||
|
'axisLine' => [
|
||||||
|
'show' => true,
|
||||||
|
'lineStyle' => [
|
||||||
|
'color' => $item['color'] ?? ''
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'axisLabel'=> [
|
||||||
|
'formatter'=>'{value} '.($item['unit'] ?? '')
|
||||||
|
]
|
||||||
|
];
|
||||||
|
//数据
|
||||||
|
$_series = [
|
||||||
|
'name' => $item['name'] ?? '',
|
||||||
|
'data' => $item['data'] ?? [],
|
||||||
|
'type' => $item['type'] ?? 'line',
|
||||||
|
'yAxisIndex' => $i,
|
||||||
|
];
|
||||||
|
switch($item['type']){
|
||||||
|
case 'line':
|
||||||
|
$_series = array_merge($_series, [
|
||||||
|
'smooth'=> true,
|
||||||
|
'symbol'=> 'none',
|
||||||
|
'lineStyle' => [
|
||||||
|
'color' => $item['color'] ?? ''
|
||||||
|
],
|
||||||
|
'areaStyle' => [
|
||||||
|
'color' => $item['color'] ?? ''
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
break;
|
||||||
|
case 'bar':
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$seriesData[] = $_series;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'title' => [
|
||||||
|
'text' => $title,
|
||||||
|
],
|
||||||
|
"tooltip" => [//提示
|
||||||
|
'trigger'=>'axis',//坐标轴触发
|
||||||
|
'axisPointer' => [
|
||||||
|
'type' => 'cross'
|
||||||
|
],
|
||||||
|
// 'formatter' => $tips
|
||||||
|
],
|
||||||
|
'grid' => [
|
||||||
|
'left' => '8%',
|
||||||
|
'right' => '8%',
|
||||||
|
],
|
||||||
|
'xAxis' => [
|
||||||
|
'type' => 'category',
|
||||||
|
'data' => $x,
|
||||||
|
],
|
||||||
|
'yAxis' => $yAxisData,
|
||||||
|
'series' => $seriesData
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成饼状图config
|
||||||
|
* -todo
|
||||||
|
*/
|
||||||
|
public function chartPieConfig(){
|
||||||
|
return ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ class CropPlantController extends AdminController
|
||||||
])->target('plant_harvest_chart'),
|
])->target('plant_harvest_chart'),
|
||||||
]),
|
]),
|
||||||
amisMake()->Card()->className('m-r')->body(
|
amisMake()->Card()->className('m-r')->body(
|
||||||
amisMake()->Chart()->name('plant_harvest_chart')->api(admin_url('crop-plant-harveste-chart?plant_id=${id}&start_at=${start_at}&end_at=${end_at}'))
|
amisMake()->Chart()->name('plant_harvest_chart')->api(admin_url('crop-plant-harveste-chart?plant_id=${id}&start_at=${start_at}&end_at=${end_at}'))->debug(true),
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
|
|
@ -144,43 +144,21 @@ class CropPlantController extends AdminController
|
||||||
|
|
||||||
private function plantHarvestChartConfig(array $times, array $areas, array $outputs)
|
private function plantHarvestChartConfig(array $times, array $areas, array $outputs)
|
||||||
{
|
{
|
||||||
return [
|
return Components::make()->chartLineBarConfig('种植情况', $times, [
|
||||||
'title' => [
|
[
|
||||||
'text' => '种植情况',
|
'name'=> '种植面积',
|
||||||
|
'type' => 'line',
|
||||||
|
'data' => $areas,
|
||||||
|
'color' => '#91CC75',
|
||||||
|
'unit' => 'm²'
|
||||||
],
|
],
|
||||||
"tooltip" => [
|
[
|
||||||
'trigger'=>'axis'
|
'name'=> '产量',
|
||||||
],
|
'type'=>'bar',
|
||||||
'xAxis' => [
|
'data'=> $outputs,
|
||||||
'type' => 'category',
|
'color' => '#5470C6',
|
||||||
'boundaryGap' => false,
|
'unit' => 'kg'
|
||||||
'data' => $times,
|
|
||||||
],
|
|
||||||
'yAxis' => [
|
|
||||||
'type' =>'value'
|
|
||||||
],
|
|
||||||
'grid' => [
|
|
||||||
'left' => '8%',
|
|
||||||
'right' => '8%',
|
|
||||||
],
|
|
||||||
'series' => [
|
|
||||||
[
|
|
||||||
'name' => '面积',
|
|
||||||
'data' => $areas,
|
|
||||||
'type' => 'line',
|
|
||||||
'smooth'=> true,
|
|
||||||
'symbol'=> 'none',
|
|
||||||
'areaStyle' => [],
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => '产量',
|
|
||||||
'data' => $outputs,
|
|
||||||
'type' => 'line',
|
|
||||||
'smooth'=> true,
|
|
||||||
'symbol'=> 'none',
|
|
||||||
'areaStyle' => [],
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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');
|
||||||
|
|
|
||||||
|
|
@ -61,4 +61,80 @@ class Region extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany(PlantHarvestLog::class, 'region_id');
|
return $this->hasMany(PlantHarvestLog::class, 'region_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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